testappproj/testapp/forms.py
author amit@thunder
Mon, 17 May 2010 22:33:59 +0530
changeset 0 0b061d58aea3
child 1 0eda880b3d25
permissions -rw-r--r--
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system

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")
  Solution_Image = forms.ImageField(required=False)
  Session = forms.ChoiceField(choices=SESSION_CHOICES, 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