summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoradityacp2020-04-15 15:33:55 +0530
committeradityacp2020-04-15 15:33:55 +0530
commit6ac89a48fcd349dcc9d097cb76fe9eda934ad19d (patch)
treeb35aaa9c27b9b1499d5dc4b8166209edcbfde84b
parent9b7c8c7f6eb3e93f1bc28d118da165a7c600cbb3 (diff)
downloadonline_test-6ac89a48fcd349dcc9d097cb76fe9eda934ad19d.tar.gz
online_test-6ac89a48fcd349dcc9d097cb76fe9eda934ad19d.tar.bz2
online_test-6ac89a48fcd349dcc9d097cb76fe9eda934ad19d.zip
Show selected values in the filter forms
-rw-r--r--yaksh/forms.py54
-rw-r--r--yaksh/templates/yaksh/showquestions.html2
-rw-r--r--yaksh/views.py35
3 files changed, 56 insertions, 35 deletions
diff --git a/yaksh/forms.py b/yaksh/forms.py
index d2627d7..81b067c 100644
--- a/yaksh/forms.py
+++ b/yaksh/forms.py
@@ -344,28 +344,37 @@ class RandomQuestionForm(forms.Form):
class QuestionFilterForm(forms.Form):
+
+ language = forms.ChoiceField(
+ choices=languages,
+ widget=forms.Select(attrs={'class': 'custom-select'}),
+ required=False
+ )
+ question_type = forms.ChoiceField(
+ choices=question_types,
+ widget=forms.Select(attrs={'class': 'custom-select'}),
+ required=False
+ )
+
def __init__(self, *args, **kwargs):
user = kwargs.pop("user")
+ lang = kwargs.pop("language") if "language" in kwargs else None
+ que_type = kwargs.pop("type") if "type" in kwargs else None
+ marks = kwargs.pop("marks") if "marks" in kwargs else None
super(QuestionFilterForm, self).__init__(*args, **kwargs)
- questions = Question.objects.filter(user_id=user.id)
- points_list = questions.values_list('points', flat=True).distinct()
- points_options = [(None, 'Select Marks')]
- points_options.extend([(point, point) for point in points_list])
- self.fields['marks'] = forms.FloatField(
- widget=forms.Select(choices=points_options,
- attrs={'class': 'custom-select'})
+ points = Question.objects.filter(
+ user_id=user.id).values_list('points', flat=True).distinct()
+ points_options = [('', 'Select Marks')]
+ points_options.extend([(point, point) for point in points])
+ self.fields['marks'] = forms.ChoiceField(
+ choices=points_options,
+ widget=forms.Select(attrs={'class': 'custom-select'}),
+ required=False
)
self.fields['marks'].required = False
- language = forms.CharField(
- max_length=8, widget=forms.Select(
- choices=languages, attrs={'class': 'custom-select'}),
- required=False
- )
- question_type = forms.CharField(
- max_length=8, widget=forms.Select(
- choices=question_types, attrs={'class': 'custom-select'}),
- required=False
- )
+ self.fields['language'].initial = lang
+ self.fields['question_type'].initial = que_type
+ self.fields['marks'].initial = marks
class SearchFilterForm(forms.Form):
@@ -375,11 +384,18 @@ class SearchFilterForm(forms.Form):
'class': form_input_class,}),
required=False
)
- search_status = forms.CharField(max_length=16, widget=forms.Select(
+ search_status = forms.ChoiceField(
choices=status_types,
- attrs={'class': 'custom-select'}),
+ widget=forms.Select(attrs={'class': 'custom-select'})
)
+ def __init__(self, *args, **kwargs):
+ status = kwargs.pop("status") if "status" in kwargs else None
+ tags = kwargs.pop("tags") if "tags" in kwargs else None
+ super(SearchFilterForm, self).__init__(*args, **kwargs)
+ self.fields["search_status"].initial = status
+ self.fields["search_tags"].initial = tags
+
class CourseForm(forms.ModelForm):
""" course form for moderators """
diff --git a/yaksh/templates/yaksh/showquestions.html b/yaksh/templates/yaksh/showquestions.html
index 8f1bdaf..daeaea7 100644
--- a/yaksh/templates/yaksh/showquestions.html
+++ b/yaksh/templates/yaksh/showquestions.html
@@ -13,7 +13,7 @@
{% block content %}
<div class="container-fluid">
<div class="nav nav-pills" role="tablist" aria-orientation="vertical">
- <a href="#show" id="showbar" class="nav-link active" data-toggle="pill" role="tab" aria-controls="show" aria-selected="true"> Show all Questions</a>
+ <a href="#show" id="showbar" class="nav-link active" data-toggle="pill" role="tab" aria-controls="show" aria-selected="true"> All Questions</a>
<a href="#updown" id="updownbar" class="nav-link" data-toggle="pill" role="tab" aria-controls="updown" aria-selected="false" > Upload Questions</a>
</div>
<br>
diff --git a/yaksh/views.py b/yaksh/views.py
index 1d7a8c6..90d3d2b 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -1070,20 +1070,20 @@ def courses(request):
Q(creator=user) | Q(teachers=user),
is_trial=False).order_by('-active').distinct()
- form = SearchFilterForm()
+ tags = request.GET.get('search_tags')
+ status = request.GET.get('search_status')
- course_tags = request.GET.get('search_tags')
- course_status = request.GET.get('search_status')
+ form = SearchFilterForm(tags=tags, status=status)
- if course_status == 'select' and course_tags:
+ if status == 'select' and tags:
courses = courses.filter(
- name__icontains=course_tags)
- elif course_status == 'active' :
+ name__icontains=tags)
+ elif status == 'active':
courses = courses.filter(
- name__icontains=course_tags, active=True)
- elif course_status == 'closed':
+ name__icontains=tags, active=True)
+ elif status == 'closed':
courses = courses.filter(
- name__icontains=course_tags, active=False)
+ name__icontains=tags, active=False)
paginator = Paginator(courses, 30)
page = request.GET.get('page')
@@ -1556,9 +1556,12 @@ def show_all_questions(request):
user, False, question_ids, None)
trial_paper.update_total_marks()
trial_paper.save()
- return my_redirect(reverse("yaksh:start_quiz",
- args=[1, trial_module.id, trial_paper.id, trial_course.id]
- ))
+ return my_redirect(
+ reverse("yaksh:start_quiz",
+ args=[1, trial_module.id, trial_paper.id,
+ trial_course.id]
+ )
+ )
else:
message = "Please select atleast one question to test"
@@ -1591,15 +1594,16 @@ def questions_filter(request):
questions = Question.objects.get_queryset().filter(
user_id=user.id, active=True).order_by('-id')
- form = QuestionFilterForm(user=user)
user_tags = questions.values_list('tags', flat=True).distinct()
all_tags = Tag.objects.filter(id__in=user_tags)
- form = QuestionFilterForm(user=user)
upload_form = UploadFileForm()
filter_dict = {}
question_type = request.GET.get('question_type')
marks = request.GET.get('marks')
language = request.GET.get('language')
+ form = QuestionFilterForm(
+ user=user, language=language, marks=marks, type=question_type
+ )
if question_type:
filter_dict['type'] = str(question_type)
if marks:
@@ -1664,8 +1668,9 @@ def test_question(request, question_id):
return my_redirect(
reverse("yaksh:start_quiz",
args=[1, trial_module.id, trial_paper.id, trial_course.id]
+ )
)
- )
+
@login_required
@email_verified