testappproj/testapp/forms.py
author amit@thunder
Mon, 31 May 2010 19:18:57 +0530
changeset 2 654c583fd78e
parent 1 0eda880b3d25
child 3 34d0c21e3352
permissions -rw-r--r--
Made some changes and templates

from django import forms
from registration.forms import RegistrationForm
from django.utils.translation import ugettext_lazy as _
from testapp.models import Test_User
from registration.models import RegistrationProfile
#from google.appengine.ext.db import djangoforms
import models


attrs_dict = { 'class': 'required' }

PROBLEM_CHOICES=(
    ('P', 'Plotting'),
    ('S', 'Scripting'),
)

SESSION_CHOICES=(
  ('A','DAY 1 SESSION 1'),
  ('B','DAY 1 SESSION 2'),
  ('C','DAY 1 SESSION 3'),
  ('D','DAY 1 SESSION 4'),
  ('E','DAY 2 SESSION 1'),
  ('F','DAY 2 SESSION 2'),
  ('G','DAY 2 SESSION 3'),
  ('H','DAY 2 SESSION 4'),
  )


class ProblemForm(forms.Form):
  Description = forms.CharField(widget=forms.Textarea(attrs={'rows': '10', 'cols': '80'}),required=True,help_text="To be used as the question")
  Problem_type = forms.ChoiceField(choices=PROBLEM_CHOICES,required=True)
  Solution = forms.CharField(widget=forms.Textarea(attrs={'rows': '10', 'cols': '80'}),help_text="comma seperated in case of multiple solutions",required=False)
  Solution_Image = forms.ImageField(required=False)
  Session = forms.ChoiceField(choices=SESSION_CHOICES, required=True)
  Credit=forms.IntegerField(required=True)

  class Meta:
   model = models.Problem
   exclude = ('author', 'created', 'modified')



class Test_UserForm(RegistrationForm):

  fullname = forms.CharField(widget=forms.TextInput(attrs=attrs_dict))
  class Meta:
        exclude = ('special_user',)


  def save(self, profile_callback=None):
    new_user = RegistrationProfile.objects.create_inactive_user(username=self.cleaned_data['username'],
                                                                password=self.cleaned_data['password1'],
                                                                email=self.cleaned_data['email'])
    new_profile = Test_User(user=new_user, fullname=self.cleaned_data[fullname])
    new_profile.save()
    return new_user



class UploadForm(forms.Form):
  file = forms.FileField()

  class Meta:
    model = None