testappproj/testapp/forms.py
author amit@thunder
Fri, 25 Jun 2010 03:59:57 +0530
changeset 5 548c6261fa00
parent 4 4d5422e5a45d
permissions -rw-r--r--
A pure python way to compare the solution images
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
     1
from recaptcha.client import captcha
0
0b061d58aea3 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
amit@thunder
parents:
diff changeset
     2
from django import forms
0b061d58aea3 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
amit@thunder
parents:
diff changeset
     3
from registration.forms import RegistrationForm
0b061d58aea3 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
amit@thunder
parents:
diff changeset
     4
from django.utils.translation import ugettext_lazy as _
0b061d58aea3 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
amit@thunder
parents:
diff changeset
     5
from testapp.models import Test_User
0b061d58aea3 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
amit@thunder
parents:
diff changeset
     6
from registration.models import RegistrationProfile
0b061d58aea3 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
amit@thunder
parents:
diff changeset
     7
#from google.appengine.ext.db import djangoforms
0b061d58aea3 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
amit@thunder
parents:
diff changeset
     8
import models
4
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
     9
from django.conf import settings
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    10
from django.utils.safestring import mark_safe
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    11
0
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    12
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    13
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    14
attrs_dict = { 'class': 'required' }
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    15
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    16
PROBLEM_CHOICES=(
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    17
    ('P', 'Plotting'),
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    18
    ('S', 'Scripting'),
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    19
)
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    20
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    21
SESSION_CHOICES=(
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    22
  ('A','DAY 1 SESSION 1'),
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    23
  ('B','DAY 1 SESSION 2'),
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    24
  ('C','DAY 1 SESSION 3'),
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    25
  ('D','DAY 1 SESSION 4'),
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    26
  ('E','DAY 2 SESSION 1'),
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    27
  ('F','DAY 2 SESSION 2'),
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    28
  ('G','DAY 2 SESSION 3'),
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    29
  ('H','DAY 2 SESSION 4'),
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    30
  )
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    31
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    32
4
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    33
# class ReCaptcha(forms.Widget):
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    34
#     input_type = None # Subclasses must define this.
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    35
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    36
#     def render(self, name, value, attrs=None):
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    37
#         final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    38
#         html = u"<script>var RecaptchaOptions = {theme : '%s'};</script>" % (
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    39
#             final_attrs.get('theme', 'white'))
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    40
#         html += captcha.displayhtml(settings.RECAPTCHA_PUBLIC)
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    41
#         return mark_safe(html)
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    42
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    43
#     def value_from_datadict(self, data, files, name):
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    44
#         return {
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    45
#             'recaptcha_challenge_field': data.get('recaptcha_challenge_field', None),
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    46
#             'recaptcha_response_field': data.get('recaptcha_response_field', None),
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    47
#         }
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    48
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    49
# class ReCaptchaField(forms.FileField):
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    50
#     widget = ReCaptcha
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    51
#     default_error_messages = {
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    52
#         'invalid-site-public-key': u"Invalid public key",
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    53
#         'invalid-site-private-key': u"Invalid private key",
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    54
#         'invalid-request-cookie': u"Invalid cookie",
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    55
#         'incorrect-captcha-sol': u"Invalid entry, please try again.",
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    56
#         'verify-params-incorrect': u"The parameters to verify were incorrect, make sure you are passing all the required parameters.",
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    57
#         'invalid-referrer': u"Invalid referrer domain",
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    58
#         'recaptcha-not-reachable': u"Could not contact reCAPTCHA server",
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    59
#     }
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    60
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    61
#     def clean(self, data, initial):
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    62
#         if initial is None or initial == '':
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    63
#             raise Exception("ReCaptchaField requires the client's IP be set to the initial value")
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    64
#         ip = initial
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    65
#         resp = captcha.submit(data.get("recaptcha_challenge_field", None),
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    66
#                               data.get("recaptcha_response_field", None),
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    67
#                               settings.RECAPTCHA_PRIVATE, ip)
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    68
#         if not resp.is_valid:
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    69
#             raise forms.ValidationError(self.default_error_messages.get(
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    70
#                     resp.error_code, "Unknown error: %s" % (resp.error_code)))
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    71
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    72
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    73
0
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    74
class ProblemForm(forms.Form):
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    75
  Description = forms.CharField(widget=forms.Textarea(attrs={'rows': '10', 'cols': '80'}),required=True,help_text="To be used as the question")
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    76
  Problem_type = forms.ChoiceField(choices=PROBLEM_CHOICES,required=True)
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    77
  Solution = forms.CharField(widget=forms.Textarea(attrs={'rows': '10', 'cols': '80'}),help_text="comma seperated in case of multiple solutions",required=False)
0
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    78
  Solution_Image = forms.ImageField(required=False)
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    79
  Session = forms.ChoiceField(choices=SESSION_CHOICES, required=True)
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
    80
  Credit=forms.IntegerField(required=True)
0
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    81
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    82
  class Meta:
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    83
   model = models.Problem
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    84
   exclude = ('author', 'created', 'modified')
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    85
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    86
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    87
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    88
class Test_UserForm(RegistrationForm):
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    89
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    90
  Fullname = forms.CharField(widget=forms.TextInput(attrs=attrs_dict))
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    91
  Address =  forms.CharField(widget=forms.TextInput(attrs=attrs_dict))
4
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    92
#  captcha = ReCaptchaField()
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    93
0
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    94
  class Meta:
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    95
        exclude = ('special_user','exam_done')
0
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    96
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    97
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    98
  def save(self, profile_callback=None):
0b061d58aea3 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
amit@thunder
parents:
diff changeset
    99
    new_user = RegistrationProfile.objects.create_inactive_user(username=self.cleaned_data['username'],
0b061d58aea3 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
amit@thunder
parents:
diff changeset
   100
                                                                password=self.cleaned_data['password1'],
0b061d58aea3 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
amit@thunder
parents:
diff changeset
   101
                                                                email=self.cleaned_data['email'])
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   102
    new_profile = Test_User(user=new_user, fullname=self.cleaned_data['Fullname'],address=self.cleaned_data['Address'])
0
0b061d58aea3 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
amit@thunder
parents:
diff changeset
   103
    new_profile.save()
0b061d58aea3 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
amit@thunder
parents:
diff changeset
   104
    return new_user
0b061d58aea3 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
amit@thunder
parents:
diff changeset
   105
0b061d58aea3 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
amit@thunder
parents:
diff changeset
   106
0b061d58aea3 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
amit@thunder
parents:
diff changeset
   107
0b061d58aea3 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
amit@thunder
parents:
diff changeset
   108
class UploadForm(forms.Form):
0b061d58aea3 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
amit@thunder
parents:
diff changeset
   109
  file = forms.FileField()
0b061d58aea3 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
amit@thunder
parents:
diff changeset
   110
0b061d58aea3 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
amit@thunder
parents:
diff changeset
   111
  class Meta:
0b061d58aea3 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
amit@thunder
parents:
diff changeset
   112
    model = None