From 5e247ba3ff97647619c4d6ec1d55cf1f88eb8942 Mon Sep 17 00:00:00 2001 From: Johnson Chetty Date: Tue, 4 Dec 2012 18:46:12 +0100 Subject: [PATCH] invitation based changes 0.9 --- itf/app/forms.py | 2 -- itf/app/views.py | 2 +- itf/itfprofiles/forms.py | 24 +++++++++++++++++++ itf/itfprofiles/models.py | 19 ++++++++++----- itf/itfprofiles/views.py | 13 ++-------- .../modules/itfprofiles/invitation_email.txt | 5 +++- 6 files changed, 44 insertions(+), 21 deletions(-) diff --git a/itf/app/forms.py b/itf/app/forms.py index 93b94a1..7da8ab2 100644 --- a/itf/app/forms.py +++ b/itf/app/forms.py @@ -39,8 +39,6 @@ class PopupForm(ItfForm): ''' pass - - class AutocompleteAddWidget(forms.Select): ''' Widget for select2 single select diff --git a/itf/app/views.py b/itf/app/views.py index 1411025..edf28d7 100755 --- a/itf/app/views.py +++ b/itf/app/views.py @@ -44,7 +44,7 @@ def popup_form(request, ctype_id): if request.POST: form = form_class(request.POST, request.FILES) if form.is_valid(): - instance = form.save(commit=False) + instance = form.save(commit=False, request=request) if instance.__dict__.has_key('added_by_id'): instance.added_by = request.user instance.save() diff --git a/itf/itfprofiles/forms.py b/itf/itfprofiles/forms.py index d3c6554..e899a82 100644 --- a/itf/itfprofiles/forms.py +++ b/itf/itfprofiles/forms.py @@ -74,6 +74,29 @@ PadmaClipsInline = itf_inlineformset_factory(PadmaClip, extra=1, is_generic=True #Popup Form Classes: class PopupPersonForm(PopupForm): + def save(self, *args, **kwargs): + if kwargs.has_key('request'): + request = kwargs.pop('request') + #form = PersonForm(request.POST, request.FILES) + + invitee = super(PopupPersonForm, self).save(*args, **kwargs) + invitee.save() + invitation = PersonInvitation( + invitee=invitee, + invite_code=User.objects.make_random_password(30), + is_validated=False, + inviter=Person.objects.get(user=request.user), + sent_date=datetime.now() + ) + + invitation.save() + #import pdb + #pdb.set_trace() + invitation.send_invite() + + return invitee + + class Meta: model = Person fields = ('first_name', 'last_name', 'email',) @@ -221,6 +244,7 @@ class ProductionForm(ItfForm): class ItfAllAuthRegForm(forms.Form): firstname=forms.CharField() lastname=forms.CharField() + #invite_code=forms.HiddenField() #def __init__(self, request=None): diff --git a/itf/itfprofiles/models.py b/itf/itfprofiles/models.py index 0589fa5..932a231 100644 --- a/itf/itfprofiles/models.py +++ b/itf/itfprofiles/models.py @@ -1,3 +1,4 @@ + from django.db import models from app.models import ItfModel from django.contrib.auth.models import User @@ -142,19 +143,25 @@ class PersonInvitation(models.Model): is_validated=models.BooleanField(default=False) sent_date = models.DateTimeField() - def send_mail(self): + def send_invite(self): #import pdb ; pdb.set_trace() - #from django.template.loader import get_template + from django.core.mail import send_mail + from django.template.loader import get_template + from django.template import Context + from itf.settings import SITE_HOST, DEFAULT_FROM_MAIL + template = get_template('modules/itfprofiles/invitation_email.txt') subject = 'Invitation to join the India Theatre Forum' - link = 'http://%s/invitation/accept/%s/' % ( "test.theatreforum.in", self.invite_code, ) + + + link = 'http://%s/invitation/accept/%s/' % ( SITE_HOST, self.invite_code, ) context = Context({ - 'name': str(self.invitee.first_name) + str(self.invitee.last_name), + 'name': str(self.invitee.first_name) + ' ' + str(self.invitee.last_name), 'link': link, - 'sender': str(self.inviter.first_name) + str(self.inviter.last_name) + 'sender': str(self.inviter.first_name) + ' ' + str(self.inviter.last_name) }) - message = template.render(context) + message = template.render(context) send_mail( subject, message, DEFAULT_FROM_MAIL, [self.invitee.email] diff --git a/itf/itfprofiles/views.py b/itf/itfprofiles/views.py index f6ea45c..f008a64 100644 --- a/itf/itfprofiles/views.py +++ b/itf/itfprofiles/views.py @@ -55,7 +55,7 @@ def friend_invite(request): if request.method == 'POST': form = PersonForm(request.POST, request.FILES) if form.is_valid(): - invitee = form.save() + invitee = form.save() invitation = PersonInvitation( invitee=invitee, invite_code=User.objects.make_random_password(30), @@ -65,7 +65,7 @@ def friend_invite(request): ) invitation.save() #try: - invitation.send_mail() + invitation.send_invite() #except: # return HttpResponse("Not Invited!!") return HttpResponse("Invited!!") @@ -97,15 +97,6 @@ def personpopup(request): form = PersonForm(request.POST, request.FILES) if form.is_valid(): instance = form.save() - invitation = PersonInvitation( - invitee=invitee, - invite_code=User.objects.make_random_password(30), - is_validated=False, - inviter=Person.objects.get(user=request.user), - sent_date=datetime.now() - ) - invitation.save() - invitation.send_mail() #return HttpResponse("This person will be Invited!") #return HttpResponse("" % (str(instance.id), instance.get_title())) else: diff --git a/itf/templates/modules/itfprofiles/invitation_email.txt b/itf/templates/modules/itfprofiles/invitation_email.txt index edec8ac..992f410 100644 --- a/itf/templates/modules/itfprofiles/invitation_email.txt +++ b/itf/templates/modules/itfprofiles/invitation_email.txt @@ -10,7 +10,10 @@ Who we are.. Our roots.. And The vision.. Since the summer of 2006, a number of theatre practitioners, scholars and theatre lovers have come together under the aegis of the India Theatre Forum (ITF) to try and create a national resource for theatre and a meeting ground for all those who wish to take on the public responsibility of laying the grounds for excellence and diversity in theatrical endeavour. The question that led to the creation of the ITF was: can this happenstance become the norm? -Can we overcome what we see as limitations, can we learn to identify and recognize opportunities and openings, can we think in terms of long-term growth and sustenance? Such work cannot be done in isolation, but requires the coming together of dedicated and experienced people who have an abiding interest in the field of theatre, and who represent the diverse knowledge and experience base of theatre in this country. It requires the constant exchange of ideas and information, as well as intensive and open debate and discussion. +Can we overcome what we see as limitations, can we learn to identify and recognize opportunities and openings, can we think in terms of long-term growth and sustenance? +Such work cannot be done in isolation, but requires the coming together of dedicated and experienced people who have an abiding interest in the field of theatre, and who represent the diverse knowledge and experience base of theatre in this country. It requires the constant exchange of ideas and information, as well as intensive and open debate and discussion. + +It is in this new era that the performing arts must evolve collaboratively and co-operatively like never before. -- India Theatre Forum