taskapp/forms/user.py
changeset 44 2b09336352b5
parent 40 43853e376bb8
child 47 4e059a4220cc
equal deleted inserted replaced
43:b5b9a4fc508f 44:2b09336352b5
     1 #!/usr/bin/python2.5
     1 #!/usr/bin/python2.5
     2 
     2 
     3 from django import forms
     3 from django import forms
     4 from pytask.taskapp.models import GENDER_CHOICES, Profile
     4 from pytask.taskapp.models import GENDER_CHOICES, Profile
     5 from django.forms import ModelForm
     5 from django.forms import ModelForm
       
     6 from registration.forms import RegistrationForm
       
     7 from registration.models import RegistrationProfile
     6 
     8 
     7 class UserProfileEditForm(ModelForm):
     9 class UserProfileEditForm(ModelForm):
       
    10     """Form used to edit the profile of a user"""
       
    11     
     8     class Meta:
    12     class Meta:
     9         model = Profile
    13         model = Profile
    10         exclude = ('user','rights','dob','credits')
    14         exclude = ('user','rights','dob','credits')
       
    15 
       
    16 class RegistrationFormCustom(RegistrationForm):
       
    17     """Used instead of RegistrationForm used by default django-registration backend, this adds date of birth and gender to the default django-registration RegistrationForm"""
       
    18     
       
    19     dob = forms.DateField(help_text = "YYYY-MM-DD", required=True, label=u'date of birth')
       
    20     gender = forms.ChoiceField(choices = GENDER_CHOICES, required=True, label=u'gender')
       
    21     
       
    22     def save(self,profile_callback=None):
       
    23         new_user = RegistrationProfile.objects.create_inactive_user(username=self.cleaned_data['username'],password=self.cleaned_data['password1'],email=self.cleaned_data['email'])
       
    24         
       
    25         new_profile = Profile(user=new_user,dob=self.cleaned_data['dob'],gender=self.cleaned_data['gender'])
       
    26         new_profile.save()
       
    27         
       
    28         return new_user