Commit 48df2303 authored by Eduardo Nunes's avatar Eduardo Nunes
Browse files

Adding release date into module course

parent b71d5741
# Generated by Django 2.2.24 on 2021-09-28 03:58
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
('courses', '0033_auto_20210805_1035'),
]
operations = [
migrations.AddField(
model_name='lesson',
name='release_date',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now, verbose_name='Date'),
preserve_default=False,
),
]
......@@ -208,7 +208,16 @@ class Course(models.Model):
@property
def public_lessons(self):
return self.lessons.exclude(status='draft')
lessons = []
for lesson in self.lessons.all():
if lesson.status == 'draft':
if lesson.release_date and lesson.release_date <= timezone.now():
lesson.status = 'published'
lesson.save()
lessons.append(lesson)
else:
lessons.append(lesson)
return lessons
def first_lesson(self):
if self.lessons.exists():
......@@ -911,6 +920,10 @@ class Lesson(PositionedModel):
null=True,
blank=True,
)
release_date = models.DateTimeField(
_('Date'),
auto_now_add=True
)
collection_name = 'course'
class Meta:
......@@ -923,8 +936,6 @@ class Lesson(PositionedModel):
lessons = list(self.course.public_lessons)
return len(lessons) > 0 and self == lessons[-1]
def __str__(self):
return self.name
......
......@@ -190,15 +190,15 @@ class LessonSerializer(serializers.ModelSerializer):
units = UnitSerializer(many=True)
is_course_last_lesson = serializers.BooleanField(read_only=True)
thumbnail_url = serializers.ReadOnlyField()
release_date = serializers.DateTimeField()
class Meta:
model = Lesson
fields = ('id', 'course', 'is_course_last_lesson', 'desc',
'name', 'notes', 'position', 'slug', 'status', 'units',
'thumbnail_url')
'name', 'notes', 'position', 'slug', 'status',
'units', 'thumbnail_url')
def update(self, instance, validated_data):
units = self.update_units(self.initial_data.get('units'), instance)
for old_unit in instance.units.all():
......
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