fixed creation of user profile at registration time, added custom registration form so as to include dob and gender.
authoranoop
Thu, 18 Feb 2010 19:39:54 +0530
changeset 44 2b09336352b5
parent 43 b5b9a4fc508f
child 45 ab8918e654ae
fixed creation of user profile at registration time, added custom registration form so as to include dob and gender.
taskapp/forms/user.py
urls.py
--- a/taskapp/forms/user.py	Wed Feb 17 19:28:18 2010 +0530
+++ b/taskapp/forms/user.py	Thu Feb 18 19:39:54 2010 +0530
@@ -3,8 +3,26 @@
 from django import forms
 from pytask.taskapp.models import GENDER_CHOICES, Profile
 from django.forms import ModelForm
+from registration.forms import RegistrationForm
+from registration.models import RegistrationProfile
 
 class UserProfileEditForm(ModelForm):
+    """Form used to edit the profile of a user"""
+    
     class Meta:
         model = Profile
         exclude = ('user','rights','dob','credits')
+
+class RegistrationFormCustom(RegistrationForm):
+    """Used instead of RegistrationForm used by default django-registration backend, this adds date of birth and gender to the default django-registration RegistrationForm"""
+    
+    dob = forms.DateField(help_text = "YYYY-MM-DD", required=True, label=u'date of birth')
+    gender = forms.ChoiceField(choices = GENDER_CHOICES, required=True, label=u'gender')
+    
+    def save(self,profile_callback=None):
+        new_user = RegistrationProfile.objects.create_inactive_user(username=self.cleaned_data['username'],password=self.cleaned_data['password1'],email=self.cleaned_data['email'])
+        
+        new_profile = Profile(user=new_user,dob=self.cleaned_data['dob'],gender=self.cleaned_data['gender'])
+        new_profile.save()
+        
+        return new_user
--- a/urls.py	Wed Feb 17 19:28:18 2010 +0530
+++ b/urls.py	Thu Feb 18 19:39:54 2010 +0530
@@ -7,6 +7,8 @@
 from pytask.taskapp.views import user as userViews
 from pytask.taskapp.views import task as taskViews
 
+from pytask.taskapp.forms.user import RegistrationFormCustom
+from registration.views import register
 
 urlpatterns = patterns('',
     # Example:
@@ -29,6 +31,7 @@
     
     (r'^admin/', include(admin.site.urls)),
     
+    url(r'^accounts/register/$',register,{'form_class' : RegistrationFormCustom},name='registration_register'),
     (r'^accounts/', include('registration.urls')),
     (r'^accounts/profile/$', userViews.view_my_profile),