summaryrefslogtreecommitdiff
path: root/yaksh/views.py
diff options
context:
space:
mode:
authoradityacp2017-02-22 15:00:11 +0530
committeradityacp2017-03-10 15:41:07 +0530
commitc2ffb981b81410006a04b43997a2441a99dbff3d (patch)
tree6b2593d06d1bc355de5813ec129cdf937215eefd /yaksh/views.py
parent344b6441017f72225a0d89f41c6cde38f4bbe187 (diff)
downloadonline_test-c2ffb981b81410006a04b43997a2441a99dbff3d.tar.gz
online_test-c2ffb981b81410006a04b43997a2441a99dbff3d.tar.bz2
online_test-c2ffb981b81410006a04b43997a2441a99dbff3d.zip
Remove manytomany relationship for fixed_questions in question paper
Diffstat (limited to 'yaksh/views.py')
-rw-r--r--yaksh/views.py23
1 files changed, 14 insertions, 9 deletions
diff --git a/yaksh/views.py b/yaksh/views.py
index 63653e6..9b6fc4e 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -25,7 +25,8 @@ import six
# Local imports.
from yaksh.models import get_model_class, Quiz, Question, QuestionPaper, QuestionSet, Course
from yaksh.models import Profile, Answer, AnswerPaper, User, TestCase, FileUpload,\
- has_profile, StandardTestCase, McqTestCase, StdIOBasedTestCase, HookTestCase
+ has_profile, StandardTestCase, McqTestCase, StdIOBasedTestCase, HookTestCase,\
+ FixedQuestions
from yaksh.forms import UserRegisterForm, UserLoginForm, QuizForm,\
QuestionForm, RandomQuestionForm,\
QuestionFilterForm, CourseForm, ProfileForm, UploadFileForm,\
@@ -265,7 +266,8 @@ def show_all_questionpapers(request, questionpaper_id=None):
else:
qu_papers = QuestionPaper.objects.get(id=questionpaper_id)
quiz = qu_papers.quiz
- fixed_questions = qu_papers.fixed_questions.all()
+ fixed_ques = FixedQuestions()
+ fixed_questions = fixed_ques.get_fixed_questions(qu_papers)
random_questions = qu_papers.random_questions.all()
context = {'quiz': quiz, 'fixed_questions': fixed_questions,
'random_questions': random_questions}
@@ -805,8 +807,9 @@ def _remove_already_present(questionpaper_id, questions):
if questionpaper_id is None:
return questions
questionpaper = QuestionPaper.objects.get(pk=questionpaper_id)
- questions = questions.exclude(
- id__in=questionpaper.fixed_questions.values_list('id', flat=True))
+ fixed_questions = FixedQuestions.objects.filter(
+ questionpaper=questionpaper).values_list('question_id', flat=True)
+ questions = questions.exclude(id__in=fixed_questions)
for random_set in questionpaper.random_questions.all():
questions = questions.exclude(
id__in=random_set.questions.values_list('id', flat=True))
@@ -824,6 +827,7 @@ def design_questionpaper(request, quiz_id, questionpaper_id=None):
questions = None
marks = None
state = None
+ fixed_que = FixedQuestions()
if questionpaper_id is None:
question_paper = QuestionPaper.objects.get_or_create(quiz_id=quiz_id)[0]
else:
@@ -839,13 +843,14 @@ def design_questionpaper(request, quiz_id, questionpaper_id=None):
state = request.POST.get('is_active', None)
if 'add-fixed' in request.POST:
- question_ids = request.POST.getlist('questions', None)
- for question in Question.objects.filter(id__in=question_ids):
- question_paper.fixed_questions.add(question)
+ question_ids = request.POST.get('checked_ques', None).split(',')
+ for q_id in question_ids:
+ que = Question.objects.get(id=q_id)
+ fixed_que.add_fixed_questions(question_paper, que)
if 'remove-fixed' in request.POST:
question_ids = request.POST.getlist('added-questions', None)
- question_paper.fixed_questions.remove(*question_ids)
+ fixed_que.remove_fixed_questions(question_ids)
if 'add-random' in request.POST:
question_ids = request.POST.getlist('random_questions', None)
@@ -872,7 +877,7 @@ def design_questionpaper(request, quiz_id, questionpaper_id=None):
question_paper.update_total_marks()
question_paper.save()
random_sets = question_paper.random_questions.all()
- fixed_questions = question_paper.fixed_questions.all()
+ fixed_questions = fixed_que.get_fixed_questions(question_paper)
context = {'qpaper_form': qpaper_form, 'filter_form': filter_form, 'qpaper':
question_paper, 'questions': questions, 'fixed_questions': fixed_questions,
'state': state, 'random_sets': random_sets}