diff options
Diffstat (limited to 'yaksh/views.py')
-rw-r--r-- | yaksh/views.py | 117 |
1 files changed, 81 insertions, 36 deletions
diff --git a/yaksh/views.py b/yaksh/views.py index 6c7a12e..7202826 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -156,6 +156,7 @@ def user_logout(request): def quizlist_user(request, enrolled=None, msg=None): """Show All Quizzes that is available to logged-in user.""" user = request.user + courses_data = [] if request.method == "POST": course_code = request.POST.get('course_code') @@ -164,18 +165,30 @@ def quizlist_user(request, enrolled=None, msg=None): title = 'Search' elif enrolled is not None: - courses = user.students.all() + courses = user.students.all().order_by('-id') title = 'Enrolled Courses' else: courses = Course.objects.filter( active=True, is_trial=False ).exclude( ~Q(requests=user), ~Q(rejected=user), hidden=True - ) + ).order_by('-id') title = 'All Courses' + for course in courses: + if user in course.students.all(): + _percent = course.get_completion_percent(user) + else: + _percent = None + courses_data.append( + { + 'data': course, + 'completion_percentage': _percent, + } + ) + context = { - 'user': user, 'courses': courses, + 'user': user, 'courses': courses_data, 'title': title, 'msg': msg } @@ -471,11 +484,19 @@ def start(request, questionpaper_id=None, attempt_num=None, course_id=None, # unit module prerequiste check if learning_module.has_prerequisite(): - if not learning_module.is_prerequisite_passed(user, course): + if not learning_module.is_prerequisite_complete(user, course): msg = "You have not completed the module previous to {0}".format( learning_module.name) return course_modules(request, course_id, msg) + if learning_module.check_prerequisite_passes: + if not learning_module.is_prerequisite_passed(user, course): + msg = ( + "You have not successfully passed the module" + " previous to {0}".format(learning_module.name) + ) + return course_modules(request, course_id, msg) + # is user enrolled in the course if not course.is_enrolled(user): msg = 'You are not enrolled in {0} course'.format(course.name) @@ -501,7 +522,7 @@ def start(request, questionpaper_id=None, attempt_num=None, course_id=None, # prerequisite check and passing criteria for quiz if learning_unit.has_prerequisite(): - if not learning_unit.is_prerequisite_passed( + if not learning_unit.is_prerequisite_complete( user, learning_module, course): msg = "You have not completed the previous Lesson/Quiz/Exercise" if is_moderator(user): @@ -515,23 +536,28 @@ def start(request, questionpaper_id=None, attempt_num=None, course_id=None, # if any previous attempt last_attempt = AnswerPaper.objects.get_user_last_attempt( quest_paper, user, course_id) - if last_attempt and 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() - ) + + 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_number = last_attempt.attempt_number + 1 + else: + attempt_number = 1 + # allowed to start if not quest_paper.can_attempt_now(user, course_id)[0]: msg = quest_paper.can_attempt_now(user, course_id)[1] if is_moderator(user): return prof_manage(request, msg=msg) - return view_module(request, module_id=module_id, course_id=course_id, - msg=msg) - if not last_attempt: - attempt_number = 1 - else: - attempt_number = last_attempt.attempt_number + 1 + return complete( + request, msg, last_attempt.attempt_number, quest_paper.id, + course_id=course_id, module_id=module_id + ) + if attempt_num is None and not quest_paper.quiz.is_exercise: context = { 'user': user, @@ -2198,18 +2224,15 @@ def _read_user_csv(reader, course): if users.exists(): user = users[0] if remove.strip().lower() == 'true': - if _remove_from_course(user, course): - upload_details.append("{0} -- {1} -- User rejected".format( - counter, user.username)) - continue + _remove_from_course(user, course) + upload_details.append("{0} -- {1} -- User rejected".format( + counter, user.username)) else: - if _add_to_course(user, course): - upload_details.append("{0} -- {1} -- User rejected".format( - counter, user.username)) - if user not in course.get_enrolled(): - upload_details.append("{0} -- {1} not added to course".format( - counter, user)) - continue + _add_to_course(user, course) + upload_details.append( + "{0} -- {1} -- User Added Successfully".format( + counter, user.username)) + continue user_defaults = {'email': email, 'first_name': first_name, 'last_name': last_name} user, created = _create_or_update_user(username, password, @@ -2259,13 +2282,15 @@ def _get_csv_values(row, fields): def _remove_from_course(user, course): if user in course.get_enrolled(): course.reject(True, user) - return True + else: + course.rejected.add(user) def _add_to_course(user, course): if user in course.get_rejected(): course.enroll(True, user) - return True + else: + course.students.add(user) def _create_or_update_user(username, password, defaults): @@ -2424,17 +2449,24 @@ def show_lesson(request, lesson_id, module_id, course_id): msg = "{0} is not active".format(learn_unit.lesson.name) return view_module(request, module_id, course_id, msg) if learn_module.has_prerequisite(): - if not learn_module.is_prerequisite_passed(user, course): + if not learn_module.is_prerequisite_complete(user, course): msg = "You have not completed the module previous to {0}".format( learn_module.name) return view_module(request, module_id, course_id, msg) + if learn_module.check_prerequisite_passes: + if not learn_module.is_prerequisite_passed(user, course): + msg = ( + "You have not successfully passed the module" + " previous to {0}".format(learn_module.name) + ) + return view_module(request, module_id, course_id, msg) # update course status with current unit _update_unit_status(course_id, user, learn_unit) all_modules = course.get_learning_modules() if learn_unit.has_prerequisite(): - if not learn_unit.is_prerequisite_passed(user, learn_module, course): + if not learn_unit.is_prerequisite_complete(user, learn_module, course): msg = "You have not completed previous Lesson/Quiz/Exercise" return view_module(request, learn_module.id, course_id, msg=msg) context = {'lesson': learn_unit.lesson, 'user': user, @@ -2696,13 +2728,20 @@ def design_course(request, course_id): if remove_values: course.learning_module.remove(*remove_values) - if "Change_prerequisite" in request.POST: + if "change_prerequisite_completion" in request.POST: unit_list = request.POST.getlist("check_prereq") for unit in unit_list: learning_module = course.learning_module.get(id=unit) learning_module.toggle_check_prerequisite() learning_module.save() + if "change_prerequisite_passing" in request.POST: + unit_list = request.POST.getlist("check_prereq_passes") + for unit in unit_list: + learning_module = course.learning_module.get(id=unit) + learning_module.toggle_check_prerequisite_passes() + learning_module.save() + added_learning_modules = course.get_learning_modules() all_learning_modules = LearningModule.objects.filter( creator=user, is_trial=False) @@ -2734,11 +2773,19 @@ def view_module(request, module_id, course_id, msg=None): return course_modules(request, course_id, msg) all_modules = course.get_learning_modules() if learning_module.has_prerequisite(): - if not learning_module.is_prerequisite_passed(user, course): + if not learning_module.is_prerequisite_complete(user, course): msg = "You have not completed the module previous to {0}".format( learning_module.name) return course_modules(request, course_id, msg) + if learning_module.check_prerequisite_passes: + if not learning_module.is_prerequisite_passed(user, course): + msg = ( + "You have not successfully passed the module" + " previous to {0}".format(learning_module.name) + ) + return course_modules(request, course_id, msg) + learning_units = learning_module.get_learning_units() context['learning_units'] = learning_units context['learning_module'] = learning_module @@ -2825,8 +2872,6 @@ def preview_questionpaper(request, questionpaper_id): if not is_moderator(user): raise Http404('You are not allowed to view this page!') paper = QuestionPaper.objects.get(id=questionpaper_id) - if not paper.quiz.creator == user: - raise Http404('This questionpaper does not belong to you') context = { 'questions': paper._get_questions_for_answerpaper(), 'paper': paper, |