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/forms.py | 2 +- yaksh/models.py | 7 ++++--- yaksh/templates/yaksh/add_question.html | 2 +- yaksh/views.py | 12 +++++------- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/yaksh/forms.py b/yaksh/forms.py index bc9b4c0..1931fad 100644 --- a/yaksh/forms.py +++ b/yaksh/forms.py @@ -177,7 +177,7 @@ class QuestionForm(forms.ModelForm): class Meta: model = Question - exclude = ['user'] + exclude = ['user', 'active'] class FileForm(forms.Form): diff --git a/yaksh/models.py b/yaksh/models.py index f098cd2..432f25e 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -271,7 +271,7 @@ class Question(models.Model): return json.dumps(question_data) def dump_questions(self, question_ids, user): - questions = Question.objects.filter(id__in=question_ids, user_id=user.id) + questions = Question.objects.filter(id__in=question_ids, user_id=user.id, active=True) questions_dict = [] zip_file_name = string_io() zip_file = zipfile.ZipFile(zip_file_name, "a") @@ -764,8 +764,9 @@ class AnswerPaperManager(models.Manager): attempt_number) questions = self.get_all_questions(questionpaper_id, attempt_number) all_questions = Question.objects.filter( - id__in=set(questions) - ).order_by('type') + id__in=set(questions), + active=True + ).order_by('type') for question in all_questions: if question.id in questions_answered: question_stats[question] = [questions_answered[question.id], diff --git a/yaksh/templates/yaksh/add_question.html b/yaksh/templates/yaksh/add_question.html index f003256..5a5f1ce 100644 --- a/yaksh/templates/yaksh/add_question.html +++ b/yaksh/templates/yaksh/add_question.html @@ -20,7 +20,7 @@
Summary: | {{ form.summary }}{{ form.summary.errors }} |
Language: | {{form.language}}{{form.language.errors}} - |
Active: | {{ form.active }}{{form.active.errors}} Type: {{ form.type }}{{form.type.errors}} + |
Type: | {{ form.type }}{{form.type.errors}} |
Points: | {{form.points }}{{ form.points.errors }} |
Rendered: | |
Description: | {{ form.description}} {{form.description.errors}} 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/models.py | 5 ++-- yaksh/views.py | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 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 """ -- 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(-) 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 |