diff options
author | mahesh | 2017-04-21 03:12:10 +0530 |
---|---|---|
committer | mahesh | 2017-06-14 12:45:07 +0530 |
commit | a37b9b082ef9c89bd8f06844afad5db691e25995 (patch) | |
tree | 35e651edc10f1f3a3572f088ed67d6cb068b9572 /yaksh | |
parent | ebc8a2af6d4fdf52a9703701a97a3abfaf66ed06 (diff) | |
download | online_test-a37b9b082ef9c89bd8f06844afad5db691e25995.tar.gz online_test-a37b9b082ef9c89bd8f06844afad5db691e25995.tar.bz2 online_test-a37b9b082ef9c89bd8f06844afad5db691e25995.zip |
added search tag feature in showquestions
Diffstat (limited to 'yaksh')
-rw-r--r-- | yaksh/templates/yaksh/showquestions.html | 29 | ||||
-rw-r--r-- | 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 <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 }}"> <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 }}"> <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> 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() |