diff options
Diffstat (limited to 'yaksh/views.py')
-rw-r--r-- | yaksh/views.py | 65 |
1 files changed, 41 insertions, 24 deletions
diff --git a/yaksh/views.py b/yaksh/views.py index 3341aca..9116026 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -1232,16 +1232,15 @@ def ajax_questions_filter(request): question_type = request.POST.get('question_type') marks = request.POST.get('marks') language = request.POST.get('language') - - if question_type != "select": + if question_type: filter_dict['type'] = str(question_type) - if marks != "select": + if marks: filter_dict['points'] = marks - if language != "select": + if language: filter_dict['language'] = str(language) - questions = list(Question.objects.filter(**filter_dict)) + questions = Question.objects.filter(**filter_dict) return my_render_to_response( request, 'yaksh/ajax_question_filter.html', {'questions': questions} @@ -1267,19 +1266,29 @@ def _remove_already_present(questionpaper_id, questions): return questions questionpaper = QuestionPaper.objects.get(pk=questionpaper_id) questions = questions.exclude( - id__in=questionpaper.fixed_questions.values_list('id', flat=True)) + id__in=questionpaper.fixed_questions.values_list('id', flat=True)) for random_set in questionpaper.random_questions.all(): questions = questions.exclude( - id__in=random_set.questions.values_list('id', flat=True)) + id__in=random_set.questions.values_list('id', flat=True)) return questions +def _get_questions_from_tags(question_tags, user): + search_tags = [] + for tags in question_tags: + search_tags.extend(re.split('[; |, |\*|\n]', tags)) + return Question.objects.filter(tags__name__in=search_tags, + user=user).distinct() + + @login_required @email_verified def design_questionpaper(request, quiz_id, questionpaper_id=None, course_id=None): user = request.user - + que_tags = Question.objects.filter( + active=True, user=user).values_list('tags', flat=True).distinct() + all_tags = Tag.objects.filter(id__in=que_tags) if not is_moderator(user): raise Http404('You are not allowed to view this page!') if quiz_id: @@ -1309,18 +1318,24 @@ def design_questionpaper(request, quiz_id, questionpaper_id=None, question_type = request.POST.get('question_type', None) marks = request.POST.get('marks', None) state = request.POST.get('is_active', None) + tags = request.POST.get('question_tags', None) if 'add-fixed' in request.POST: question_ids = request.POST.get('checked_ques', None) - if question_paper.fixed_question_order: - ques_order = question_paper.fixed_question_order.split(",") +\ - question_ids.split(",") - questions_order = ",".join(ques_order) - else: - questions_order = question_ids - questions = Question.objects.filter(id__in=question_ids.split(',')) - question_paper.fixed_question_order = questions_order - question_paper.save() - question_paper.fixed_questions.add(*questions) + if question_ids: + if question_paper.fixed_question_order: + ques_order = ( + question_paper.fixed_question_order.split(",") + + question_ids.split(",") + ) + questions_order = ",".join(ques_order) + else: + questions_order = question_ids + questions = Question.objects.filter( + id__in=question_ids.split(',') + ) + question_paper.fixed_question_order = questions_order + question_paper.save() + question_paper.fixed_questions.add(*questions) if 'remove-fixed' in request.POST: question_ids = request.POST.getlist('added-questions', None) @@ -1356,6 +1371,11 @@ def design_questionpaper(request, quiz_id, questionpaper_id=None, if marks: questions = _get_questions(user, question_type, marks) + elif tags: + que_tags = request.POST.getlist('question_tags', None) + questions = _get_questions_from_tags(que_tags, user) + + if questions: questions = _remove_already_present(questionpaper_id, questions) question_paper.update_total_marks() @@ -1370,7 +1390,8 @@ def design_questionpaper(request, quiz_id, questionpaper_id=None, 'fixed_questions': fixed_questions, 'state': state, 'random_sets': random_sets, - 'course_id': course_id + 'course_id': course_id, + 'all_tags': all_tags } return my_render_to_response( request, 'yaksh/design_questionpaper.html', context @@ -1453,11 +1474,7 @@ def show_all_questions(request): 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() + search_result = _get_questions_from_tags(question_tags, user) context['questions'] = search_result return my_render_to_response(request, 'yaksh/showquestions.html', context) |