testappproj/testapp/forms.py
changeset 0 0b061d58aea3
child 1 0eda880b3d25
equal deleted inserted replaced
-1:000000000000 0:0b061d58aea3
       
     1 from django import forms
       
     2 from registration.forms import RegistrationForm
       
     3 from django.utils.translation import ugettext_lazy as _
       
     4 from testapp.models import Test_User
       
     5 from registration.models import RegistrationProfile
       
     6 #from google.appengine.ext.db import djangoforms
       
     7 import models
       
     8 
       
     9 
       
    10 attrs_dict = { 'class': 'required' }
       
    11 
       
    12 PROBLEM_CHOICES=(
       
    13     ('P', 'Plotting'),
       
    14     ('S', 'Scripting'),
       
    15 )
       
    16 
       
    17 SESSION_CHOICES=(
       
    18   ('A','DAY 1 SESSION 1'),
       
    19   ('B','DAY 1 SESSION 2'),
       
    20   ('C','DAY 1 SESSION 3'),
       
    21   ('D','DAY 1 SESSION 4'),
       
    22   ('E','DAY 2 SESSION 1'),
       
    23   ('F','DAY 2 SESSION 2'),
       
    24   ('G','DAY 2 SESSION 3'),
       
    25   ('H','DAY 2 SESSION 4'),
       
    26   )
       
    27 
       
    28 
       
    29 class ProblemForm(forms.Form):
       
    30   Description = forms.CharField(widget=forms.Textarea(attrs={'rows': '10', 'cols': '80'}),required=True,help_text="To be used as the question")
       
    31   Problem_type = forms.ChoiceField(choices=PROBLEM_CHOICES,required=True)
       
    32   Solution = forms.CharField(widget=forms.Textarea(attrs={'rows': '10', 'cols': '80'}),help_text="comma seperated in case of multiple solutions")
       
    33   Solution_Image = forms.ImageField(required=False)
       
    34   Session = forms.ChoiceField(choices=SESSION_CHOICES, required=True)
       
    35 
       
    36 
       
    37   class Meta:
       
    38    model = models.Problem
       
    39    exclude = ('author', 'created', 'modified')
       
    40 
       
    41 
       
    42 
       
    43 class Test_UserForm(RegistrationForm):
       
    44 
       
    45   fullname = forms.CharField(widget=forms.TextInput(attrs=attrs_dict))
       
    46   class Meta:
       
    47         exclude = ('special_user',)
       
    48 
       
    49 
       
    50   def save(self, profile_callback=None):
       
    51     new_user = RegistrationProfile.objects.create_inactive_user(username=self.cleaned_data['username'],
       
    52                                                                 password=self.cleaned_data['password1'],
       
    53                                                                 email=self.cleaned_data['email'])
       
    54     new_profile = Test_User(user=new_user, fullname=self.cleaned_data[fullname])
       
    55     new_profile.save()
       
    56     return new_user
       
    57 
       
    58 
       
    59 
       
    60 class UploadForm(forms.Form):
       
    61   file = forms.FileField()
       
    62 
       
    63   class Meta:
       
    64     model = None