Commit 04ac4604 authored by Eduardo Nunes's avatar Eduardo Nunes
Browse files

Adding status and release date into Unit model

parent 7c49001e
# Generated by Django 2.2.24 on 2021-10-08 21:03
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
('courses', '0034_lesson_release_date'),
]
operations = [
migrations.AddField(
model_name='unit',
name='release_date',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now, verbose_name='Date'),
preserve_default=False,
),
]
# Generated by Django 2.2.24 on 2021-10-11 18:42
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('courses', '0035_unit_release_date'),
]
operations = [
migrations.AddField(
model_name='unit',
name='status',
field=models.CharField(choices=[('draft', 'Draft'), ('published', 'Published')], default='draft', max_length=64, verbose_name='Status'),
),
]
......@@ -204,7 +204,7 @@ class Course(models.Model):
@property
def unit_set(self):
return Unit.objects.filter(lesson__in=self.lessons.all()).order_by('lesson')
return Unit.objects.filter(lesson__in=self.lessons.all(), status='published').order_by('lesson')
@property
def public_lessons(self):
......@@ -972,6 +972,10 @@ class Lesson(PositionedModel):
class Unit(PositionedModel):
STATES = (
('draft', _('Draft')),
('published', _('Published')),
)
title = models.CharField(
_('Title'),
max_length=128,
......@@ -1007,6 +1011,16 @@ class Unit(PositionedModel):
blank=True,
null=True,
)
status = models.CharField(
_('Status'),
choices=STATES,
default=STATES[0][0],
max_length=64,
)
release_date = models.DateTimeField(
_('Date'),
auto_now_add=True
)
collection_name = 'lesson'
......
......@@ -179,10 +179,12 @@ class ProfessorMessageSerializer(serializers.ModelSerializer):
class UnitSerializer(serializers.ModelSerializer):
video = VideoSerializer(required=False, allow_null=True)
activities = ActivitySerializer(many=True, required=False, allow_null=True)
release_date = serializers.DateTimeField(required=False)
class Meta:
model = Unit
fields = ('id', 'title', 'video', 'activities', 'side_notes', 'position', 'chat_room',)
fields = ('id', 'title', 'video', 'activities', 'side_notes',
'position', 'chat_room', 'release_date', 'status',)
class LessonSerializer(serializers.ModelSerializer):
......
......@@ -289,7 +289,7 @@ class LessonViewSet(viewsets.ModelViewSet):
def get_queryset(self):
queryset = super(LessonViewSet, self).get_queryset()
course_id = self.kwargs['course_id']
return queryset.filter(status='published', course_id=course_id)
return queryset.filter(status='published', units__status='published', course_id=course_id)
class CourseAuthorViewSet(viewsets.ModelViewSet):
......
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