From ce3eb1dbbd924003489d01f4e98aba841cd803c0 Mon Sep 17 00:00:00 2001 From: adityacp Date: Wed, 8 Apr 2020 15:55:59 +0530 Subject: Change templates, views, forms, models - Allow to test, download and delete single question - Fix pagination for searching and filtering questions --- yaksh/forms.py | 15 +- yaksh/models.py | 2 +- yaksh/static/yaksh/js/question_filter.js | 47 ---- yaksh/static/yaksh/js/show_question.js | 17 +- yaksh/templates/yaksh/ajax_question_filter.html | 57 ----- yaksh/templates/yaksh/paginator.html | 6 +- yaksh/templates/yaksh/showquestions.html | 277 ++++++++++++------------ yaksh/urls.py | 10 +- yaksh/views.py | 169 +++++++++++---- 9 files changed, 305 insertions(+), 295 deletions(-) delete mode 100644 yaksh/static/yaksh/js/question_filter.js delete mode 100644 yaksh/templates/yaksh/ajax_question_filter.html (limited to 'yaksh') diff --git a/yaksh/forms.py b/yaksh/forms.py index 52ef75d..d2627d7 100644 --- a/yaksh/forms.py +++ b/yaksh/forms.py @@ -17,9 +17,9 @@ from string import punctuation, digits import pytz from .send_emails import generate_activation_key -languages = (("select", "Select Language"),) + languages +languages = (("", "Select Language"),) + languages -question_types = (("select", "Select Question Type"),) + question_types +question_types = (("", "Select Question Type"),) + question_types test_case_types = ( ("standardtestcase", "Standard Testcase"), @@ -357,11 +357,14 @@ class QuestionFilterForm(forms.Form): ) self.fields['marks'].required = False language = forms.CharField( - max_length=8, widget=forms.Select(choices=languages, - attrs={'class': 'custom-select'})) + 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'}) + max_length=8, widget=forms.Select( + choices=question_types, attrs={'class': 'custom-select'}), + required=False ) diff --git a/yaksh/models.py b/yaksh/models.py index 52a0414..5d4d453 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -1385,7 +1385,7 @@ class Question(models.Model): testcases.append(case.get_field_value()) q_dict['testcase'] = testcases q_dict['files'] = file_names - q_dict['tags'] = [tags.tag.name for tags in q_dict['tags']] + q_dict['tags'] = [tag.name for tag in q_dict['tags']] questions_dict.append(q_dict) question._add_yaml_to_zip(zip_file, questions_dict) return zip_file_name diff --git a/yaksh/static/yaksh/js/question_filter.js b/yaksh/static/yaksh/js/question_filter.js deleted file mode 100644 index aa3a229..0000000 --- a/yaksh/static/yaksh/js/question_filter.js +++ /dev/null @@ -1,47 +0,0 @@ -$(document).ready(function(){ - $question_type = $("#id_question_type"); - $marks = $("#id_marks"); - $language = $("#id_language"); - - function question_filter() { - $.ajax({ - url: "/exam/ajax/questions/filter/", - type: "POST", - data: { - question_type: $question_type.val(), - marks: $marks.val(), - language: $language.val() - }, - dataType: "html", - success: function(output) { - var questions = $(output).filter("#questions").html(); - $("#filtered-questions").html(questions); - } - }); - } - - $question_type.change(function() { - question_filter() - }); - - $language.change(function() { - question_filter() - }); - - $marks.change(function() { - question_filter() - }); - - $("#checkall").change(function(){ - if($(this).prop("checked")) { - $("#filtered-questions input:checkbox").each(function(index, element) { - $(this).prop('checked', true); - }); - } - else { - $("#filtered-questions input:checkbox").each(function(index, element) { - $(this).prop('checked', false); - }); - } - }); -}); \ No newline at end of file diff --git a/yaksh/static/yaksh/js/show_question.js b/yaksh/static/yaksh/js/show_question.js index e6825a0..d7b6a44 100644 --- a/yaksh/static/yaksh/js/show_question.js +++ b/yaksh/static/yaksh/js/show_question.js @@ -47,7 +47,18 @@ function append_tag(tag){ tag_name.value = tag.value; } } -$(document).ready(function() - { - $("#questions-table").tablesorter({sortList: [[0,0], [4,0]]}); +$(document).ready(function() { + $("#questions-table").tablesorter({}); + $("#checkall").change(function(){ + if($(this).prop("checked")) { + $("#filtered-questions input:checkbox").each(function(index, element) { + $(this).prop('checked', true); + }); + } + else { + $("#filtered-questions input:checkbox").each(function(index, element) { + $(this).prop('checked', false); + }); + } }); +}); diff --git a/yaksh/templates/yaksh/ajax_question_filter.html b/yaksh/templates/yaksh/ajax_question_filter.html deleted file mode 100644 index 18f14ff..0000000 --- a/yaksh/templates/yaksh/ajax_question_filter.html +++ /dev/null @@ -1,57 +0,0 @@ -
- -
- -  Add Question - -

- {% if questions %} - {% include "yaksh/paginator.html" %} - -
- Select All -
- - {% include "yaksh/paginator.html" %} - {% endif %} -
diff --git a/yaksh/templates/yaksh/paginator.html b/yaksh/templates/yaksh/paginator.html index 5f0df7a..c634d5c 100644 --- a/yaksh/templates/yaksh/paginator.html +++ b/yaksh/templates/yaksh/paginator.html @@ -1,7 +1,7 @@