taskapp/forms/user.py
author nishanth
Sun, 28 Feb 2010 10:43:36 +0530
changeset 140 7bdcbb4f2c27
parent 47 4e059a4220cc
child 141 2489392ffb56
permissions -rw-r--r--
now learn more pages open in a new window.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13
0fb64b24a1c9 added views, templates for register, login, logout user.
anoop
parents: 12
diff changeset
     1
#!/usr/bin/python2.5
0fb64b24a1c9 added views, templates for register, login, logout user.
anoop
parents: 12
diff changeset
     2
0fb64b24a1c9 added views, templates for register, login, logout user.
anoop
parents: 12
diff changeset
     3
from django import forms
23
f33084ea1361 added view profile and edit profile functionalities.
anoop
parents: 13
diff changeset
     4
from pytask.taskapp.models import GENDER_CHOICES, Profile
f33084ea1361 added view profile and edit profile functionalities.
anoop
parents: 13
diff changeset
     5
from django.forms import ModelForm
47
4e059a4220cc user should enter unique email address, changed login_redirect_url.
anoop
parents: 44
diff changeset
     6
from registration.forms import RegistrationFormUniqueEmail
44
2b09336352b5 fixed creation of user profile at registration time, added custom registration form so as to include dob and gender.
anoop
parents: 40
diff changeset
     7
from registration.models import RegistrationProfile
13
0fb64b24a1c9 added views, templates for register, login, logout user.
anoop
parents: 12
diff changeset
     8
23
f33084ea1361 added view profile and edit profile functionalities.
anoop
parents: 13
diff changeset
     9
class UserProfileEditForm(ModelForm):
44
2b09336352b5 fixed creation of user profile at registration time, added custom registration form so as to include dob and gender.
anoop
parents: 40
diff changeset
    10
    """Form used to edit the profile of a user"""
2b09336352b5 fixed creation of user profile at registration time, added custom registration form so as to include dob and gender.
anoop
parents: 40
diff changeset
    11
    
23
f33084ea1361 added view profile and edit profile functionalities.
anoop
parents: 13
diff changeset
    12
    class Meta:
f33084ea1361 added view profile and edit profile functionalities.
anoop
parents: 13
diff changeset
    13
        model = Profile
f33084ea1361 added view profile and edit profile functionalities.
anoop
parents: 13
diff changeset
    14
        exclude = ('user','rights','dob','credits')
44
2b09336352b5 fixed creation of user profile at registration time, added custom registration form so as to include dob and gender.
anoop
parents: 40
diff changeset
    15
47
4e059a4220cc user should enter unique email address, changed login_redirect_url.
anoop
parents: 44
diff changeset
    16
class RegistrationFormCustom(RegistrationFormUniqueEmail):
44
2b09336352b5 fixed creation of user profile at registration time, added custom registration form so as to include dob and gender.
anoop
parents: 40
diff changeset
    17
    """Used instead of RegistrationForm used by default django-registration backend, this adds date of birth and gender to the default django-registration RegistrationForm"""
2b09336352b5 fixed creation of user profile at registration time, added custom registration form so as to include dob and gender.
anoop
parents: 40
diff changeset
    18
    
2b09336352b5 fixed creation of user profile at registration time, added custom registration form so as to include dob and gender.
anoop
parents: 40
diff changeset
    19
    dob = forms.DateField(help_text = "YYYY-MM-DD", required=True, label=u'date of birth')
2b09336352b5 fixed creation of user profile at registration time, added custom registration form so as to include dob and gender.
anoop
parents: 40
diff changeset
    20
    gender = forms.ChoiceField(choices = GENDER_CHOICES, required=True, label=u'gender')
2b09336352b5 fixed creation of user profile at registration time, added custom registration form so as to include dob and gender.
anoop
parents: 40
diff changeset
    21
    
2b09336352b5 fixed creation of user profile at registration time, added custom registration form so as to include dob and gender.
anoop
parents: 40
diff changeset
    22
    def save(self,profile_callback=None):
2b09336352b5 fixed creation of user profile at registration time, added custom registration form so as to include dob and gender.
anoop
parents: 40
diff changeset
    23
        new_user = RegistrationProfile.objects.create_inactive_user(username=self.cleaned_data['username'],password=self.cleaned_data['password1'],email=self.cleaned_data['email'])
2b09336352b5 fixed creation of user profile at registration time, added custom registration form so as to include dob and gender.
anoop
parents: 40
diff changeset
    24
        
2b09336352b5 fixed creation of user profile at registration time, added custom registration form so as to include dob and gender.
anoop
parents: 40
diff changeset
    25
        new_profile = Profile(user=new_user,dob=self.cleaned_data['dob'],gender=self.cleaned_data['gender'])
2b09336352b5 fixed creation of user profile at registration time, added custom registration form so as to include dob and gender.
anoop
parents: 40
diff changeset
    26
        new_profile.save()
2b09336352b5 fixed creation of user profile at registration time, added custom registration form so as to include dob and gender.
anoop
parents: 40
diff changeset
    27
        
2b09336352b5 fixed creation of user profile at registration time, added custom registration form so as to include dob and gender.
anoop
parents: 40
diff changeset
    28
        return new_user