Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion static/forums/templates/update-password.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</div>
<div class="sign">
<div class="need">Already Registered? </div>
<div> <a href="/accounts/login/" class="btn btn-sm btn-success">Login </a></div>
<div> <a href="{% url 'user_login' %}?next={{ request.get_full_path|urlencode }}" class="btn btn-sm btn-success">Login </a></div>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion static/website/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
</li> <!-- /li.dropdown -->
{% else %}
<li>
<a href="{% url 'user_login' %}">
<a href="{% url 'user_login' %}?next={{ request.get_full_path|urlencode }}">
<span class="glyphicon glyphicon-user"></span>
Login
</a>
Expand Down
4 changes: 2 additions & 2 deletions static/website/templates/get-question.html
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ <h4><u>Answers:</u></h4>
</a>
{% else %}
<br>
<a class="btn btn-xs btn-success vs" href="/accounts/login">
<a class="btn btn-xs btn-success vs" href="{% url 'user_login' %}?next={{ request.get_full_path|urlencode }}">
Login to add comment
</a>
{% endif %}
Expand Down Expand Up @@ -264,7 +264,7 @@ <h4><u>Answers:</u></h4>
</form>
{% else %}
<h4>
<a class="btn btn-xs btn-success" href="{% url 'user_login'%}"><b>Log-in</b></a> to answer to this question.
<a class="btn btn-xs btn-success" href="{% url 'user_login' %}?next={{ request.get_full_path|urlencode }}"><b>Log-in</b></a> to answer to this question.
</h4>
{% endif %}

Expand Down
61 changes: 49 additions & 12 deletions website/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
)
Expand All @@ -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))
Expand Down