From 9b7ccda4ddd0ce20b4aad646d7bf2559c0c7c15e Mon Sep 17 00:00:00 2001 From: Johnson Chetty Date: Fri, 14 Dec 2012 13:30:13 +0100 Subject: [PATCH] email invites 0.8 --- itf/allauth/account/views.py | 6 ++++++ itf/itfprofiles/forms.py | 2 +- itf/itfprofiles/models.py | 4 ++-- itf/itfprofiles/views.py | 5 ++++- itf/templates/allauth/account/signup.html | 7 ++++++- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/itf/allauth/account/views.py b/itf/allauth/account/views.py index ff9d9e3..9e45228 100644 --- a/itf/allauth/account/views.py +++ b/itf/allauth/account/views.py @@ -58,6 +58,7 @@ def signup(request, **kwargs): template_name = kwargs.pop("template_name", "account/signup.html") redirect_field_name = kwargs.pop("redirect_field_name", "next") success_url = kwargs.pop("success_url", None) + invite_code = kwargs.pop("invite_code", None) if success_url is None: success_url = get_default_redirect(request, redirect_field_name) @@ -66,6 +67,11 @@ def signup(request, **kwargs): form = form_class(request.POST) if form.is_valid(): user = form.save(request=request) + if invite_code: + from itfprofiles.models import PersonInvitation, Person + person = PersonInvite.objects.get(invite_code=invite_code).invitee + person.user = user + #success_url = '/edit_profile' return complete_signup(request, user, success_url) else: diff --git a/itf/itfprofiles/forms.py b/itf/itfprofiles/forms.py index e899a82..eaeedb3 100644 --- a/itf/itfprofiles/forms.py +++ b/itf/itfprofiles/forms.py @@ -253,7 +253,7 @@ class ItfAllAuthRegForm(forms.Form): def save(self, user, request=None): first_name = self.cleaned_data['firstname'] last_name = self.cleaned_data['lastname'] - if request.session['invite_code']: + if request.session.has_key('invite_code'): invite_code = request.session['invite_code'] pi = PersonInvitation.objects.get(invite_code=invite_code) inviter = pi.inviter diff --git a/itf/itfprofiles/models.py b/itf/itfprofiles/models.py index 932a231..fb85a56 100644 --- a/itf/itfprofiles/models.py +++ b/itf/itfprofiles/models.py @@ -27,8 +27,8 @@ class Person(ItfModel): #ItfModel stuff: form_names = ['PersonForm', 'PopupPersonForm'] fts_fields = ['first_name', 'last_name', 'email', 'about'] -#Basic Info - user = models.ForeignKey(User, blank=True, null=True, db_index=True, editable=False) + #Basic Info + user = models.OneToOneField(User, blank=True, null=True, db_index=True, editable=False) first_name = models.CharField(max_length=255) last_name = models.CharField(max_length=255) email = models.EmailField(blank=True, null=True, unique=True, db_index=True) diff --git a/itf/itfprofiles/views.py b/itf/itfprofiles/views.py index f008a64..c71fbba 100644 --- a/itf/itfprofiles/views.py +++ b/itf/itfprofiles/views.py @@ -84,8 +84,11 @@ def friend_invite(request): def invitation_accept(request,invite_code): - #invitation = get_object_or_404(PersonInvitation, invite_code__exact=invite_code) + invitee = get_object_or_404(PersonInvitation, invite_code__exact=invite_code).invitee request.session['invite_code'] = invite_code + request.session['invitee_first_name'] = invitee.first_name + request.session['invtee_last_name'] = invitee.last_name + request.session['invitee_email'] = invitee.email return HttpResponseRedirect('/accounts/signup') diff --git a/itf/templates/allauth/account/signup.html b/itf/templates/allauth/account/signup.html index 2981377..eb9449f 100644 --- a/itf/templates/allauth/account/signup.html +++ b/itf/templates/allauth/account/signup.html @@ -14,7 +14,12 @@
{% csrf_token %} - {{ form.as_p }} + {{ form.as_p }} + + {% if request.session.invite_code %} + + {% endif %} + {% if redirect_field_value %} {% endif %}