pytask/taskapp/forms/user.py
author anoop
Mon, 01 Feb 2010 14:08:18 +0530
changeset 16 d57e63325759
parent 6 94136f9a48bc
child 21 3e676fa948c4
permissions -rw-r--r--
added view profile and edit profile functionalities.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
94136f9a48bc added login, logout, and register.
anoop
parents: 5
diff changeset
     1
#!/usr/bin/python2.5
94136f9a48bc added login, logout, and register.
anoop
parents: 5
diff changeset
     2
94136f9a48bc added login, logout, and register.
anoop
parents: 5
diff changeset
     3
from django import forms
16
d57e63325759 added view profile and edit profile functionalities.
anoop
parents: 6
diff changeset
     4
from pytask.taskapp.models import GENDER_CHOICES, Profile
d57e63325759 added view profile and edit profile functionalities.
anoop
parents: 6
diff changeset
     5
from django.forms import ModelForm
6
94136f9a48bc added login, logout, and register.
anoop
parents: 5
diff changeset
     6
94136f9a48bc added login, logout, and register.
anoop
parents: 5
diff changeset
     7
class RegistrationForm(forms.Form):
94136f9a48bc added login, logout, and register.
anoop
parents: 5
diff changeset
     8
    username = forms.CharField(max_length=30, required=True)
94136f9a48bc added login, logout, and register.
anoop
parents: 5
diff changeset
     9
    password = forms.CharField(max_length=60, required=True, widget=forms.PasswordInput)
94136f9a48bc added login, logout, and register.
anoop
parents: 5
diff changeset
    10
    repeat_password = forms.CharField(max_length=60, required=True, widget=forms.PasswordInput)
94136f9a48bc added login, logout, and register.
anoop
parents: 5
diff changeset
    11
    email = forms.EmailField(max_length=30, required=True)
94136f9a48bc added login, logout, and register.
anoop
parents: 5
diff changeset
    12
    gender = forms.ChoiceField(choices=GENDER_CHOICES, required = True)
94136f9a48bc added login, logout, and register.
anoop
parents: 5
diff changeset
    13
    dob = forms.DateField(required=True, help_text = "(YYYY-MM-DD)")
94136f9a48bc added login, logout, and register.
anoop
parents: 5
diff changeset
    14
94136f9a48bc added login, logout, and register.
anoop
parents: 5
diff changeset
    15
class LoginForm(forms.Form):
94136f9a48bc added login, logout, and register.
anoop
parents: 5
diff changeset
    16
    username = forms.CharField(max_length=30, required=True)
94136f9a48bc added login, logout, and register.
anoop
parents: 5
diff changeset
    17
    password = forms.CharField(max_length=60, required=True, widget=forms.PasswordInput)
16
d57e63325759 added view profile and edit profile functionalities.
anoop
parents: 6
diff changeset
    18
d57e63325759 added view profile and edit profile functionalities.
anoop
parents: 6
diff changeset
    19
class UserProfileForm(ModelForm):
d57e63325759 added view profile and edit profile functionalities.
anoop
parents: 6
diff changeset
    20
    class Meta:
d57e63325759 added view profile and edit profile functionalities.
anoop
parents: 6
diff changeset
    21
        model = Profile
d57e63325759 added view profile and edit profile functionalities.
anoop
parents: 6
diff changeset
    22
        exclude = ('user','rights')
d57e63325759 added view profile and edit profile functionalities.
anoop
parents: 6
diff changeset
    23
    def __init__(self, *args, **kwargs):
d57e63325759 added view profile and edit profile functionalities.
anoop
parents: 6
diff changeset
    24
        super(UserProfileForm, self).__init__(*args, **kwargs)
d57e63325759 added view profile and edit profile functionalities.
anoop
parents: 6
diff changeset
    25
        instance = getattr(self, 'instance', None)
d57e63325759 added view profile and edit profile functionalities.
anoop
parents: 6
diff changeset
    26
        if instance and instance.id:
d57e63325759 added view profile and edit profile functionalities.
anoop
parents: 6
diff changeset
    27
            self.fields['dob'].widget.attrs['readonly'] = True
d57e63325759 added view profile and edit profile functionalities.
anoop
parents: 6
diff changeset
    28
            self.fields['gender'].widget.attrs['readonly'] = True
d57e63325759 added view profile and edit profile functionalities.
anoop
parents: 6
diff changeset
    29
            self.fields['credits'].widget.attrs['readonly'] = True
d57e63325759 added view profile and edit profile functionalities.
anoop
parents: 6
diff changeset
    30
            self.fields['aboutme'].widget.attrs['readonly'] = True
d57e63325759 added view profile and edit profile functionalities.
anoop
parents: 6
diff changeset
    31
            self.fields['foss_comm'].widget.attrs['readonly'] = True
d57e63325759 added view profile and edit profile functionalities.
anoop
parents: 6
diff changeset
    32
            self.fields['phonenum'].widget.attrs['readonly'] = True
d57e63325759 added view profile and edit profile functionalities.
anoop
parents: 6
diff changeset
    33
            self.fields['homepage'].widget.attrs['readonly'] = True
d57e63325759 added view profile and edit profile functionalities.
anoop
parents: 6
diff changeset
    34
            self.fields['street'].widget.attrs['readonly'] = True
d57e63325759 added view profile and edit profile functionalities.
anoop
parents: 6
diff changeset
    35
            self.fields['city'].widget.attrs['readonly'] = True
d57e63325759 added view profile and edit profile functionalities.
anoop
parents: 6
diff changeset
    36
            self.fields['country'].widget.attrs['readonly'] = True
d57e63325759 added view profile and edit profile functionalities.
anoop
parents: 6
diff changeset
    37
            self.fields['nick'].widget.attrs['readonly'] = True
d57e63325759 added view profile and edit profile functionalities.
anoop
parents: 6
diff changeset
    38
        #fields = ['dob','gender','credits','aboutme','foss_comm','phonenum','homepage','street','city','country','nick']
d57e63325759 added view profile and edit profile functionalities.
anoop
parents: 6
diff changeset
    39
d57e63325759 added view profile and edit profile functionalities.
anoop
parents: 6
diff changeset
    40
class UserProfileEditForm(ModelForm):
d57e63325759 added view profile and edit profile functionalities.
anoop
parents: 6
diff changeset
    41
    class Meta:
d57e63325759 added view profile and edit profile functionalities.
anoop
parents: 6
diff changeset
    42
        model = Profile
d57e63325759 added view profile and edit profile functionalities.
anoop
parents: 6
diff changeset
    43
        exclude = ('user','rights','dob','credits')