diff options
author | adityacp | 2020-09-09 09:34:54 +0530 |
---|---|---|
committer | adityacp | 2020-09-09 09:34:54 +0530 |
commit | 196e5df3930d4c3f18dfd7e33c9821ca2f74a51e (patch) | |
tree | 4039d736e24c75177682d4ce7299057e29f17d4d /yaksh/views.py | |
parent | 2d1b8eb907c7e142d4e3c76e43707fb9f82d6683 (diff) | |
parent | 23bf46ac2e262ceb373388196962a0bec048c6cb (diff) | |
download | online_test-196e5df3930d4c3f18dfd7e33c9821ca2f74a51e.tar.gz online_test-196e5df3930d4c3f18dfd7e33c9821ca2f74a51e.tar.bz2 online_test-196e5df3930d4c3f18dfd7e33c9821ca2f74a51e.zip |
Resolve conflicts
Diffstat (limited to 'yaksh/views.py')
-rw-r--r-- | yaksh/views.py | 172 |
1 files changed, 167 insertions, 5 deletions
diff --git a/yaksh/views.py b/yaksh/views.py index fffefe8..652e08c 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -38,7 +38,11 @@ from yaksh.models import ( StdIOBasedTestCase, StringTestCase, TestCase, User, get_model_class, FIXTURES_DIR_PATH, MOD_GROUP_NAME, Lesson, LessonFile, LearningUnit, LearningModule, CourseStatus, question_types, Post, Comment, +<<<<<<< HEAD Topic, TableOfContents +======= + MicroManager +>>>>>>> 23bf46ac2e262ceb373388196962a0bec048c6cb ) from yaksh.forms import ( UserRegisterForm, UserLoginForm, QuizForm, QuestionForm, @@ -484,6 +488,46 @@ def user_login(request): @login_required @email_verified +def special_start(request, micromanager_id=None): + user = request.user + micromanager = get_object_or_404(MicroManager, pk=micromanager_id, + student=user) + course = micromanager.course + quiz = micromanager.quiz + module = course.get_learning_module(quiz) + quest_paper = get_object_or_404(QuestionPaper, quiz=quiz) + + if not course.is_enrolled(user): + msg = 'You are not enrolled in {0} course'.format(course.name) + return quizlist_user(request, msg=msg) + + if not micromanager.can_student_attempt(): + msg = 'Your special attempts are exhausted for {0}'.format( + quiz.description) + return quizlist_user(request, msg=msg) + + last_attempt = AnswerPaper.objects.get_user_last_attempt( + quest_paper, user, course.id) + + if last_attempt: + if last_attempt.is_attempt_inprogress(): + return show_question( + request, last_attempt.current_question(), last_attempt, + course_id=course.id, module_id=module.id, + previous_question=last_attempt.current_question() + ) + + attempt_num = micromanager.get_attempt_number() + ip = request.META['REMOTE_ADDR'] + new_paper = quest_paper.make_answerpaper(user, ip, attempt_num, course.id, + special=True) + micromanager.increment_attempts_utilised() + return show_question(request, new_paper.current_question(), new_paper, + course_id=course.id, module_id=module.id) + + +@login_required +@email_verified def start(request, questionpaper_id=None, attempt_num=None, course_id=None, module_id=None): """Check the user cedentials and if any quiz is available, @@ -644,7 +688,7 @@ def show_question(request, question, paper, error_message=None, request, msg, paper.attempt_number, paper.question_paper.id, course_id=course_id, module_id=module_id ) - if not quiz.active: + if not quiz.active and not paper.is_special: reason = 'The quiz has been deactivated!' return complete( request, reason, paper.attempt_number, paper.question_paper.id, @@ -822,7 +866,7 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None, previous_question=current_question) else: user_answer = request.POST.get('answer') - if not user_answer: + if not str(user_answer): msg = "Please submit a valid answer." return show_question( request, current_question, paper, notification=msg, @@ -1447,6 +1491,13 @@ def design_questionpaper(request, course_id, quiz_id, questionpaper_id=None): question_paper.save() question_paper.fixed_questions.add(*questions) messages.success(request, "Questions added successfully") + return redirect( + 'yaksh:designquestionpaper', + course_id=course_id, + quiz_id=quiz_id, + questionpaper_id=questionpaper_id + ) + else: messages.warning(request, "Please select atleast one question") @@ -1465,6 +1516,12 @@ def design_questionpaper(request, course_id, quiz_id, questionpaper_id=None): question_paper.save() question_paper.fixed_questions.remove(*question_ids) messages.success(request, "Questions removed successfully") + return redirect( + 'yaksh:designquestionpaper', + course_id=course_id, + quiz_id=quiz_id, + questionpaper_id=questionpaper_id + ) else: messages.warning(request, "Please select atleast one question") @@ -1479,6 +1536,12 @@ def design_questionpaper(request, course_id, quiz_id, questionpaper_id=None): random_set.questions.add(*random_ques) question_paper.random_questions.add(random_set) messages.success(request, "Questions removed successfully") + return redirect( + 'yaksh:designquestionpaper', + course_id=course_id, + quiz_id=quiz_id, + questionpaper_id=questionpaper_id + ) else: messages.warning(request, "Please select atleast one question") @@ -1487,6 +1550,12 @@ def design_questionpaper(request, course_id, quiz_id, questionpaper_id=None): if random_set_ids: question_paper.random_questions.remove(*random_set_ids) messages.success(request, "Questions removed successfully") + return redirect( + 'yaksh:designquestionpaper', + course_id=course_id, + quiz_id=quiz_id, + questionpaper_id=questionpaper_id + ) else: messages.warning(request, "Please select question set") @@ -1503,8 +1572,8 @@ def design_questionpaper(request, course_id, quiz_id, questionpaper_id=None): if questions: questions = _remove_already_present(questionpaper_id, questions) - question_paper.update_total_marks() - question_paper.save() + question_paper.update_total_marks() + question_paper.save() random_sets = question_paper.random_questions.all() fixed_questions = question_paper.get_ordered_questions() context = { @@ -2412,8 +2481,10 @@ def _read_user_csv(request, reader, course): messages.info(request, "{0} -- Missing Values".format(counter)) continue users = User.objects.filter(username=username) + if not users.exists(): + users = User.objects.filter(email=email) if users.exists(): - user = users[0] + user = users.last() if remove.strip().lower() == 'true': _remove_from_course(user, course) messages.info(request, "{0} -- {1} -- User rejected".format( @@ -3433,6 +3504,7 @@ def hide_comment(request, course_id, uuid): @login_required @email_verified +<<<<<<< HEAD def add_marker(request, course_id, lesson_id): user = request.user course = get_object_or_404(Course, pk=course_id) @@ -3498,6 +3570,48 @@ def get_toc_contents(request, course_id, lesson_id): @login_required @email_verified +def allow_special_attempt(request, user_id, course_id, quiz_id): + user = request.user + + if not is_moderator(user): + raise Http404('You are not allowed to view this page') + + course = get_object_or_404(Course, pk=course_id) + if not course.is_creator(user) and not course.is_teacher(user): + raise Http404('This course does not belong to you') + + quiz = get_object_or_404(Quiz, pk=quiz_id) + student = get_object_or_404(User, pk=user_id) + + if not course.is_enrolled(student): + raise Http404('The student is not enrolled for this course') + + micromanager, created = MicroManager.objects.get_or_create( + course=course, student=student, quiz=quiz + ) + micromanager.manager = user + micromanager.save() + + if (not micromanager.is_special_attempt_required() or + micromanager.is_last_attempt_inprogress()): + name = student.get_full_name() + msg = '{} can attempt normally. No special attempt required!'.format( + name) + elif micromanager.can_student_attempt(): + msg = '{} already has a special attempt!'.format( + student.get_full_name()) + else: + micromanager.allow_special_attempt() + msg = 'A special attempt is provided to {}!'.format( + student.get_full_name()) + + messages.info(request, msg) + return my_redirect('/exam/manage/monitor/{0}/{1}/'.format(quiz_id, + course_id)) + + +@login_required +@email_verified def add_topic(request, content_type, course_id, lesson_id, toc_id=None, topic_id=None): user = request.user @@ -3627,6 +3741,26 @@ def add_marker_quiz(request, content_type, course_id, lesson_id, @login_required @email_verified +def revoke_special_attempt(request, micromanager_id): + user = request.user + + if not is_moderator(user): + raise Http404('You are not allowed to view this page') + + micromanager = get_object_or_404(MicroManager, pk=micromanager_id) + course = micromanager.course + if not course.is_creator(user) and not course.is_teacher(user): + raise Http404('This course does not belong to you') + micromanager.revoke_special_attempt() + msg = 'Revoked special attempt for {}'.format( + micromanager.student.get_full_name()) + messages.info(request, msg) + return my_redirect('/exam/manage/monitor/{0}/{1}/'.format( + micromanager.quiz.id, course.id)) + + +@login_required +@email_verified def delete_toc(request, course_id, toc_id): user = request.user course = get_object_or_404(Course, pk=course_id) @@ -3640,3 +3774,31 @@ def delete_toc(request, course_id, toc_id): else: get_object_or_404(Question, id=toc.object_id).delete() return redirect(redirect_url) + + +@login_required +@email_verified +def extend_time(request, paper_id): + user = request.user + + if not is_moderator(user): + raise Http404('You are not allowed to view this page') + + anspaper = get_object_or_404(AnswerPaper, pk=paper_id) + course = anspaper.course + if not course.is_creator(user) and not course.is_teacher(user): + raise Http404('This course does not belong to you') + + if request.method == "POST": + extra_time = request.POST.get('extra_time', None) + if extra_time is None: + msg = 'Please provide time' + else: + anspaper.set_extra_time(extra_time) + msg = 'Extra {0} minutes given to {1}'.format( + extra_time, anspaper.user.get_full_name()) + else: + msg = 'Bad Request' + messages.info(request, msg) + return my_redirect('/exam/manage/monitor/{0}/{1}/'.format( + anspaper.question_paper.quiz.id, course.id)) |