fix: issue with numbering the exercises

The exercises being listed in unpredicted order instead of the order
they were listed in the lesson. The was because the `index_` of the
exercise was never updated. Fixed this by updating the `index_` whenever
a lesson edited. However, the user still need to run reindex exercises
on the course correct the ordering, which wasn't possible earlier.
This commit is contained in:
Anand Chitipothu
2021-06-02 16:30:55 +05:30
parent 0dc4743556
commit 586b39c0fd

View File

@@ -11,11 +11,15 @@ class Lesson(Document):
def before_save(self):
sections = SectionParser().parse(self.body or "")
self.sections = [self.make_lms_section(i, s) for i, s in enumerate(sections)]
index = 1
for s in self.sections:
if s.type == "exercise":
e = s.get_exercise()
e.lesson = self.name
e.index_ = index
e.save()
index += 1
self.update_orphan_exercises()
def update_orphan_exercises(self):