diff options
author | adityacp | 2018-02-08 11:43:25 +0530 |
---|---|---|
committer | adityacp | 2018-02-08 11:43:25 +0530 |
commit | 440c18f4e0565e0824d432b01bc2be7b8847e122 (patch) | |
tree | 04c8ddf34d72cc54803f4f82bc1a1143ef68c9cc /yaksh | |
parent | b78b5d0b46114caefca35e82c502d1f7598e8e59 (diff) | |
download | online_test-440c18f4e0565e0824d432b01bc2be7b8847e122.tar.gz online_test-440c18f4e0565e0824d432b01bc2be7b8847e122.tar.bz2 online_test-440c18f4e0565e0824d432b01bc2be7b8847e122.zip |
Change in forms.py, views.py and models.py
- Add new attribute active in lesson and learningmodule model
- Change learningmodule get_status method
- Add condition in lesson, quiz and module views to check if module is active or not
Diffstat (limited to 'yaksh')
-rw-r--r-- | yaksh/forms.py | 2 | ||||
-rw-r--r-- | yaksh/models.py | 15 | ||||
-rw-r--r-- | yaksh/views.py | 20 |
3 files changed, 30 insertions, 7 deletions
diff --git a/yaksh/forms.py b/yaksh/forms.py index 9fd2eaa..258a1ee 100644 --- a/yaksh/forms.py +++ b/yaksh/forms.py @@ -339,4 +339,4 @@ class LearningModuleForm(forms.ModelForm): class Meta: model = LearningModule - fields = ['name', 'description'] + fields = ['name', 'description', 'active'] diff --git a/yaksh/models.py b/yaksh/models.py index 1e45851..17ba624 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -155,6 +155,9 @@ class Lesson(models.Model): # Creator of the lesson creator = models.ForeignKey(User) + # Activate/Deactivate Lesson + active = models.BooleanField(default=True) + def __str__(self): return "{0}".format(self.name) @@ -414,6 +417,7 @@ class LearningModule(models.Model): creator = models.ForeignKey(User, related_name="module_creator") check_prerequisite = models.BooleanField(default=True) html_data = models.TextField(null=True, blank=True) + active = models.BooleanField(default=True) is_trial = models.BooleanField(default=False) def get_quiz_units(self): @@ -447,21 +451,22 @@ class LearningModule(models.Model): return ordered_units.get(id=ordered_units_ids[next_index]) def get_status(self, user, course): - """ Get module status if it completed, inprogress or not attempted""" + """ Get module status if completed, inprogress or not attempted""" learning_module = course.learning_module.prefetch_related( "learning_unit").get(id=self.id) ordered_units = learning_module.learning_unit.order_by("order") status_list = [unit.get_completion_status(user, course) - for unit in ordered_units] + for unit in ordered_units + if unit.has_prerequisite()] if not status_list: default_status = "no units" elif all([status == "completed" for status in status_list]): default_status = "completed" - elif "inprogress" in status_list: - default_status = "inprogress" - else: + elif all([status == "not attempted" for status in status_list]): default_status = "not attempted" + else: + default_status = "inprogress" return default_status def is_prerequisite_passed(self, user, course): diff --git a/yaksh/views.py b/yaksh/views.py index 2bc5dfe..27325c6 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -475,6 +475,10 @@ 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 active status + if not learning_module.active: + return view_module(request, module_id, course_id) + # unit module prerequiste check if learning_module.has_prerequisite(): if not learning_module.is_prerequisite_passed(user, course): @@ -1392,7 +1396,8 @@ def design_questionpaper(request, quiz_id, questionpaper_id=None, 'questions': questions, 'fixed_questions': fixed_questions, 'state': state, - 'random_sets': random_sets + 'random_sets': random_sets, + 'course_id': course_id } return my_render_to_response( 'yaksh/design_questionpaper.html', @@ -2348,6 +2353,14 @@ 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 learning module is active + if not learn_module.active: + return view_module(request, module_id, course_id) + # if lesson is active or not + if not learn_unit.lesson.active: + 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): msg = "You have not completed the module previous to {0}".format( @@ -2660,6 +2673,11 @@ 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) + + # Check if module is active or not + if not learning_module.active: + msg = "{0} is not active".format(learning_module.name) + 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): |