diff options
author | adityacp | 2018-01-16 16:23:42 +0530 |
---|---|---|
committer | adityacp | 2018-01-16 16:23:42 +0530 |
commit | 67d4f84d3274ffce449073d1209f29943cfccf06 (patch) | |
tree | b764c59efbcc7a54095dcbd2dbdd1656446d8b94 /yaksh | |
parent | 1445358b4ee548edd16a8d42026b080b7d92a0c4 (diff) | |
download | online_test-67d4f84d3274ffce449073d1209f29943cfccf06.tar.gz online_test-67d4f84d3274ffce449073d1209f29943cfccf06.tar.bz2 online_test-67d4f84d3274ffce449073d1209f29943cfccf06.zip |
Change template, urls.py, views.py
- Change show_video.html to empty module
- Add condition to check if module is completed for the corresponding unit
Diffstat (limited to 'yaksh')
-rw-r--r-- | yaksh/templates/yaksh/show_video.html | 19 | ||||
-rw-r--r-- | yaksh/urls.py | 2 | ||||
-rw-r--r-- | yaksh/views.py | 54 |
3 files changed, 63 insertions, 12 deletions
diff --git a/yaksh/templates/yaksh/show_video.html b/yaksh/templates/yaksh/show_video.html index f4b59ac..17f9d86 100644 --- a/yaksh/templates/yaksh/show_video.html +++ b/yaksh/templates/yaksh/show_video.html @@ -64,6 +64,7 @@ {% if learning_module.html_data%} <hr> {% endif %} + {% if learning_module.get_learning_units %} <center><h4>Following are the units in this modules</h4></center> <table class="table"> <tr> @@ -95,13 +96,23 @@ </tr> {% endfor %} </table> + {% else %} + <center><h3>No Lessons/Quizzes Found</h3></center> + {% endif %} </div> </div> <div style="text-align: center;"> - <a href="{{ URL_ROOT }}/exam/next_unit/{{course.id}}/{{learning_module.id}}/{{first_unit.id}}/1" class="btn btn-info">Start - <span class="glyphicon glyphicon-chevron-right"> - </span> - </a> + {% if first_unit %} + <a href="{{ URL_ROOT }}/exam/next_unit/{{course.id}}/{{learning_module.id}}/{{first_unit.id}}/1" class="btn btn-info">Start + <span class="glyphicon glyphicon-chevron-right"> + </span> + </a> + {% else %} + <a href="{{ URL_ROOT }}/exam/next_unit/{{course.id}}/{{learning_module.id}}" class="btn btn-info">Next + <span class="glyphicon glyphicon-chevron-right"> + </span> + </a> + {% endif %} </div> {% else %} <div class="panel panel-default" style="border: none; box-shadow: none;"> diff --git a/yaksh/urls.py b/yaksh/urls.py index d60a5d3..7eca5af 100644 --- a/yaksh/urls.py +++ b/yaksh/urls.py @@ -40,6 +40,8 @@ urlpatterns = [ views.view_module, name='view_module'), url(r'^next_unit/(?P<course_id>\d+)/(?P<module_id>\d+)/(?P<current_unit_id>\d+)/$', views.get_next_unit, name='next_unit'), + url(r'^next_unit/(?P<course_id>\d+)/(?P<module_id>\d+)/$', + views.get_next_unit, name='next_unit'), url(r'^next_unit/(?P<course_id>\d+)/(?P<module_id>\d+)/(?P<current_unit_id>\d+)/(?P<first_unit>\d+)/$', views.get_next_unit, name='next_unit'), url(r'^course_modules/(?P<course_id>\d+)/$', diff --git a/yaksh/views.py b/yaksh/views.py index 7049912..3b7d28d 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -477,6 +477,16 @@ def start(request, questionpaper_id=None, attempt_num=None, course_id=None, learning_module = course.learning_module.get(id=module_id) learning_unit = learning_module.learning_unit.get(quiz=quest_paper.quiz.id) + # unit module prerequiste check + if learning_module.has_prerequisite(): + if not learning_module.is_prerequisite_passed(user, course): + msg = "You have not completed the module previous to {0}".format( + learning_module.name) + return course_modules(request, course_id, msg) + + # update course status with current unit + _update_unit_status(course_id, user, learning_unit) + # is user enrolled in the course if not course.is_enrolled(user): msg = 'You are not enrolled in {0} course'.format(course.name) @@ -2332,6 +2342,15 @@ def show_lesson(request, lesson_id, module_id, course_id): learn_module = course.learning_module.get(id=module_id) learn_unit = learn_module.learning_unit.get(lesson_id=lesson_id) learning_units = learn_module.get_learning_units() + if learn_module.has_prerequisite(): + if not learn_module.is_prerequisite_passed(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) + + # 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): @@ -2508,7 +2527,7 @@ def preview_html_text(request): @login_required @email_verified -def get_next_unit(request, course_id, module_id, current_unit_id, +def get_next_unit(request, course_id, module_id, current_unit_id=None, first_unit=None): user = request.user course = Course.objects.prefetch_related("learning_module").get( @@ -2517,8 +2536,14 @@ def get_next_unit(request, course_id, module_id, current_unit_id, raise Http404('You are not enrolled for this course!') learning_module = course.learning_module.prefetch_related( "learning_unit").get(id=module_id) - current_learning_unit = learning_module.learning_unit.get( - id=current_unit_id) + + if current_unit_id: + current_learning_unit = learning_module.learning_unit.get( + id=current_unit_id) + else: + next_module = course.next_module(learning_module.id) + return my_redirect("/exam/quizzes/view_module/{0}/{1}".format( + next_module.id, course_id)) if first_unit: next_unit = current_learning_unit @@ -2547,9 +2572,6 @@ def get_next_unit(request, course_id, module_id, current_unit_id, return my_redirect("/exam/quizzes/view_module/{0}/{1}/".format( next_module.id, course.id)) - # make next available unit as current unit - course_status.current_unit = next_unit - course_status.save() if next_unit.type == "quiz": return my_redirect("/exam/start/{0}/{1}/{2}".format( next_unit.quiz.questionpaper_set.get().id, module_id, course_id)) @@ -2635,13 +2657,14 @@ def view_module(request, module_id, course_id, msg=None): all_modules = course.get_learning_modules() if learning_module.has_prerequisite(): if not learning_module.is_prerequisite_passed(user, course): - msg = "You have not completed the previous learning module" + msg = "You have not completed 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 - context['first_unit'] = learning_units[0] + context['first_unit'] = learning_units.first() context['all_modules'] = all_modules context['user'] = user context['course'] = course @@ -2683,3 +2706,18 @@ def course_status(request, course_id): 'state': 'course_status', 'modules': course.get_learning_modules() } return my_render_to_response('yaksh/course_detail.html', context) + + +def _update_unit_status(course_id, user, unit): + course_status = CourseStatus.objects.filter( + user=user, course_id=course_id, + ) + if not course_status.exists(): + course_status = CourseStatus.objects.create( + user=user, course_id=course_id + ) + else: + course_status = course_status.first() + # make next available unit as current unit + course_status.current_unit = unit + course_status.save() |