diff options
author | CruiseDevice | 2019-12-23 13:06:48 +0530 |
---|---|---|
committer | CruiseDevice | 2020-01-02 16:20:31 +0530 |
commit | 925d616c4137f014f2f55a979b2350ef0409a5b9 (patch) | |
tree | d1747de34407fde93e108810a5feeee242a8e341 | |
parent | 75e8fb06b42420f21c8571341ef8300a102cd2c7 (diff) | |
download | online_test-925d616c4137f014f2f55a979b2350ef0409a5b9.tar.gz online_test-925d616c4137f014f2f55a979b2350ef0409a5b9.tar.bz2 online_test-925d616c4137f014f2f55a979b2350ef0409a5b9.zip |
Resolve comments
- Fix PEP8
- Change the url as per django urlpattern
- Replace all the buttons by <a> 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
-rw-r--r-- | yaksh/forms.py | 2 | ||||
-rw-r--r-- | yaksh/templates/yaksh/ajax_question_filter.html | 5 | ||||
-rw-r--r-- | yaksh/templates/yaksh/showquestions.html | 30 | ||||
-rw-r--r-- | yaksh/views.py | 20 |
4 files changed, 37 insertions, 20 deletions
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 @@ }); </script> {% if questions %} + {% include "yaksh/paginator.html" %} + <h5 class="highlight"><input type="checkbox" id="checkall"> Select All </h5> @@ -36,7 +38,7 @@ <td> <input type="checkbox" name="question" value="{{ question.id }}"> </td> - <td><a href="{{URL_ROOT}}/exam/manage/addquestion/{{ question.id }}">{{question.summary|capfirst}}</a></td> + <td><a href="{% url 'yaksh:add_question' question.id %}">{{question.summary|capfirst}}</a></td> <td>{{question.language|capfirst}}</td> <td>{{question.type|capfirst}}</td> <td>{{question.points}}</td> @@ -45,5 +47,6 @@ </tbody> </table> </ul> + {% include "yaksh/paginator.html" %} {% endif %} </div> 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 @@ </p> </div> <div class="card-body"> - <div><a class="btn btn-primary" href="{% url 'yaksh:download_yaml_template' %}">Download Template</a></div> + <div><a class="btn btn-lg btn-primary" href="{% url 'yaksh:download_yaml_template' %}">Download Template</a></div> <br/> <h4> Or </h4> <form action="" method="post" enctype="multipart/form-data"> @@ -59,7 +59,7 @@ </div> </div> <h4>And</h4> - <button class="btn btn-success" type="submit" name="upload" value="upload">Upload File</button> + <a class="btn btn-lg btn-success" type="submit" name="upload" value="upload">Upload File</a> </form> </div> </div> @@ -72,19 +72,19 @@ {% if message %} {%if message == "Questions Uploaded Successfully"%} <div class="alert alert-success alert-dismissable"> - <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a> + <a href="#" class="close" data-dismiss="alert" aria-label="close"><span class="fa fa-window-close"></span></a> {{ message }} </div> {%else %} <div class="alert alert-danger alert-dismissable"> - <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a> + <a href="#" class="close" data-dismiss="alert" aria-label="close"><span class="fa fa-window-close"></span></a> {{ message }} </div> {% endif %} {% endif %} {% if msg %} <div class="alert alert-danger alert-dismissable animated flash"> - <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a> + <a href="#" class="close" data-dismiss="alert" aria-label="close"><span class="fa fa-window-close"></span></a> {{ msg }} </div> {% endif %} @@ -112,7 +112,7 @@ </div> <input type="text" name="question_tags" id="question_tags" class="form-control" type="search" placeholder="Search using comma separated Tags"> <span class="input-group-append"> - <button class="btn btn-outline-secondary" type="submit"><i class="fa fa-search yakshred"></i></button> + <a class="btn btn-outline-secondary" type="submit"><i class="fa fa-search yakshred"></i></a> </span> </div> </div> @@ -133,13 +133,14 @@ </div> </div> <br/> - <button class="btn btn-primary" type="button" onClick='location.replace("{{URL_ROOT}}");'> - Clear Filters</button> + <a class="btn btn-lg btn-primary" type="button" onClick='location.replace("{% url 'yaksh:show_questions' %}");'> + Clear Filters</a> </div> </div> <div id="filtered-questions"> {% if questions %} <div> + {% include "yaksh/paginator.html" %} <br> <h5><input id="checkall" type="checkbox"> Select All </h5> <div class="table-wrapper-2"> @@ -159,7 +160,7 @@ <td> <input type="checkbox" name="question" value="{{ question.id }}"> </td> - <td><a href="{{URL_ROOT}}/exam/manage/addquestion/{{ question.id }}">{{question.summary|capfirst}}</a></td> + <td><a href="{% url 'yaksh:add_question' question.id %}">{{question.summary|capfirst}}</a></td> <td>{{question.language|capfirst}}</td> <td>{{question.type|capfirst}}</td> <td>{{question.points}}</td> @@ -169,16 +170,17 @@ </table> </div> </div> + {% include "yaksh/paginator.html" %} {% endif %} </div> - {% include "yaksh/paginator.html" %} <center> - <button class="btn btn-primary" type="button" onclick='location.replace("{{URL_ROOT}}/exam/manage/addquestion/");'>Add Question</button> + <a class="btn btn-lg btn-primary" type="button" onclick='location.replace("{% url 'yaksh:add_question' %}");'>Add Question</a> + {% if questions %} - <button class="btn btn-primary" type="submit" name='download' value='download'>Download Selected</button> - <button class="btn btn-primary" type="submit" name="test" value="test">Test Selected</button> + <a class="btn btn-lg btn-primary" type="submit" name='download' value='download'>Download Selected</a> + <a class="btn btn-lg btn-primary" type="submit" name="test" value="test">Test Selected</a> {% endif %} - <button class="btn btn-danger" type="submit" onClick="return confirm_delete(frm);" name='delete' value='delete'>Delete Selected</button> + <a class="btn btn-lg btn-danger" type="submit" onClick="return confirm_delete(frm);" name='delete' value='delete'>Delete Selected</a> </center> </form> </div> 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) |