diff --git a/static/forums/templates/update-password.html b/static/forums/templates/update-password.html
index b54e95c..f510884 100755
--- a/static/forums/templates/update-password.html
+++ b/static/forums/templates/update-password.html
@@ -33,7 +33,7 @@
diff --git a/static/website/templates/base.html b/static/website/templates/base.html
index 0152830..578adc2 100644
--- a/static/website/templates/base.html
+++ b/static/website/templates/base.html
@@ -100,7 +100,7 @@
{% else %}
-
+
Login
diff --git a/static/website/templates/get-question.html b/static/website/templates/get-question.html
index 7bc8bc0..9025017 100755
--- a/static/website/templates/get-question.html
+++ b/static/website/templates/get-question.html
@@ -231,7 +231,7 @@ Answers:
{% else %}
-
+
Login to add comment
{% endif %}
@@ -264,7 +264,7 @@ Answers:
{% else %}
- Log-in to answer to this question.
+ Log-in to answer to this question.
{% endif %}
diff --git a/website/forms.py b/website/forms.py
index cd32f52..1d9391f 100755
--- a/website/forms.py
+++ b/website/forms.py
@@ -9,37 +9,72 @@
seconds = ()
+def _get_category_choices():
+ """Distinct FOSS categories for new-question form, sorted alphabetically."""
+ categories = 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', flat=True)
+ .distinct()
+ )
+ # Remove empty/None and sort case-insensitively (A-Z)
+ categories = [c for c in categories if c]
+ categories = sorted(set(categories), key=lambda x: x.lower())
+ return [('', 'Select a Category')] + [(c, c) for c in categories]
+
+
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.'})
+ category = forms.ChoiceField(
+ choices=[],
+ 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):
+ # Values that can be passed explicitly (e.g. from the spoken website)
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)
+ self.fields['category'].choices = _get_category_choices()
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):
+
+ # If no explicit minute/second values were provided (e.g. normal POST),
+ # preserve any values that came from submitted form data so that
+ # validation errors (like missing reCAPTCHA) do not wipe them out.
+ data = args[0] if args else {}
+ if select_min is None and data and 'minute_range' in data:
+ select_min = data.get('minute_range')
+ if select_sec is None and data and 'second_range' in data:
+ select_sec = data.get('second_range')
+
+ # When a minute/second value is available (from the spoken website or a
+ # previous form submission), show that value as the only selectable
+ # option; otherwise show the default placeholders.
+ if select_min:
minutes = (
(select_min, select_min),
)
- seconds = (
- (select_sec, select_sec),
- )
else:
minutes = (
("", "min"),
)
+
+ if select_sec:
+ seconds = (
+ (select_sec, select_sec),
+ )
+ else:
seconds = (
("", "sec"),
)
@@ -48,7 +83,9 @@ def __init__(self, *args, **kwargs):
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)
+ tutorials = TutorialDetails.objects.using('spoken').filter(
+ foss__foss=category
+ ).order_by('level', 'order')
for tutorial in tutorials:
tutorial_choices += ((tutorial.tutorial, tutorial.tutorial),)
self.fields['tutorial'] = forms.CharField(widget=forms.Select(choices=tutorial_choices))