summaryrefslogtreecommitdiff
path: root/yaksh
diff options
context:
space:
mode:
authorankitjavalkar2016-10-07 16:04:25 +0530
committerankitjavalkar2016-10-13 15:12:33 +0530
commit3d1d4a50524301d03526e4857844d0e6e4536527 (patch)
tree5fe8c99eb9a52451bb0314a22bd8983c6ca2234d /yaksh
parent40c43990ce2b352b85711beef2763aa22763faa9 (diff)
downloadonline_test-3d1d4a50524301d03526e4857844d0e6e4536527.tar.gz
online_test-3d1d4a50524301d03526e4857844d0e6e4536527.tar.bz2
online_test-3d1d4a50524301d03526e4857844d0e6e4536527.zip
Minor fixes: Hide question instead of deletion
Diffstat (limited to 'yaksh')
-rw-r--r--yaksh/models.py5
-rw-r--r--yaksh/views.py80
2 files changed, 82 insertions, 3 deletions
diff --git a/yaksh/models.py b/yaksh/models.py
index 432f25e..60c4349 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -623,8 +623,7 @@ class QuestionPaper(models.Model):
def _get_questions_for_answerpaper(self):
""" Returns fixed and random questions for the answer paper"""
- questions = []
- questions = list(self.fixed_questions.all())
+ questions = list(self.fixed_questions.filter(active=True))
for question_set in self.random_questions.all():
questions += question_set.get_random_questions()
return questions
@@ -993,7 +992,7 @@ class AnswerPaper(models.Model):
return q_a
def get_questions(self):
- return self.questions.all()
+ return self.questions.filter(active=True)
def get_questions_answered(self):
return self.questions_answered.all()
diff --git a/yaksh/views.py b/yaksh/views.py
index d26c5df..1b977f9 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -1085,6 +1085,86 @@ def grade_user(request, quiz_id=None, user_id=None, attempt_number=None):
)
+<<<<<<< HEAD
+=======
+@csrf_exempt
+def ajax_questionpaper(request, query):
+ """
+ During question paper creation, ajax call made to get question details.
+ """
+
+ user = request.user
+ if query == 'marks':
+ question_type = request.POST.get('question_type')
+ questions = Question.objects.filter(type=question_type, user=user, active=True)
+ marks = questions.values_list('points').distinct()
+ return my_render_to_response('yaksh/ajax_marks.html', {'marks': marks})
+ elif query == 'questions':
+ question_type = request.POST['question_type']
+ marks_selected = request.POST['marks']
+ fixed_questions = request.POST.getlist('fixed_list[]')
+ fixed_question_list = ",".join(fixed_questions).split(',')
+ random_questions = request.POST.getlist('random_list[]')
+ random_question_list = ",".join(random_questions).split(',')
+ question_list = fixed_question_list + random_question_list
+ questions = list(Question.objects.filter(type=question_type,
+ points=marks_selected,
+ user=user,
+ active=True)
+ )
+ questions = [question for question in questions \
+ if not str(question.id) in question_list]
+ return my_render_to_response('yaksh/ajax_questions.html',
+ {'questions': questions})
+
+
+@login_required
+def design_questionpaper(request):
+ user = request.user
+ ci = RequestContext(request)
+
+ if not is_moderator(user):
+ raise Http404('You are not allowed to view this page!')
+
+ if request.method == 'POST':
+ fixed_questions = request.POST.getlist('fixed')
+ random_questions = request.POST.getlist('random')
+ random_number = request.POST.getlist('number')
+ is_shuffle = request.POST.get('shuffle_questions', False)
+ if is_shuffle == 'on':
+ is_shuffle = True
+
+ question_paper = QuestionPaper(shuffle_questions=is_shuffle)
+ quiz = Quiz.objects.order_by("-id")[0]
+ tot_marks = 0
+ question_paper.quiz = quiz
+ question_paper.total_marks = tot_marks
+ question_paper.save()
+ if fixed_questions:
+ fixed_questions_ids = ",".join(fixed_questions)
+ fixed_questions_ids_list = fixed_questions_ids.split(',')
+ for question_id in fixed_questions_ids_list:
+ question_paper.fixed_questions.add(question_id)
+ if random_questions:
+ for random_question, num in zip(random_questions, random_number):
+ qid = random_question.split(',')[0]
+ question = Question.objects.get(id=int(qid))
+ marks = question.points
+ question_set = QuestionSet(marks=marks, num_questions=num)
+ question_set.save()
+ for question_id in random_question.split(','):
+ question_set.questions.add(question_id)
+ question_paper.random_questions.add(question_set)
+ question_paper.update_total_marks()
+ question_paper.save()
+ return my_redirect('/exam/manage/courses')
+ else:
+ form = RandomQuestionForm()
+ context = {'form': form, 'questionpaper':True}
+ return my_render_to_response('yaksh/design_questionpaper.html',
+ context, context_instance=ci)
+
+>>>>>>> Minor fixes: Hide question instead of deletion
@login_required
def view_profile(request):
""" view moderators and users profile """