summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--yaksh/templates/yaksh/showquestions.html29
-rw-r--r--yaksh/views.py10
2 files changed, 35 insertions, 4 deletions
diff --git a/yaksh/templates/yaksh/showquestions.html b/yaksh/templates/yaksh/showquestions.html
index a136ddf..6e1ea6e 100644
--- a/yaksh/templates/yaksh/showquestions.html
+++ b/yaksh/templates/yaksh/showquestions.html
@@ -26,9 +26,9 @@ Upload File <span class="glyphicon glyphicon-open"></span></button>
{% endif %}
<br><br>
<form name=frm action="" method="post">
-{% csrf_token %}
+<!-- Filtering Questions -->
<div class="row" id="selectors">
- <h5 style="padding-left: 20px;">Filters</h5>
+ <h4 style="padding-left: 20px;">Filters Questions: </h4>
<div class="col-md-3">
{{ form.question_type }}
</div>
@@ -40,16 +40,37 @@ Upload File <span class="glyphicon glyphicon-open"></span></button>
</div>
</div>
<br>
- <button class="btn btn-primary" type="button" onClick='location.replace("{{URL_ROOT}}");'>Clear Filters</button>
-<br>
+ <button class="btn btn-primary" type="button" onClick='location.replace("{{URL_ROOT}}");'>
+ Clear Filters</button>
+<br><br>
+<!-- Searching Tags -->
+{% csrf_token %}
+ <div class="col-md-16">
+ <div class="input-group">
+ <span class="input-group-addon" id="basic-addon1">Search Questions </span>
+ <input type="text" name="question_tags" class="form-control"
+ placeholder="Search using comma separated Tags">
+ <span class="input-group-btn">
+ <button class="btn btn-default" type="submit">Search</button>
+ <button class="btn btn-default" onclick='location.replace("{{URL_ROOT}}/exam/manage/questions/");'>
+ Cancel</button>
+ </span>
+ </div>
+ </div>
<div id="filtered-questions">
+{% if not search_result %}
{% if questions %}
<h5><input id="checkall" type="checkbox"> Select All </h5>
{% 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 %}
{% endif %}
+{% else %}
+{% for i in search_result %}
+<input type="checkbox" name="question" value="{{ i.id }}">&nbsp;&nbsp;<a href="{{URL_ROOT}}/exam/manage/addquestion/{{ i.id }}">{{ i }}</a><br>
+{% endfor %}
+{% endif %}
</div>
<br>
<button class="btn btn-primary" type="button" onclick='location.replace("{{URL_ROOT}}/exam/manage/addquestion/");'>Add Question <span class="glyphicon glyphicon-plus"></span></button>&nbsp;&nbsp;
diff --git a/yaksh/views.py b/yaksh/views.py
index c10ba6a..4096da3 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -29,6 +29,7 @@ try:
from StringIO import StringIO as string_io
except ImportError:
from io import BytesIO as string_io
+import re
# Local imports.
from yaksh.models import get_model_class, Quiz, Question, QuestionPaper, QuestionSet, Course
from yaksh.models import Profile, Answer, AnswerPaper, User, TestCase, FileUpload,\
@@ -1045,6 +1046,15 @@ def show_all_questions(request):
else:
context["msg"] = "Please select atleast one question to test"
+ if request.POST.get('question_tags'):
+ question_tags = request.POST.getlist("question_tags")
+ all_tags = []
+ for tags in question_tags:
+ all_tags.extend(re.split('[; |, |\*|\n]',tags))
+ search_result = Question.objects.filter(tags__name__in=all_tags)\
+ .distinct()
+ context['search_result'] = search_result
+
questions = Question.objects.filter(user_id=user.id, active=True)
form = QuestionFilterForm(user=user)
upload_form = UploadFileForm()