event/forms.py
author nishanth
Tue, 20 Apr 2010 15:31:21 +0530
changeset 12 81cd0140a0f2
parent 9 601057af86c2
child 62 baddb55f8da7
permissions -rw-r--r--
created the register user functionality.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9
601057af86c2 implemented event create
nishanth
parents:
diff changeset
     1
from django import forms
601057af86c2 implemented event create
nishanth
parents:
diff changeset
     2
601057af86c2 implemented event create
nishanth
parents:
diff changeset
     3
from offline.event.models import Event
601057af86c2 implemented event create
nishanth
parents:
diff changeset
     4
601057af86c2 implemented event create
nishanth
parents:
diff changeset
     5
class EventCreateForm(forms.ModelForm):
601057af86c2 implemented event create
nishanth
parents:
diff changeset
     6
601057af86c2 implemented event create
nishanth
parents:
diff changeset
     7
    class Meta:
601057af86c2 implemented event create
nishanth
parents:
diff changeset
     8
        model = Event
601057af86c2 implemented event create
nishanth
parents:
diff changeset
     9
        fields = ['title', 'start_date', 'stop_date']
601057af86c2 implemented event create
nishanth
parents:
diff changeset
    10
601057af86c2 implemented event create
nishanth
parents:
diff changeset
    11
    def clean_start_date(self):
601057af86c2 implemented event create
nishanth
parents:
diff changeset
    12
        return self.cleaned_data['start_date']
601057af86c2 implemented event create
nishanth
parents:
diff changeset
    13
601057af86c2 implemented event create
nishanth
parents:
diff changeset
    14
    def clean_stop_date(self):
601057af86c2 implemented event create
nishanth
parents:
diff changeset
    15
601057af86c2 implemented event create
nishanth
parents:
diff changeset
    16
        stop_date = self.cleaned_data['stop_date']
601057af86c2 implemented event create
nishanth
parents:
diff changeset
    17
        start_date = self.clean_start_date()
601057af86c2 implemented event create
nishanth
parents:
diff changeset
    18
601057af86c2 implemented event create
nishanth
parents:
diff changeset
    19
        if start_date > stop_date:
601057af86c2 implemented event create
nishanth
parents:
diff changeset
    20
            raise forms.ValidationError("Event cannot stop before it starts")
601057af86c2 implemented event create
nishanth
parents:
diff changeset
    21
601057af86c2 implemented event create
nishanth
parents:
diff changeset
    22
        return self.cleaned_data['stop_date']
12
81cd0140a0f2 created the register user functionality.
nishanth
parents: 9
diff changeset
    23