summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPrabhu Ramachandran2015-09-01 13:03:56 +0530
committerPrabhu Ramachandran2015-09-01 13:03:56 +0530
commitc9abbadbb0e6a4a60edb7ef2a14d6c74648b0677 (patch)
tree8a140c6e2869885b5f53ac8204a8b6ed4a2436a2
parent44cb800dec3fb81fa084ef59ebe4b54f0b389bc1 (diff)
parentdbab99bc13b8483c24706e47a9a0926508e3c332 (diff)
downloadonline_test-c9abbadbb0e6a4a60edb7ef2a14d6c74648b0677.tar.gz
online_test-c9abbadbb0e6a4a60edb7ef2a14d6c74648b0677.tar.bz2
online_test-c9abbadbb0e6a4a60edb7ef2a14d6c74648b0677.zip
Merge pull request #54 from ankitjavalkar/filter-sort
Filter fields for questions
-rw-r--r--testapp/exam/forms.py17
-rw-r--r--testapp/exam/static/exam/js/question_filter.js47
-rw-r--r--testapp/exam/templates/exam/ajax_question_filter.html15
-rw-r--r--testapp/exam/templates/exam/showquestions.html23
-rw-r--r--testapp/exam/urls.py2
-rw-r--r--testapp/exam/views.py42
6 files changed, 142 insertions, 4 deletions
diff --git a/testapp/exam/forms.py b/testapp/exam/forms.py
index 20ed7b4..124d79f 100644
--- a/testapp/exam/forms.py
+++ b/testapp/exam/forms.py
@@ -237,5 +237,22 @@ class RandomQuestionForm(forms.Form):
(choices=(('select', 'Select Marks'),)))
shuffle_questions = forms.BooleanField(required=False)
+
+class QuestionFilterForm(forms.Form):
+ def __init__(self, *args, **kwargs):
+ super(QuestionFilterForm, self).__init__(*args, **kwargs)
+ questions = Question.objects.all()
+ points_list = questions.values_list('points', flat=True).distinct()
+ points_options = [('select', 'Select Marks')]
+ points_options.extend([(point, point) for point in points_list])
+ self.fields['marks'] = forms.FloatField(widget=forms.Select\
+ (choices=points_options))
+
+ language = forms.CharField(max_length=8, widget=forms.Select\
+ (choices=languages))
+ question_type = forms.CharField(max_length=8, widget=forms.Select\
+ (choices=question_types))
+
+
TestCaseFormSet = inlineformset_factory(Question, TestCase,\
can_order=False, can_delete=False, extra=1)
diff --git a/testapp/exam/static/exam/js/question_filter.js b/testapp/exam/static/exam/js/question_filter.js
new file mode 100644
index 0000000..065b06b
--- /dev/null
+++ b/testapp/exam/static/exam/js/question_filter.js
@@ -0,0 +1,47 @@
+$(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").live("click", function(){
+ if($(this).attr("checked")) {
+ $("#filtered-questions input:checkbox").each(function(index, element) {
+ $(this).attr('checked', true);
+ });
+ }
+ else {
+ $("#filtered-questions input:checkbox").each(function(index, element) {
+ $(this).attr('checked', false);
+ });
+ }
+ });
+}); \ No newline at end of file
diff --git a/testapp/exam/templates/exam/ajax_question_filter.html b/testapp/exam/templates/exam/ajax_question_filter.html
new file mode 100644
index 0000000..11bf660
--- /dev/null
+++ b/testapp/exam/templates/exam/ajax_question_filter.html
@@ -0,0 +1,15 @@
+<div id="questions">
+ {% if questions %}
+ <h5 class="highlight"><input type="checkbox" id="checkall" class="ignore"> Select All </h5>
+ {% endif %}
+ <ul class="inputs-list">
+
+ {% for question in questions %}
+ <li>
+ <label>
+ <input type="checkbox" name="question" data-qid="{{question.id}}">&nbsp;&nbsp;<a href="{{URL_ROOT}}/exam/manage/addquestion/{{ question.id }}">{{ question }}</a><br>
+ </label>
+ </li>
+ {% endfor %}
+ </ul>
+</div>
diff --git a/testapp/exam/templates/exam/showquestions.html b/testapp/exam/templates/exam/showquestions.html
index 62b40e4..d593ab8 100644
--- a/testapp/exam/templates/exam/showquestions.html
+++ b/testapp/exam/templates/exam/showquestions.html
@@ -4,15 +4,38 @@
{% block subtitle %}List of Questions {% endblock %}
{% block script %}
+<script src="{{ URL_ROOT }}/static/exam/js/min.js"></script>
<script src="{{ URL_ROOT }}/static/exam/js/show_question.js"></script>
+<script src="{{ URL_ROOT }}/static/exam/js/question_filter.js"></script>
{% endblock %}
{% block manage %}
<form name=frm action="" method="post">
{% csrf_token %}
+<div class="row" id="selectors">
+ <h5 style="padding-left: 20px;">Filters</h5>
+ <div class="span4">
+ {{ form.question_type }}
+ </div>
+ <div class="span4">
+ {{ form.language }}
+ </div>
+ <div class="span4">
+ {{ form.marks }}
+ </div>
+</div>
+<br>
+<div class="row">
+<div class="span16">
+ <button class="btn" type="button" onClick='location.replace("{{URL_ROOT}}");'>Clear Filters</button>
+</div>
+</div>
+<br>
+<div id="filtered-questions">
{% for i in questions %}
<input type="checkbox" name="question" value="{{ i.id }}">&nbsp;&nbsp;<a href="{{URL_ROOT}}/exam/manage/addquestion/{{ i.id }}">{{ i }}</a><br>
{% endfor %}
+</div>
<br>
<button class="btn" type="button" onclick='location.replace("{{URL_ROOT}}/exam/manage/addquestion/");'>Add Question</button>&nbsp;&nbsp;
<button class="btn" type="submit" name='edit' value='edit' onClick="return confirm_edit(frm);">Edit Selected</button>&nbsp;&nbsp;
diff --git a/testapp/exam/urls.py b/testapp/exam/urls.py
index 43970ce..c87df9a 100644
--- a/testapp/exam/urls.py
+++ b/testapp/exam/urls.py
@@ -47,4 +47,6 @@ urlpatterns = patterns('testapp.exam.views',
url(r'^manage/designquestionpaper/manual/(?P<questionpaper_id>\d+)/$',\
'manual_questionpaper'),
url(r'^ajax/questionpaper/(?P<query>.+)/$', 'ajax_questionpaper'),
+ url(r'^ajax/questions/filter/$', 'ajax_questions_filter'), ##@@
+
)
diff --git a/testapp/exam/views.py b/testapp/exam/views.py
index 69d16d7..f39f3c1 100644
--- a/testapp/exam/views.py
+++ b/testapp/exam/views.py
@@ -19,7 +19,8 @@ import json
from testapp.exam.models import Quiz, Question, QuestionPaper, QuestionSet
from testapp.exam.models import Profile, Answer, AnswerPaper, User, TestCase
from testapp.exam.forms import UserRegisterForm, UserLoginForm, QuizForm,\
- QuestionForm, RandomQuestionForm, TestCaseFormSet
+ QuestionForm, RandomQuestionForm, TestCaseFormSet,\
+ QuestionFilterForm
from testapp.exam.xmlrpc_clients import code_server
from settings import URL_ROOT
from testapp.exam.models import AssignmentUpload
@@ -1249,6 +1250,30 @@ def show_all_quiz(request):
context_instance=ci)
+@csrf_exempt
+def ajax_questions_filter(request):
+ """Ajax call made when filtering displayed questions."""
+
+ filter_dict = {}
+ question_type = request.POST.get('question_type')
+ marks = request.POST.get('marks')
+ language = request.POST.get('language')
+
+ if question_type != "select":
+ filter_dict['type'] = str(question_type)
+
+ if marks != "select":
+ filter_dict['points'] = marks
+
+ if language != "select":
+ filter_dict['language'] = str(language)
+
+ questions = list(Question.objects.filter(**filter_dict))
+
+ return my_render_to_response('exam/ajax_question_filter.html',
+ {'questions': questions})
+
+
def show_all_questions(request):
"""Show a list of all the questions currently in the databse."""
@@ -1261,18 +1286,24 @@ def show_all_questions(request):
data = request.POST.getlist('question')
if data is None:
questions = Question.objects.all()
+ form = QuestionFilterForm()
context = {'papers': [],
'question': None,
- 'questions': questions}
+ 'questions': questions,
+ 'form': form
+ }
return my_render_to_response('exam/showquestions.html', context,
context_instance=ci)
else:
for i in data:
question = Question.objects.get(id=i).delete()
questions = Question.objects.all()
+ form = QuestionFilterForm()
context = {'papers': [],
'question': None,
- 'questions': questions}
+ 'questions': questions,
+ 'form': form
+ }
return my_render_to_response('exam/showquestions.html', context,
context_instance=ci)
elif request.method == 'POST' and request.POST.get('edit') == 'edit':
@@ -1312,9 +1343,12 @@ def show_all_questions(request):
context_instance=ci)
else:
questions = Question.objects.all()
+ form = QuestionFilterForm()
context = {'papers': [],
'question': None,
- 'questions': questions}
+ 'questions': questions,
+ 'form': form
+ }
return my_render_to_response('exam/showquestions.html', context,
context_instance=ci)