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 /yaksh/views.py | |
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
Diffstat (limited to 'yaksh/views.py')
-rw-r--r-- | yaksh/views.py | 30 |
1 files changed, 22 insertions, 8 deletions
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) |