-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathforms.py
More file actions
executable file
·71 lines (62 loc) · 3.25 KB
/
forms.py
File metadata and controls
executable file
·71 lines (62 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from django import forms
from spoken_auth.models import TutorialDetails, TutorialResources, FossCategory
from django.db.models import Q
tutorials = (
("Select a Tutorial", "Select a Tutorial"),
)
minutes = ()
seconds = ()
class NewQuestionForm(forms.Form):
category = forms.ChoiceField(choices=[('', 'Select a Category'), ] + list(TutorialResources.objects.filter(
Q(status=1) | Q(status=2), language__name='English',tutorial_detail__foss__show_on_homepage=1).values_list('tutorial_detail__foss__foss',
'tutorial_detail__foss__foss').distinct()),
widget=forms.Select(attrs={}), required=True, error_messages={'required': 'State field is required.'})
title = forms.CharField(max_length=200)
body = forms.CharField(widget=forms.Textarea())
def __init__(self, *args, **kwargs):
category = kwargs.pop('category', None)
selecttutorial = kwargs.pop('tutorial', None)
select_min = kwargs.pop('minute_range', None)
select_sec = kwargs.pop('second_range', None)
super(NewQuestionForm, self).__init__(*args, **kwargs)
tutorial_choices = (
("Select a Tutorial", "Select a Tutorial"),
)
# check minute_range, secpnd_range coming from spoken website
# user clicks on post question link through website
if (select_min is None and select_sec is None):
minutes = (
(select_min, select_min),
)
seconds = (
(select_sec, select_sec),
)
else:
minutes = (
("", "min"),
)
seconds = (
("", "sec"),
)
if not category and args and 'category' in args[0] and args[0]['category']:
category = args[0]['category']
if FossCategory.objects.filter(foss=category).exists():
self.fields['category'].initial = category
tutorials = TutorialDetails.objects.using('spoken').filter(foss__foss=category)
for tutorial in tutorials:
tutorial_choices += ((tutorial.tutorial, tutorial.tutorial),)
self.fields['tutorial'] = forms.CharField(widget=forms.Select(choices=tutorial_choices))
if TutorialDetails.objects.using('spoken').filter(tutorial=selecttutorial).exists():
self.fields['tutorial'].initial = selecttutorial
self.fields['minute_range'] = forms.CharField(widget=forms.Select(choices=minutes))
self.fields['second_range'] = forms.CharField(widget=forms.Select(choices=seconds))
else:
self.fields['minute_range'] = forms.CharField(widget=forms.Select(choices=minutes))
self.fields['second_range'] = forms.CharField(widget=forms.Select(choices=seconds))
else:
self.fields['tutorial'] = forms.CharField(widget=forms.Select(choices=tutorial_choices))
self.fields['minute_range'] = forms.CharField(widget=forms.Select(choices=minutes))
self.fields['second_range'] = forms.CharField(widget=forms.Select(choices=seconds))
class AnswerQuesitionForm(forms.Form):
question = forms.IntegerField(widget=forms.HiddenInput())
body = forms.CharField(widget=forms.Textarea())