From 925d616c4137f014f2f55a979b2350ef0409a5b9 Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Mon, 23 Dec 2019 13:06:48 +0530 Subject: Resolve comments - Fix PEP8 - Change the url as per django urlpattern - Replace all the buttons by tag - Use get_queryset() for filtering data for pagination - Make buttons large - Add Pagination in ajax_question_filter.html - Hide Pagination when there is no question object --- yaksh/forms.py | 2 +- yaksh/templates/yaksh/ajax_question_filter.html | 5 ++++- yaksh/templates/yaksh/showquestions.html | 30 +++++++++++++------------ yaksh/views.py | 20 +++++++++++++---- 4 files changed, 37 insertions(+), 20 deletions(-) (limited to 'yaksh') diff --git a/yaksh/forms.py b/yaksh/forms.py index 4a90ef7..ffb15a6 100644 --- a/yaksh/forms.py +++ b/yaksh/forms.py @@ -399,7 +399,7 @@ class ProfileForm(forms.ModelForm): ) class UploadFileForm(forms.Form): - file = forms.FileField(widget=forms.FileInput(attrs={'class':'upload'})) + file = forms.FileField(widget=forms.FileInput(attrs={'class': 'upload'})) class QuestionPaperForm(forms.ModelForm): diff --git a/yaksh/templates/yaksh/ajax_question_filter.html b/yaksh/templates/yaksh/ajax_question_filter.html index ea0d0b5..7dba6df 100644 --- a/yaksh/templates/yaksh/ajax_question_filter.html +++ b/yaksh/templates/yaksh/ajax_question_filter.html @@ -16,6 +16,8 @@ }); {% if questions %} + {% include "yaksh/paginator.html" %} +
Select All
@@ -36,7 +38,7 @@ -
{{question.summary|capfirst}} + {{question.summary|capfirst}} {{question.language|capfirst}} {{question.type|capfirst}} {{question.points}} @@ -45,5 +47,6 @@ + {% include "yaksh/paginator.html" %} {% endif %} diff --git a/yaksh/templates/yaksh/showquestions.html b/yaksh/templates/yaksh/showquestions.html index 31312e2..3353e4a 100644 --- a/yaksh/templates/yaksh/showquestions.html +++ b/yaksh/templates/yaksh/showquestions.html @@ -46,7 +46,7 @@

-
Download Template
+
Download Template

Or

@@ -59,7 +59,7 @@

And

- + Upload File @@ -72,19 +72,19 @@ {% if message %} {%if message == "Questions Uploaded Successfully"%}
- × + {{ message }}
{%else %}
- × + {{ message }}
{% endif %} {% endif %} {% if msg %}
- × + {{ msg }}
{% endif %} @@ -112,7 +112,7 @@ - + @@ -133,13 +133,14 @@
- + + Clear Filters
{% if questions %}
+ {% include "yaksh/paginator.html" %}
Select All
@@ -159,7 +160,7 @@ - {{question.summary|capfirst}} + {{question.summary|capfirst}} {{question.language|capfirst}} {{question.type|capfirst}} {{question.points}} @@ -169,16 +170,17 @@
+ {% include "yaksh/paginator.html" %} {% endif %}
- {% include "yaksh/paginator.html" %}
- + Add Question + {% if questions %} - - + Download Selected + Test Selected {% endif %} - + Delete Selected
diff --git a/yaksh/views.py b/yaksh/views.py index d82d4e0..f5a4b82 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -1324,10 +1324,21 @@ def ajax_questions_filter(request): if language: filter_dict['language'] = str(language) - questions = Question.objects.filter(**filter_dict) - + questions = Question.objects.get_queryset().filter( + **filter_dict).order_by('id') + paginator = Paginator(questions, 10) + page = request.GET.get('page') + try: + questions = paginator.page(page) + except PageNotAnInteger: + questions = paginator.page(1) + except EmptyPage: + questions = paginator.page(paginator.num_pages) return my_render_to_response( - request, 'yaksh/ajax_question_filter.html', {'questions': questions} + request, 'yaksh/ajax_question_filter.html', { + 'questions': questions, + 'objects': questions + } ) @@ -1492,7 +1503,8 @@ def show_all_questions(request): if not is_moderator(user): raise Http404("You are not allowed to view this page !") - questions = Question.objects.filter(user_id=user.id, active=True) + 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) -- cgit