88minutes = ()
99seconds = ()
1010
11- # Pre-fetch FOSS ids shown on homepage
12- foss_ids = list (
13- FossCategory .objects .using ('spoken' )
14- .filter (show_on_homepage = 1 )
15- .values_list ('id' , flat = True ) # get ids only
16- )
17-
1811
1912class NewQuestionForm (forms .Form ):
20- category = forms .ChoiceField (
21- choices = [('' , 'Select a Category' )] +
22- list (
23- TutorialResources .objects .using ('spoken' )
24- .filter (
25- Q (status__in = [1 , 2 ]), # cleaner than Q(status=1)|Q(status=2)
26- language_id = 22 , # use id instead of name
27- tutorial_detail__foss_id__in = foss_ids
28- )
29- .values ('tutorial_detail__foss__foss' )
30- .order_by ('tutorial_detail__foss__foss' )
31- .values_list ('tutorial_detail__foss__foss' , 'tutorial_detail__foss__foss' )
32- .distinct ()
33- ),
34- widget = forms .Select (attrs = {}),
35- required = True ,
36- error_messages = {'required' : 'State field is required.' }
37- )
38-
13+ category = forms .ChoiceField (choices = [('' , 'Select a Category' ), ] + list (TutorialResources .objects .filter (
14+ Q (status = 1 ) | Q (status = 2 ), language__name = 'English' ,tutorial_detail__foss__show_on_homepage = 1 ).values ('tutorial_detail__foss__foss' ).order_by (
15+ 'tutorial_detail__foss__foss' ).values_list ('tutorial_detail__foss__foss' ,
16+ 'tutorial_detail__foss__foss' ).distinct ()),
17+ widget = forms .Select (attrs = {}), required = True , error_messages = {'required' : 'State field is required.' })
3918 title = forms .CharField (max_length = 200 )
4019 body = forms .CharField (widget = forms .Textarea ())
4120
@@ -45,43 +24,49 @@ def __init__(self, *args, **kwargs):
4524
4625 select_min = kwargs .pop ('minute_range' , None )
4726 select_sec = kwargs .pop ('second_range' , None )
48-
4927 super (NewQuestionForm , self ).__init__ (* args , ** kwargs )
50-
51- tutorial_choices = (("Select a Tutorial" , "Select a Tutorial" ),)
52-
53- # Set minutes & seconds
54- if select_min is None and select_sec is None :
55- minutes = ((select_min , select_min ),)
56- seconds = ((select_sec , select_sec ),)
28+ tutorial_choices = (
29+ ("Select a Tutorial" , "Select a Tutorial" ),
30+ )
31+ # check minute_range, secpnd_range coming from spoken website
32+ # user clicks on post question link through website
33+ if (select_min is None and select_sec is None ):
34+ minutes = (
35+ (select_min , select_min ),
36+ )
37+ seconds = (
38+ (select_sec , select_sec ),
39+ )
5740 else :
58- minutes = (("" , "min" ),)
59- seconds = (("" , "sec" ),)
41+ minutes = (
42+ ("" , "min" ),
43+ )
44+ seconds = (
45+ ("" , "sec" ),
46+ )
6047
61- # Handle category logic
6248 if not category and args and 'category' in args [0 ] and args [0 ]['category' ]:
6349 category = args [0 ]['category' ]
64-
65- if FossCategory .objects .using ('spoken' ).filter (foss = category ).exists ():
50+ if FossCategory .objects .filter (foss = category ).exists ():
6651 self .fields ['category' ].initial = category
6752 tutorials = TutorialDetails .objects .using ('spoken' ).filter (foss__foss = category )
6853 for tutorial in tutorials :
6954 tutorial_choices += ((tutorial .tutorial , tutorial .tutorial ),)
70-
7155 self .fields ['tutorial' ] = forms .CharField (widget = forms .Select (choices = tutorial_choices ))
72-
7356 if TutorialDetails .objects .using ('spoken' ).filter (tutorial = selecttutorial ).exists ():
7457 self .fields ['tutorial' ].initial = selecttutorial
7558
76- self .fields ['minute_range' ] = forms .CharField (widget = forms .Select (choices = minutes ))
77- self .fields ['second_range' ] = forms .CharField (widget = forms .Select (choices = seconds ))
59+ self .fields ['minute_range' ] = forms .CharField (widget = forms .Select (choices = minutes ))
60+ self .fields ['second_range' ] = forms .CharField (widget = forms .Select (choices = seconds ))
61+ else :
62+ self .fields ['minute_range' ] = forms .CharField (widget = forms .Select (choices = minutes ))
63+ self .fields ['second_range' ] = forms .CharField (widget = forms .Select (choices = seconds ))
7864 else :
7965 self .fields ['tutorial' ] = forms .CharField (widget = forms .Select (choices = tutorial_choices ))
8066 self .fields ['minute_range' ] = forms .CharField (widget = forms .Select (choices = minutes ))
8167 self .fields ['second_range' ] = forms .CharField (widget = forms .Select (choices = seconds ))
8268
8369
84-
8570class AnswerQuesitionForm (forms .Form ):
8671 question = forms .IntegerField (widget = forms .HiddenInput ())
87- body = forms .CharField (widget = forms .Textarea ())
72+ body = forms .CharField (widget = forms .Textarea ())
0 commit comments