taskapp/forms/user.py
author nishanth
Tue, 02 Mar 2010 22:50:17 +0530
changeset 184 8ca20bacc78e
parent 141 2489392ffb56
child 206 85660d75683d
permissions -rw-r--r--
created a starthere page.
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
47
4e059a4220cc user should enter unique email address, changed login_redirect_url.
anoop
parents: 44
diff changeset
     5
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
     6
from registration.models import RegistrationProfile
13
0fb64b24a1c9 added views, templates for register, login, logout user.
anoop
parents: 12
diff changeset
     7
141
2489392ffb56 added the functionality to request a user to be AD MG DV.
nishanth
parents: 47
diff changeset
     8
class UserProfileEditForm(forms.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
     9
    """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
    10
    
23
f33084ea1361 added view profile and edit profile functionalities.
anoop
parents: 13
diff changeset
    11
    class Meta:
f33084ea1361 added view profile and edit profile functionalities.
anoop
parents: 13
diff changeset
    12
        model = Profile
f33084ea1361 added view profile and edit profile functionalities.
anoop
parents: 13
diff changeset
    13
        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
    14
47
4e059a4220cc user should enter unique email address, changed login_redirect_url.
anoop
parents: 44
diff changeset
    15
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
    16
    """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
    17
    
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
    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
    19
    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
    20
    
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
    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
    22
        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
    23
        
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
        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
    25
        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
    26
        
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
        return new_user
141
2489392ffb56 added the functionality to request a user to be AD MG DV.
nishanth
parents: 47
diff changeset
    28
2489392ffb56 added the functionality to request a user to be AD MG DV.
nishanth
parents: 47
diff changeset
    29
def UserChoiceForm(choices, instance=None):
2489392ffb56 added the functionality to request a user to be AD MG DV.
nishanth
parents: 47
diff changeset
    30
    """ take a list of users and return a choice form.
2489392ffb56 added the functionality to request a user to be AD MG DV.
nishanth
parents: 47
diff changeset
    31
    """
2489392ffb56 added the functionality to request a user to be AD MG DV.
nishanth
parents: 47
diff changeset
    32
2489392ffb56 added the functionality to request a user to be AD MG DV.
nishanth
parents: 47
diff changeset
    33
    class myForm(forms.Form):
2489392ffb56 added the functionality to request a user to be AD MG DV.
nishanth
parents: 47
diff changeset
    34
        user = forms.ChoiceField(choices, required=True)
2489392ffb56 added the functionality to request a user to be AD MG DV.
nishanth
parents: 47
diff changeset
    35
    return myForm(instance) if instance else myForm()