diff options
author | Prabhu Ramachandran | 2017-09-01 17:17:58 +0530 |
---|---|---|
committer | GitHub | 2017-09-01 17:17:58 +0530 |
commit | acb0cf85839eb090041a2606dddc3b1e29e25d16 (patch) | |
tree | 3dbbf48a20574c68c62c5a26c268c933d5e27188 | |
parent | a9cc03b372071962a009737416b281738b82572f (diff) | |
parent | e8eca566edde7b330a92af91541cee5d348a0326 (diff) | |
download | online_test-acb0cf85839eb090041a2606dddc3b1e29e25d16.tar.gz online_test-acb0cf85839eb090041a2606dddc3b1e29e25d16.tar.bz2 online_test-acb0cf85839eb090041a2606dddc3b1e29e25d16.zip |
Merge pull request #302 from maheshgudi/add_tag_search
Search questions using tag
-rw-r--r-- | yaksh/static/yaksh/js/show_question.js | 12 | ||||
-rw-r--r-- | yaksh/templates/yaksh/showquestions.html | 53 | ||||
-rw-r--r-- | yaksh/views.py | 30 |
3 files changed, 76 insertions, 19 deletions
diff --git a/yaksh/static/yaksh/js/show_question.js b/yaksh/static/yaksh/js/show_question.js index e7cd817..e6825a0 100644 --- a/yaksh/static/yaksh/js/show_question.js +++ b/yaksh/static/yaksh/js/show_question.js @@ -37,7 +37,17 @@ function confirm_edit(frm) else return true; } + +function append_tag(tag){ + var tag_name = document.getElementById("question_tags"); + if (tag_name.value != null){ + tag_name.value = tag.value+", "+tag_name.value; + } + else{ + tag_name.value = tag.value; + } +} $(document).ready(function() { $("#questions-table").tablesorter({sortList: [[0,0], [4,0]]}); - });
\ No newline at end of file + }); diff --git a/yaksh/templates/yaksh/showquestions.html b/yaksh/templates/yaksh/showquestions.html index 78be301..a8983bd 100644 --- a/yaksh/templates/yaksh/showquestions.html +++ b/yaksh/templates/yaksh/showquestions.html @@ -58,8 +58,11 @@ Upload File <span class="glyphicon glyphicon-open"/></button> {{ msg }} </div> {% endif %} +<br><br> +<form name=frm action="" method="post"> +<!-- 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> @@ -69,10 +72,40 @@ Upload File <span class="glyphicon glyphicon-open"/></button> <div class="col-md-3"> {{ form.marks }} </div> -</div> -<br> - <button class="btn btn-primary" type="button" onClick='location.replace("{{URL_ROOT}}");'>Clear Filters</button> <br> +<h4 style="padding-left: 20px;">Or</h4> + +<h4 style="padding-left: 20px;">Search using Tags: </h4> +</div> +<!-- Searching Tags --> +{% csrf_token %} + <div class="col-md-14"> + <div class="input-group"> + <span class="input-group-addon" id="basic-addon1">Search Questions </span> + <input type="text" id="question_tags" 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> + </span> + <div class="col-md-6"> + <select class="form-control" id="sel1" onchange="append_tag(this);"> + {% if all_tags %} + <option value="" disabled selected>Available Tags</option> + {% for tag in all_tags %} + <option> + {{tag}} + </option> + {% endfor %} + {% else %} + <option value="" disabled selected>No Available Tags</option> + {% endif %} + </select> + </div> + </div> + </div> +<br><br> +<button class="btn btn-primary" type="button" onClick='location.replace("{{URL_ROOT}}");'> + Clear Filters</button> <div id="filtered-questions"> {% if questions %} @@ -90,15 +123,15 @@ Upload File <span class="glyphicon glyphicon-open"/></button> </thead> <tbody> -{% for i in questions %} +{% for question in questions %} <tr> <td> -<input type="checkbox" name="question" value="{{ i.id }}"> +<input type="checkbox" name="question" value="{{ question.id }}"> </td> -<td><a href="{{URL_ROOT}}/exam/manage/addquestion/{{ i.id }}">{{i.summary|capfirst}}</a></td> -<td>{{i.language|capfirst}}</td> -<td>{{i.type|capfirst}}</td> -<td>{{i.points}}</td> +<td><a href="{{URL_ROOT}}/exam/manage/addquestion/{{ question.id }}">{{question.summary|capfirst}}</a></td> +<td>{{question.language|capfirst}}</td> +<td>{{question.type|capfirst}}</td> +<td>{{question.points}}</td> </tr> {% endfor %} </tbody> diff --git a/yaksh/views.py b/yaksh/views.py index 3c7df4d..0c45d66 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,\ @@ -1032,6 +1033,18 @@ def show_all_questions(request): if not is_moderator(user): raise Http404("You are not allowed to view this page !") + questions = Question.objects.filter(user_id=user.id, active=True) + form = QuestionFilterForm(user=user) + user_tags = questions.values_list('tags', flat=True).distinct() + all_tags = Tag.objects.filter(id__in = user_tags) + upload_form = UploadFileForm() + context['questions'] = questions + context['all_tags'] = all_tags + context['papers'] = [] + context['question'] = None + context['form'] = form + context['upload_form'] = upload_form + if request.method == 'POST': if request.POST.get('delete') == 'delete': data = request.POST.getlist('question') @@ -1080,14 +1093,15 @@ def show_all_questions(request): else: context["msg"] = "Please select atleast one question to test" - questions = Question.objects.filter(user_id=user.id, active=True) - form = QuestionFilterForm(user=user) - upload_form = UploadFileForm() - context['papers'] = [] - context['question'] = None - context['questions'] = questions - context['form'] = form - context['upload_form'] = upload_form + if request.POST.get('question_tags'): + question_tags = request.POST.getlist("question_tags") + search_tags = [] + for tags in question_tags: + search_tags.extend(re.split('[; |, |\*|\n]',tags)) + search_result = Question.objects.filter(tags__name__in=search_tags, + user=user).distinct() + context['questions'] = search_result + return my_render_to_response('yaksh/showquestions.html', context, context_instance=ci) |