upload/forms.py
author Madhusudan.C.S <madhusudancs@gmail.com>
Thu, 03 Sep 2009 18:52:01 +0530
changeset 19 6af9056ccac9
parent 18 07408d1ced76
permissions -rw-r--r--
Fixed terms and conditions bug.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
4d2bbb2f3c4e Added models and views.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
     1
from django import forms
4d2bbb2f3c4e Added models and views.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
     2
4
ac11fee16880 Updated settings.py
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3
diff changeset
     3
from spoken_tut.upload.models import Participant
2
4d2bbb2f3c4e Added models and views.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
     4
18
07408d1ced76 Added CSS and I accept terms and condition.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 17
diff changeset
     5
2
4d2bbb2f3c4e Added models and views.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
     6
class ParticipantForm(forms.ModelForm):
18
07408d1ced76 Added CSS and I accept terms and condition.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 17
diff changeset
     7
  def clean_other_lang(self):
07408d1ced76 Added CSS and I accept terms and condition.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 17
diff changeset
     8
    """Cleaner for validating Other language field.
07408d1ced76 Added CSS and I accept terms and condition.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 17
diff changeset
     9
    """
07408d1ced76 Added CSS and I accept terms and condition.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 17
diff changeset
    10
    cleaned_data = self.cleaned_data
07408d1ced76 Added CSS and I accept terms and condition.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 17
diff changeset
    11
    lang = cleaned_data.get('language')
07408d1ced76 Added CSS and I accept terms and condition.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 17
diff changeset
    12
    other_lang = cleaned_data.get('other_lang')
07408d1ced76 Added CSS and I accept terms and condition.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 17
diff changeset
    13
    if lang == 'Other' and not other_lang:
07408d1ced76 Added CSS and I accept terms and condition.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 17
diff changeset
    14
      raise forms.ValidationError('Please fill in the other language field.')
07408d1ced76 Added CSS and I accept terms and condition.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 17
diff changeset
    15
07408d1ced76 Added CSS and I accept terms and condition.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 17
diff changeset
    16
    return other_lang
17
08a47999f316 Added submissions page.
Shantanu <shantanu@fossee.in>
parents: 4
diff changeset
    17
18
07408d1ced76 Added CSS and I accept terms and condition.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 17
diff changeset
    18
  def clean(self):
07408d1ced76 Added CSS and I accept terms and condition.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 17
diff changeset
    19
    """Form cleaner for accepting the terms and conditions.
07408d1ced76 Added CSS and I accept terms and condition.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 17
diff changeset
    20
    """
19
6af9056ccac9 Fixed terms and conditions bug.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 18
diff changeset
    21
6af9056ccac9 Fixed terms and conditions bug.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 18
diff changeset
    22
    data = self.data
6af9056ccac9 Fixed terms and conditions bug.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 18
diff changeset
    23
    accept = data.get('accept')
6af9056ccac9 Fixed terms and conditions bug.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 18
diff changeset
    24
    
18
07408d1ced76 Added CSS and I accept terms and condition.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 17
diff changeset
    25
    if not accept:
07408d1ced76 Added CSS and I accept terms and condition.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 17
diff changeset
    26
      raise forms.ValidationError(
07408d1ced76 Added CSS and I accept terms and condition.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 17
diff changeset
    27
          'You need to accept the terms and condition for uploading the data.')
2
4d2bbb2f3c4e Added models and views.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    28
19
6af9056ccac9 Fixed terms and conditions bug.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 18
diff changeset
    29
    return self.cleaned_data
18
07408d1ced76 Added CSS and I accept terms and condition.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 17
diff changeset
    30
07408d1ced76 Added CSS and I accept terms and condition.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 17
diff changeset
    31
  class Meta:
07408d1ced76 Added CSS and I accept terms and condition.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 17
diff changeset
    32
    model = Participant