From a37b9b082ef9c89bd8f06844afad5db691e25995 Mon Sep 17 00:00:00 2001 From: mahesh Date: Fri, 21 Apr 2017 03:12:10 +0530 Subject: added search tag feature in showquestions --- yaksh/templates/yaksh/showquestions.html | 29 +++++++++++++++++++++++++---- yaksh/views.py | 10 ++++++++++ 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 {% endif %}

-{% csrf_token %} +
-
Filters
+

Filters Questions:

{{ form.question_type }}
@@ -40,16 +40,37 @@ Upload File

- -
+ +

+ +{% csrf_token %} +
+
+ Search Questions + + + + + +
+
+{% if not search_result %} {% if questions %}
Select All
{% for i in questions %}   {{ i }}
{% endfor %} {% endif %} +{% else %} +{% for i in search_result %} +  {{ i }}
+{% endfor %} +{% endif %}

   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() -- cgit