|
1 from recaptcha.client import captcha |
1 from django import forms |
2 from django import forms |
2 from registration.forms import RegistrationForm |
3 from registration.forms import RegistrationForm |
3 from django.utils.translation import ugettext_lazy as _ |
4 from django.utils.translation import ugettext_lazy as _ |
4 from testapp.models import Test_User |
5 from testapp.models import Test_User |
5 from registration.models import RegistrationProfile |
6 from registration.models import RegistrationProfile |
6 #from google.appengine.ext.db import djangoforms |
7 #from google.appengine.ext.db import djangoforms |
7 import models |
8 import models |
|
9 from django.conf import settings |
|
10 from django.utils.safestring import mark_safe |
|
11 |
8 |
12 |
9 |
13 |
10 attrs_dict = { 'class': 'required' } |
14 attrs_dict = { 'class': 'required' } |
11 |
15 |
12 PROBLEM_CHOICES=( |
16 PROBLEM_CHOICES=( |
24 ('G','DAY 2 SESSION 3'), |
28 ('G','DAY 2 SESSION 3'), |
25 ('H','DAY 2 SESSION 4'), |
29 ('H','DAY 2 SESSION 4'), |
26 ) |
30 ) |
27 |
31 |
28 |
32 |
|
33 # class ReCaptcha(forms.Widget): |
|
34 # input_type = None # Subclasses must define this. |
|
35 |
|
36 # def render(self, name, value, attrs=None): |
|
37 # final_attrs = self.build_attrs(attrs, type=self.input_type, name=name) |
|
38 # html = u"<script>var RecaptchaOptions = {theme : '%s'};</script>" % ( |
|
39 # final_attrs.get('theme', 'white')) |
|
40 # html += captcha.displayhtml(settings.RECAPTCHA_PUBLIC) |
|
41 # return mark_safe(html) |
|
42 |
|
43 # def value_from_datadict(self, data, files, name): |
|
44 # return { |
|
45 # 'recaptcha_challenge_field': data.get('recaptcha_challenge_field', None), |
|
46 # 'recaptcha_response_field': data.get('recaptcha_response_field', None), |
|
47 # } |
|
48 |
|
49 # class ReCaptchaField(forms.FileField): |
|
50 # widget = ReCaptcha |
|
51 # default_error_messages = { |
|
52 # 'invalid-site-public-key': u"Invalid public key", |
|
53 # 'invalid-site-private-key': u"Invalid private key", |
|
54 # 'invalid-request-cookie': u"Invalid cookie", |
|
55 # 'incorrect-captcha-sol': u"Invalid entry, please try again.", |
|
56 # 'verify-params-incorrect': u"The parameters to verify were incorrect, make sure you are passing all the required parameters.", |
|
57 # 'invalid-referrer': u"Invalid referrer domain", |
|
58 # 'recaptcha-not-reachable': u"Could not contact reCAPTCHA server", |
|
59 # } |
|
60 |
|
61 # def clean(self, data, initial): |
|
62 # if initial is None or initial == '': |
|
63 # raise Exception("ReCaptchaField requires the client's IP be set to the initial value") |
|
64 # ip = initial |
|
65 # resp = captcha.submit(data.get("recaptcha_challenge_field", None), |
|
66 # data.get("recaptcha_response_field", None), |
|
67 # settings.RECAPTCHA_PRIVATE, ip) |
|
68 # if not resp.is_valid: |
|
69 # raise forms.ValidationError(self.default_error_messages.get( |
|
70 # resp.error_code, "Unknown error: %s" % (resp.error_code))) |
|
71 |
|
72 |
|
73 |
29 class ProblemForm(forms.Form): |
74 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") |
75 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) |
76 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",required=False) |
77 Solution = forms.CharField(widget=forms.Textarea(attrs={'rows': '10', 'cols': '80'}),help_text="comma seperated in case of multiple solutions",required=False) |
33 Solution_Image = forms.ImageField(required=False) |
78 Solution_Image = forms.ImageField(required=False) |