Commit d28c3ea3 authored by Matheus Miranda's avatar Matheus Miranda
Browse files

Add conditition for post released units

parent c106fedf
......@@ -502,15 +502,25 @@ class CourseStudent(models.Model):
if last_unit_done:
cur_position = last_unit_done.unit.position
cur_lesson = last_unit_done.unit.lesson
units_done_ids = [sp.unit.id for sp in self.units_done]
if cur_lesson.status == 'published':
next_units = Unit.objects.filter(lesson=last_unit_done.unit.lesson,
position__gt=cur_position,
status='published').order_by('position')
position__gt=cur_position,
status='published').exclude(id__in=units_done_ids).order_by('position')
if next_units:
next_unit = next_units.first()
elif cur_lesson == self.course.public_lessons[-1]:
next_unit = last_unit_done.unit
else:
# If there is no foward units, get the first one not completed
prev_public_units = Unit.objects.filter(lesson__course=cur_lesson.course,
lesson__status='published',
status='published').exclude(id__in=units_done_ids)
if prev_public_units:
next_unit = prev_public_units.first()
elif cur_lesson == self.course.public_lessons[-1]:
next_unit = last_unit_done.unit
if next_unit:
return next_unit
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment