From f98684da14deb2bbf76088323bc4cf8075026896 Mon Sep 17 00:00:00 2001 From: adityacp Date: Mon, 8 Jan 2018 17:40:40 +0530 Subject: Change in models.py and views.py - Add new model method for course to check last unit and get next module - Change views to allow student to redirect to next module --- yaksh/models.py | 13 +++++++++++++ yaksh/views.py | 29 ++++++++++++++++++++++------- 2 files changed, 35 insertions(+), 7 deletions(-) (limited to 'yaksh') diff --git a/yaksh/models.py b/yaksh/models.py index 1d24bda..208c855 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -668,6 +668,19 @@ class Course(models.Model): module.learning_unit.all().delete() learning_modules.delete() + def is_last_unit(self, module, unit_id): + last_unit = module.get_learning_units().last() + return unit_id == last_unit.id + + def next_module(self, current_module_id): + modules = self.get_learning_modules() + module_ids = list(modules.values_list("id", flat=True)) + current_unit_index = module_ids.index(current_module_id) + next_index = current_unit_index + 1 + if next_index == len(module_ids): + next_index = 0 + return modules.get(id=module_ids[next_index]) + def __str__(self): return self.name diff --git a/yaksh/views.py b/yaksh/views.py index a4d9e78..99f81b8 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -503,7 +503,7 @@ def start(request, questionpaper_id=None, attempt_num=None, course_id=None, if learning_unit.has_prerequisite(): if not learning_unit.is_prerequisite_passed( user, learning_module, course): - msg = "You have not completed the prerequisite" + msg = "You have not completed the previous Lesson/Quiz/Exercise" if is_moderator(user): return prof_manage(request, msg=msg) return view_module(request, module_id=module_id, @@ -607,6 +607,7 @@ def show_question(request, question, paper, error_message=None, notification=Non files = FileUpload.objects.filter(question_id=question.id, hide=False) course = Course.objects.get(id=course_id) module = course.learning_module.get(id=module_id) + all_modules = course.get_learning_modules() context = { 'question': question, 'paper': paper, @@ -620,7 +621,8 @@ def show_question(request, question, paper, error_message=None, notification=Non 'module': module, 'can_skip': can_skip, 'delay_time': delay_time, - 'quiz_type': quiz_type + 'quiz_type': quiz_type, + 'all_modules': all_modules } answers = paper.get_previous_answers(question) if answers: @@ -2329,12 +2331,13 @@ 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() + all_modules = course.get_learning_modules() if learn_unit.has_prerequisite(): if not learn_unit.is_prerequisite_passed(user, learn_module, course): - msg = "You have not completed the prerequisite" + 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, - 'course': course, 'state': "lesson", + 'course': course, 'state': "lesson", "all_modules": all_modules, 'learning_units': learning_units, "current_unit": learn_unit, 'learning_module': learn_module} return my_render_to_response('yaksh/show_video.html', context) @@ -2516,13 +2519,14 @@ def get_next_unit(request, course_id, module_id, current_unit_id, current_learning_unit = learning_module.learning_unit.get( id=current_unit_id) - course_status = CourseStatus.objects.filter( - user=user, course_id=course_id, - ) if first_unit: next_unit = current_learning_unit else: next_unit = learning_module.get_next_unit(current_learning_unit.id) + + 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 @@ -2534,6 +2538,14 @@ def get_next_unit(request, course_id, module_id, current_unit_id, if not first_unit: course_status.completed_units.add(current_learning_unit.id) + # if last unit of current module go to next module + is_last_unit = course.is_last_unit(learning_module, + current_learning_unit.id) + if is_last_unit: + next_module = course.next_module(learning_module.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() @@ -2619,14 +2631,17 @@ def view_module(request, module_id, course_id, msg=None): msg = "{0} is either expired or not active".format(course.name) return course_modules(request, course_id, msg) learning_module = course.learning_module.get(id=module_id) + 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" 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['all_modules'] = all_modules context['user'] = user context['course'] = course context['state'] = "module" -- cgit From 08a4c0271535bfb24a82a07d6e881cd2b9bab470 Mon Sep 17 00:00:00 2001 From: adityacp Date: Mon, 8 Jan 2018 17:43:56 +0530 Subject: Change in css and templates - Allow horizontal scroll for sidebar in dashboard.css - Change templates to display all modules - Change error messages in course template --- yaksh/static/yaksh/css/dashboard.css | 2 +- yaksh/templates/yaksh/complete.html | 4 +- yaksh/templates/yaksh/courses.html | 14 ++--- yaksh/templates/yaksh/question.html | 67 +++++++++++---------- yaksh/templates/yaksh/show_video.html | 109 ++++++++++++++++++++++++---------- 5 files changed, 124 insertions(+), 72 deletions(-) (limited to 'yaksh') diff --git a/yaksh/static/yaksh/css/dashboard.css b/yaksh/static/yaksh/css/dashboard.css index 20a0339..b5b3648 100644 --- a/yaksh/static/yaksh/css/dashboard.css +++ b/yaksh/static/yaksh/css/dashboard.css @@ -38,7 +38,7 @@ body { z-index: 1000; display: block; padding: 20px; - overflow-x: hidden; + overflow-x: auto; overflow-y: auto; /* Scrollable contents if viewport is shorter than content. */ background-color: #f5f5f5; border-right: 1px solid #eee; diff --git a/yaksh/templates/yaksh/complete.html b/yaksh/templates/yaksh/complete.html index d0b7e4d..e4317fe 100644 --- a/yaksh/templates/yaksh/complete.html +++ b/yaksh/templates/yaksh/complete.html @@ -39,12 +39,12 @@ width="80" alt="YAKSH">{% endblock %} Home {% if module_id and not user == "moderator" %} {% if first_unit %} - Next Unit + Next {% else %} - Next Unit + Next diff --git a/yaksh/templates/yaksh/courses.html b/yaksh/templates/yaksh/courses.html index b6b9f7e..a1fd48a 100644 --- a/yaksh/templates/yaksh/courses.html +++ b/yaksh/templates/yaksh/courses.html @@ -75,7 +75,7 @@ Closed {% endif %}

-
Teacher(s) Added to {{ course }}
+
Teacher(s) added to {{ course }}

{% if course.get_teachers %} @@ -93,7 +93,7 @@ {% else %} -
No Teacher(s) Added
+
No Teacher(s) added
{% endif %}


@@ -209,7 +209,7 @@
Course Creator

{{course.creator.get_full_name.title}}


-
Teacher(s) Added to {{ course }}
+
Teacher(s) added to {{ course }}

{% if course.get_teachers %} @@ -228,7 +228,7 @@ {% else %} -
No Teacher(s) Added
+
No Teacher(s) added
{% endif %}


@@ -326,7 +326,7 @@ Add New Quiz Add New Exercise {% if not quizzes %} -

No new Quiz Added

+

No new Quiz added



{% else %}

Quizzes

@@ -380,7 +380,7 @@ {% if type == "lesson" %} Add new Lesson {% if not lessons %} -

No new Lessons Added

+

No new Lessons added



{% else %}

Lessons

@@ -414,7 +414,7 @@ Add new Module {% if not learning_modules %} -

No new learning modules Added

+

No new learning modules added



{% else %}

Learning Modules

diff --git a/yaksh/templates/yaksh/question.html b/yaksh/templates/yaksh/question.html index b7251ad..96c8e6e 100644 --- a/yaksh/templates/yaksh/question.html +++ b/yaksh/templates/yaksh/question.html @@ -110,37 +110,44 @@ question_type = "{{ question.type }}" {% block onload %} onload="updateTime();" {% endblock %} {% block learning_units %} -

Lessons/Quizzes

- + {% endfor %} {% endblock %} {% block main %} diff --git a/yaksh/templates/yaksh/show_video.html b/yaksh/templates/yaksh/show_video.html index 0490697..f4b59ac 100644 --- a/yaksh/templates/yaksh/show_video.html +++ b/yaksh/templates/yaksh/show_video.html @@ -1,42 +1,54 @@ {% extends "user.html" %} {% load custom_filters %} -{% block title %} {{ learning_module.name|title }} {% endblock %} +{% block title %} {{ learning_module.name }} {% endblock %} -{% block pagetitle %} {{ learning_module.name|title }} {% endblock %} +{% block pagetitle %} {{ learning_module.name }} +{% if state == "lesson" %} + : {{lesson.name}} +{% endif %} +{% endblock %} {% block main %} {% if msg %}
@@ -49,16 +61,49 @@
{{learning_module.html_data|safe}} + {% if learning_module.html_data%} +
+ {% endif %} +

Following are the units in this modules

+ + + + + + {% for unit in learning_module.get_learning_units %} + +
    +
+ + + + {% endfor %} +
Unit NameUnit Type
+ {% if unit.type == "quiz" %} + {{unit.quiz.description}} + {% else %} + {{unit.lesson.name}} + {% endif %} + + {% if unit.type == "quiz" %} + {% if unit.quiz.is_exercise %} + Exercise + {% else %} + Quiz + {% endif %} + {% else %} + Lesson + {% endif %} +
- First Unit + Start
{% else %} -

{{lesson.name}}

{{lesson.html_data|safe}} @@ -80,7 +125,7 @@
{% endif %}
- Next Unit + Next -- cgit