From 40c43990ce2b352b85711beef2763aa22763faa9 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Tue, 4 Oct 2016 18:34:00 +0530 Subject: Hide questions instead of deletion --- yaksh/views.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'yaksh/views.py') diff --git a/yaksh/views.py b/yaksh/views.py index 049788a..d26c5df 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -915,12 +915,10 @@ def show_all_questions(request): if request.POST.get('delete') == 'delete': data = request.POST.getlist('question') if data is not None: - questions = Question.objects.filter(id__in=data, user_id=user.id) - files = FileUpload.objects.filter(question_id__in=questions) - if files: - for file in files: - file.remove() - questions.delete() + questions = Question.objects.filter(id__in=data, user_id=user.id, active=True) + for q in questions: + q.active = False + q.save() if request.POST.get('upload') == 'upload': form = UploadFileForm(request.POST, request.FILES) @@ -959,7 +957,7 @@ def show_all_questions(request): else: context["msg"] = "Please select atleast one question to test" - questions = Question.objects.filter(user_id=user.id) + questions = Question.objects.filter(user_id=user.id, active=True) form = QuestionFilterForm(user=user) upload_form = UploadFileForm() context['papers'] = [] -- cgit From 3d1d4a50524301d03526e4857844d0e6e4536527 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Fri, 7 Oct 2016 16:04:25 +0530 Subject: Minor fixes: Hide question instead of deletion --- yaksh/views.py | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) (limited to 'yaksh/views.py') 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 """ -- cgit From d33e97e4081037d92f89c7ae5742f74411b51931 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Thu, 13 Oct 2016 15:11:05 +0530 Subject: Fix variable name in for loop --- yaksh/views.py | 86 ++-------------------------------------------------------- 1 file changed, 3 insertions(+), 83 deletions(-) (limited to 'yaksh/views.py') diff --git a/yaksh/views.py b/yaksh/views.py index 1b977f9..270a47c 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -916,9 +916,9 @@ def show_all_questions(request): data = request.POST.getlist('question') if data is not None: questions = Question.objects.filter(id__in=data, user_id=user.id, active=True) - for q in questions: - q.active = False - q.save() + for question in questions: + question.active = False + question.save() if request.POST.get('upload') == 'upload': form = UploadFileForm(request.POST, request.FILES) @@ -1085,86 +1085,6 @@ 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 """ -- cgit