diff options
author | adityacp | 2020-04-02 11:05:27 +0530 |
---|---|---|
committer | adityacp | 2020-04-02 11:05:27 +0530 |
commit | 957222b17cd80859158df06ed4c8f2d3b83f2873 (patch) | |
tree | 864bc4d74379430edc26858506fa6a26baf0c1b1 /yaksh | |
parent | e6cce5b0ca4d616b7ff55c66f5d94376974fcc4c (diff) | |
download | online_test-957222b17cd80859158df06ed4c8f2d3b83f2873.tar.gz online_test-957222b17cd80859158df06ed4c8f2d3b83f2873.tar.bz2 online_test-957222b17cd80859158df06ed4c8f2d3b83f2873.zip |
Optimize code to add unit to module only on creation
Diffstat (limited to 'yaksh')
-rw-r--r-- | yaksh/views.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/yaksh/views.py b/yaksh/views.py index c72c4ff..51f6e54 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -351,7 +351,8 @@ def add_quiz(request, course_id=None, module_id=None, quiz_id=None): unit, created = LearningUnit.objects.get_or_create( type="quiz", quiz=added_quiz, order=order ) - module.learning_unit.add(unit.id) + if created: + module.learning_unit.add(unit.id) messages.success(request, "Quiz saved successfully") return redirect( reverse("yaksh:edit_quiz", @@ -406,7 +407,8 @@ def add_exercise(request, course_id=None, module_id=None, quiz_id=None): unit, created = LearningUnit.objects.get_or_create( type="quiz", quiz=quiz, order=order ) - module.learning_unit.add(unit.id) + if created: + module.learning_unit.add(unit.id) messages.success( request, "{0} saved successfully".format(quiz.description) ) @@ -2518,7 +2520,8 @@ def edit_lesson(request, course_id=None, module_id=None, lesson_id=None): unit, created = LearningUnit.objects.get_or_create( type="lesson", lesson=lesson, order=order ) - module.learning_unit.add(unit.id) + if created: + module.learning_unit.add(unit.id) messages.success( request, "Saved {0} successfully".format(lesson.name) ) |