9
|
1 |
from django import forms
|
|
2 |
|
62
|
3 |
from offline.event.models import Event, QUIZ_CHOICES
|
|
4 |
from offline.quiz.models import TOPICS_CHOICES
|
9
|
5 |
|
|
6 |
class EventCreateForm(forms.ModelForm):
|
|
7 |
|
|
8 |
class Meta:
|
|
9 |
model = Event
|
|
10 |
fields = ['title', 'start_date', 'stop_date']
|
|
11 |
|
|
12 |
def clean_start_date(self):
|
|
13 |
return self.cleaned_data['start_date']
|
|
14 |
|
|
15 |
def clean_stop_date(self):
|
|
16 |
|
|
17 |
stop_date = self.cleaned_data['stop_date']
|
|
18 |
start_date = self.clean_start_date()
|
|
19 |
|
|
20 |
if start_date > stop_date:
|
|
21 |
raise forms.ValidationError("Event cannot stop before it starts")
|
|
22 |
|
|
23 |
return self.cleaned_data['stop_date']
|
12
|
24 |
|
62
|
25 |
class OpenQuizForm(forms.Form):
|
|
26 |
|
|
27 |
quiz_num = forms.ChoiceField(required=True, widget=forms.RadioSelect, choices=QUIZ_CHOICES)
|
|
28 |
topics = forms.MultipleChoiceField(required=True, widget=forms.CheckboxSelectMultiple, choices=TOPIC_CHOICES,)
|
|
29 |
|
|
30 |
def clean_topics(self):
|
|
31 |
|
|
32 |
return self.cleaned_data["topics"]
|