Commit 2a02a164 authored by Matheus Miranda's avatar Matheus Miranda
Browse files

Update resume_next_unit to schedulable objects

parent 253d06f0
......@@ -492,24 +492,50 @@ class CourseStudent(models.Model):
def resume_next_unit(self):
try:
last_unit_done = self.units_done.latest('complete')
# try to get the next unit in same lesson
next_unit = Unit.objects.filter(lesson=last_unit_done.unit.lesson,
position__gt=last_unit_done.unit.position).order_by(
'position').first()
next_unit = None
cur_lesson = None
last_unit_done = self.units_done.latest('complete') if self.units_done else None
if last_unit_done:
cur_position = last_unit_done.unit.position
cur_lesson = last_unit_done.unit.lesson
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')
if next_units:
next_unit = next_units.first()
if next_unit:
return next_unit
else:
next_lesson = self.course.lessons.filter(
position__gt=last_unit_done.unit.lesson.position,
status='published').order_by(
'position').first()
if next_lesson and next_lesson.first_unit():
return next_lesson.units.order_by('position').first()
else:
return self.course.first_lesson().first_unit()
lesson_position = cur_lesson.position if cur_lesson else -1
public_lessons = self.course.lessons.filter(
status='published',
position__gt=lesson_position).order_by('position')
for lesson in public_lessons:
public_units = lesson.units.filter(status='published').order_by('position')
if public_units:
return public_units.first()
return None
#next_lesson = self.course.lessons.filter(
# position__gt=last_unit_done.unit.lesson.position,
# status='published').order_by(
# 'position').first()
#if next_lesson and next_lesson.first_unit():
# return next_lesson.units.order_by('position').first()
#else:
# return self.course.first_lesson().first_unit()
except StudentProgress.DoesNotExist:
print("CHEGUEEEIIII NO EXCEPTTTTTTT")
first_lesson = self.course.first_lesson()
if first_lesson:
return first_lesson.first_unit()
......@@ -933,6 +959,19 @@ class Lesson(PositionedModel):
lessons = list(self.course.public_lessons)
return len(lessons) > 0 and self == lessons[-1]
@property
def public_units(self):
units = []
for unit in self.units.all():
if unit.status == 'draft':
if unit.release_date and unit.release_date <= timezone.now():
unit.status = 'published'
unit.save()
units.append(lesson)
else:
units.append(unit)
return units
def __str__(self):
return self.name
......
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