From 476c28819bdced516dabaf9136ab4dbcba872c6d Mon Sep 17 00:00:00 2001 From: Johnson Chetty Date: Thu, 27 Sep 2012 20:45:50 +0200 Subject: [PATCH] email user invitations 0.5 --- itf/itfprofiles/models.py | 39 ++++++++++++++++- itf/itfprofiles/views.py | 43 ++++++++++++++++++- itf/settings.py | 7 ++- .../registration/activation_email.txt | 9 +++- itf/urls.py | 7 ++- 5 files changed, 96 insertions(+), 9 deletions(-) diff --git a/itf/itfprofiles/models.py b/itf/itfprofiles/models.py index ef71d82..fd9b96d 100644 --- a/itf/itfprofiles/models.py +++ b/itf/itfprofiles/models.py @@ -8,6 +8,12 @@ from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes import generic from imagestore.models import Album +# mail imports +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 + GENDER_CHOICES = ( ('M', 'Male'), ('F', 'Female'), @@ -125,6 +131,37 @@ BUZZ_ITEM_TYPES = ( ('publicity', 'Publicity'), ) + +class PersonInvitation(models.Model): + invite_code = models.CharField(max_length=30) + inviter = models.ForeignKey(Person, related_name='has_invited', null=True, blank=True) + invitee = models.ForeignKey(Person, related_name='was_invited_by', null=True, blank=True) + is_validated=models.BooleanField(default=False) + sent_date = models.DateTimeField() + + def __unicode__(self): + return u'%s, %s' % (self.invitee.first_name, self.invitee.email) + + def send(self): + subject = 'Invitation to join the India Theatre Forum' + link = 'http://%s/invitation/accept/%s/' % ( + SITE_HOST, + self.invite_code, + ) + template = get_template('modules/itfprofiles/invitation_email.txt') + + context = Context({ + 'name': str(self.invitee.first_name) + str(self.invitee.last_name), + 'link': link, + 'sender': str(self.inviter.first_name) + str(self.inviter.last_name), + }) + message = template.render(context) + send_mail( + subject, message, + DEFAULT_FROM_MAIL, [self.invitee.email] + ) + + class BuzzItem(ItfModel): link = models.URLField(verify_exists=False) title = models.CharField(max_length=255) @@ -218,7 +255,7 @@ class Training(models.Model): # title = models.CharField(max_length=255) # desc= models.TextField(max_length=2048) person = models.ForeignKey("Person") - area = models.CharField(max_length=255) # Choices? + area = models.CharField(max_length=255) with_whom = models.CharField(max_length=255) # Is this a foreign key to person, or group, or just text field like now? where = models.ForeignKey("TheatreGroup") from_when = models.DateField(blank=True, null=True) diff --git a/itf/itfprofiles/views.py b/itf/itfprofiles/views.py index e326a28..c0d1c6b 100644 --- a/itf/itfprofiles/views.py +++ b/itf/itfprofiles/views.py @@ -8,6 +8,7 @@ from django.template import RequestContext from django.http import HttpResponse, HttpResponseRedirect from django.contrib.auth.decorators import login_required +from datetime import datetime def person_form(request): person = Person.objects.all()[0] @@ -17,7 +18,6 @@ def person_form(request): #pdb.set_trace() return render_to_response("test/person_form.html", {'form': form, 'inlines': inlines}) - @login_required def edit_profile(request): user = request.user @@ -49,10 +49,49 @@ def edit_profile(request): }) return render_to_response("test/person_form.html", context) +@login_required +def friend_invite(request): + if request.method == 'POST': + form = PersonForm(request.POST, request.FILES) + if form.is_valid(): + invitee = 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.send() + try: + invitation.save() + except: + return HttpResponse("Not Invited!!") + return HttpResponse("Invited!!") + + #return HttpResponseRedirect('/invitation/invite/') + else: + return render_to_response('test/popup.html', context) + + else: + form = PersonForm() + context = RequestContext(request, { + 'form': form + }) + return render_to_response("test/popup.html", context) + + +def invitation_accept(request,invite_code): + invitation = get_object_or_404(PersonInvitation, invite_code__exact=invite_code) + request.session['invitation'] = invitation.id + return HttpResponseRedirect('/accounts/madd') + + + def personpopup(request): form = PersonForm() if request.POST: - return HttpResponse("" % ("45", "sanjay bhangar",)) + return HttpResponse("" % ("45", "sanjay bhangar",)) form = PersonForm(request.POST, request.FILES) if form.is_valid(): instance = form.save() diff --git a/itf/settings.py b/itf/settings.py index 36a4203..34a2371 100755 --- a/itf/settings.py +++ b/itf/settings.py @@ -5,6 +5,7 @@ from os.path import join # import markdown SITENAME = "India Theatre Forum" +SITE_HOST = "theatreforum.in" DEBUG = True TEMPLATE_DEBUG = DEBUG JSON_DEBUG = DEBUG @@ -233,10 +234,10 @@ INSTALLED_APPS = ( ) -# jj allauthsettingsa +# jj all auth + email settings LOGIN_REDIRECT_URL = '/edit_profile' #ACCOUNT_AUTHENTICATION_METHOD='' - +DEFAULT_FROM_MAIL='webmaster@%s' % (SITE_HOST,) #ACCOUNT_AUTHENTICATION_METHOD = 'email' ACCOUNT_EMAIL_REQUIRED=True ACCOUNT_EMAIL_VERIFICATION=False @@ -263,8 +264,6 @@ SOCIALACCOUNT_PROVIDERS = { 'openid': name='Google', openid_url='https://www.google.com/accounts/o8/id')]}} -#ACCOUNT_ACTIVATION_DAYS = 30 - #overwrite default settings with local settings try: from local_settings import * diff --git a/itf/templates/registration/activation_email.txt b/itf/templates/registration/activation_email.txt index 3594c80..5760db5 100755 --- a/itf/templates/registration/activation_email.txt +++ b/itf/templates/registration/activation_email.txt @@ -1 +1,8 @@ -Please activate your registration by clicking on this link: http://theatreforum.in/accounts/activate/{{ activation_key }}/ +Hello, +Welcome to the theatre forum circle! + +Please activate your registration by clicking on this link: +http://theatreforum.in/accounts/activate/{{ activation_key }}/ + +-- +India Theatre Forum diff --git a/itf/urls.py b/itf/urls.py index f5082a6..627a942 100755 --- a/itf/urls.py +++ b/itf/urls.py @@ -55,12 +55,17 @@ urlpatterns = patterns('', (r'emailsignuplist', 'festival.views.email_signups'), (r'^favicon.ico$', 'django.views.generic.simple.redirect_to', {'url': '/static/images/favicon.ico'}), + (r'^invitation/(w+)/$','itfprofiles.views.invitation_accept'), + #(r'^invitation/add/$', 'itfprofiles.views.friend_add'), + (r'^invitation/invite/$', 'itfprofiles.views.friend_invite'), +) # (r'^ajax_filtered_fields/', include('ajax_filtered_fields.urls')), # Uncomment the next line to enable the admin: # (r'^test$', 'app.views.index'), # (r'^$', 'festival.views.home') -) + + if settings.LOCAL_DEVELOPMENT: #