summaryrefslogtreecommitdiff
path: root/testapp/exam
diff options
context:
space:
mode:
authorankitjavalkar2015-07-21 18:02:56 +0530
committerankitjavalkar2015-08-05 12:00:54 +0530
commit214d8696fafee4e38c6bf039315aac37e4cd2e2b (patch)
treef7bc823ab005a9791f020c0eeb7a0a1f828b28fe /testapp/exam
parent0225aad1492600ed53504b0986fd13da24c28ae9 (diff)
downloadonline_test-214d8696fafee4e38c6bf039315aac37e4cd2e2b.tar.gz
online_test-214d8696fafee4e38c6bf039315aac37e4cd2e2b.tar.bz2
online_test-214d8696fafee4e38c6bf039315aac37e4cd2e2b.zip
Add filters to question display
Diffstat (limited to 'testapp/exam')
-rw-r--r--testapp/exam/forms.py13
-rw-r--r--testapp/exam/static/exam/js/question_filter.js69
-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, 160 insertions, 4 deletions
diff --git a/testapp/exam/forms.py b/testapp/exam/forms.py
index b7625be..1c61816 100644
--- a/testapp/exam/forms.py
+++ b/testapp/exam/forms.py
@@ -240,5 +240,18 @@ class RandomQuestionForm(forms.Form):
(choices=(('select', 'Select Marks'),)))
shuffle_questions = forms.BooleanField(required=False)
+
+class QuestionFilterForm(forms.Form):
+ questions = Question.objects.all()
+ points_list = questions.values_list('points', flat=True).distinct()
+ points_options = [(i, i) for i in points_list]
+
+ language = forms.CharField(max_length=8, widget=forms.Select\
+ (choices=languages))
+ question_type = forms.CharField(max_length=8, widget=forms.Select\
+ (choices=question_types))
+ marks = forms.FloatField(widget=forms.Select(choices=points_options))
+
+
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..7dc92a6
--- /dev/null
+++ b/testapp/exam/static/exam/js/question_filter.js
@@ -0,0 +1,69 @@
+$(document).ready(function(){
+ $question_type = $("#id_question_type");
+ $marks = $("#id_marks");
+ $language = $("#id_language");
+
+ $question_type.change(function() {
+ $.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);
+ }
+ });
+ });
+
+ $language.change(function() {
+ $.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);
+ }
+ });
+ });
+
+ $marks.change(function() {
+ $.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);
+ }
+ });
+ });
+
+ $("#checkall").live("click", function(){
+ if($(this).attr("checked")) {
+ $("#filtered-questions input:checkbox").each(function(index, element) {
+ $(this).attr('checked','checked');
+ });
+ }
+ else {
+ $("#filtered_questions input:checkbox").each(function(index, element) {
+ $(this).removeAttr('checked');
+ });
+ }
+ });
+}); \ 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..e1c9dc5 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 != "":
+ 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)