diff options
Diffstat (limited to 'yaksh/models.py')
-rw-r--r-- | yaksh/models.py | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index aa65ad9..1d24bda 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -158,6 +158,9 @@ class Lesson(models.Model): def __str__(self): return "{0}".format(self.name) + def get_files(self): + return LessonFile.objects.filter(lesson=self) + ############################################################################# class LessonFile(models.Model): @@ -233,7 +236,7 @@ class QuizManager(models.Manager): quiz = learning_modules[0].learning_unit.filter(quiz=trial_quiz) if not quiz.exists(): trial_learning_unit = LearningUnit.objects.create( - order=1, quiz=trial_quiz, learning_type="quiz", + order=1, quiz=trial_quiz, type="quiz", check_prerequisite=False) learning_modules[0].learning_unit.add(trial_learning_unit.id) trial_learning_module = learning_modules[0] @@ -242,7 +245,7 @@ class QuizManager(models.Manager): name="Trial for {}".format(trial_course), order=1, check_prerequisite=False, creator=user, is_trial=True) trial_learning_unit = LearningUnit.objects.create( - order=1, quiz=trial_quiz, learning_type="quiz", + order=1, quiz=trial_quiz, type="quiz", check_prerequisite=False) trial_learning_module.learning_unit.add(trial_learning_unit.id) trial_course.learning_module.add(trial_learning_module.id) @@ -359,7 +362,7 @@ class Quiz(models.Model): class LearningUnit(models.Model): """ Maintain order of lesson and quiz added in the course """ order = models.IntegerField() - learning_type = models.CharField(max_length=16) + type = models.CharField(max_length=16) lesson = models.ForeignKey(Lesson, null=True, blank=True) quiz = models.ForeignKey(Quiz, null=True, blank=True) check_prerequisite = models.BooleanField(default=True) @@ -415,7 +418,7 @@ class LearningModule(models.Model): def get_quiz_units(self): return [unit.quiz for unit in self.learning_unit.filter( - learning_type="quiz")] + type="quiz")] def get_learning_units(self): return self.learning_unit.order_by("order") @@ -425,7 +428,7 @@ class LearningModule(models.Model): added_quiz_lessons = [] if learning_units.exists(): for unit in learning_units: - if unit.learning_type == "quiz": + if unit.type == "quiz": added_quiz_lessons.append(("quiz", unit.quiz)) else: added_quiz_lessons.append(("lesson", unit.lesson)) @@ -608,11 +611,18 @@ class Course(models.Model): demo_que_ppr = QuestionPaper() demo_que_ppr.create_demo_quiz_ppr(demo_quiz, user) success = True - ordered_unit = LearningUnit.objects.create( - order=1, learning_type="quiz", quiz=demo_quiz) + demo_lesson = Lesson.objects.create( + name="Demo lesson", description="demo lesson", + html_data="demo lesson", creator=user) + quiz_unit = LearningUnit.objects.create( + order=1, type="quiz", quiz=demo_quiz) + lesson_unit = LearningUnit.objects.create( + order=2, type="lesson", lesson=demo_lesson) learning_module = LearningModule.objects.create( - name="demo module", description="demo module", creator=user) - learning_module.learning_unit.add(ordered_unit) + name="demo module", description="demo module", creator=user, + html_data="demo module") + learning_module.learning_unit.add(quiz_unit) + learning_module.learning_unit.add(lesson_unit) course.learning_module.add(learning_module) else: success = False |