diff --git a/api/v1/serializers/course.py b/api/v1/serializers/course.py index 4c6814a8..8ee35447 100644 --- a/api/v1/serializers/course.py +++ b/api/v1/serializers/course.py @@ -77,6 +77,8 @@ class CourseCreateSerializer(DispatchContentMixin, DispatchMaterialMixin, serializers.ModelSerializer ): + title = serializers.CharField(allow_blank=True) + short_description = serializers.CharField(allow_blank=True) slug = serializers.SlugField(allow_unicode=True, required=False) content = serializers.ListSerializer( child=ContentCreateSerializer(), diff --git a/api/v1/views.py b/api/v1/views.py index 043c0fb8..16a0fc6f 100644 --- a/api/v1/views.py +++ b/api/v1/views.py @@ -81,6 +81,7 @@ class CourseViewSet(ExtendedModelViewSet): serializer_class_map = { 'list': CourseSerializer, 'retrieve': CourseSerializer, + 'draft': CourseSerializer, } filter_fields = ('category', 'status', 'is_infinite', 'is_featured',) search_fields = ('author__email', 'title', 'category__title',) @@ -91,6 +92,13 @@ class CourseViewSet(ExtendedModelViewSet): # 'delete': IsAdmin, # } + @list_route(methods=['get']) + def draft(self, request): + drafts = Course.objects.filter(author=request.user, status=Course.DRAFT) + serializer = self.get_serializer_class() + serialized_data = serializer(instance=drafts.last()) + return Response(serialized_data.data) + class LessonViewSet(ExtendedModelViewSet): queryset = Lesson.objects.select_related( diff --git a/apps/course/fixtures/course.json b/apps/course/fixtures/course.json index 8f9e29d0..6b818598 100644 --- a/apps/course/fixtures/course.json +++ b/apps/course/fixtures/course.json @@ -13,7 +13,7 @@ "category": 2, "duration": 1, "is_featured": false, - "status": 0, + "status": 1, "created_at": "2018-01-27T07:04:41.113Z", "update_at": "2018-01-31T15:03:47.118Z", "likes": [], @@ -34,7 +34,7 @@ "category": 1, "duration": 1, "is_featured": false, - "status": 0, + "status": 1, "created_at": "2018-01-27T07:09:03.437Z", "update_at": "2018-01-31T15:03:47.115Z", "likes": [], @@ -55,7 +55,7 @@ "category": 9, "duration": 1, "is_featured": false, - "status": 0, + "status": 1, "created_at": "2018-01-27T07:09:03.442Z", "update_at": "2018-01-31T15:03:47.112Z", "likes": [], @@ -76,7 +76,7 @@ "category": 8, "duration": 1, "is_featured": false, - "status": 0, + "status": 1, "created_at": "2018-01-27T07:09:03.445Z", "update_at": "2018-01-31T15:03:47.108Z", "likes": [], @@ -97,7 +97,7 @@ "category": 7, "duration": 1, "is_featured": false, - "status": 0, + "status": 1, "created_at": "2018-01-27T07:09:03.449Z", "update_at": "2018-01-31T15:03:47.104Z", "likes": [], @@ -118,7 +118,7 @@ "category": 6, "duration": 1, "is_featured": false, - "status": 0, + "status": 1, "created_at": "2018-01-27T07:09:03.452Z", "update_at": "2018-01-31T15:03:47.101Z", "likes": [], @@ -139,7 +139,7 @@ "category": 5, "duration": 1, "is_featured": false, - "status": 0, + "status": 1, "created_at": "2018-01-27T07:09:03.455Z", "update_at": "2018-01-31T15:03:47.097Z", "likes": [], @@ -160,7 +160,7 @@ "category": 4, "duration": 1, "is_featured": false, - "status": 0, + "status": 1, "created_at": "2018-01-27T07:09:03.458Z", "update_at": "2018-01-31T15:03:47.093Z", "likes": [], @@ -181,7 +181,7 @@ "category": 3, "duration": 1, "is_featured": false, - "status": 0, + "status": 1, "created_at": "2018-01-27T07:09:03.461Z", "update_at": "2018-01-31T15:03:47.089Z", "likes": [], diff --git a/apps/course/migrations/0033_auto_20180214_1346.py b/apps/course/migrations/0033_auto_20180214_1346.py new file mode 100644 index 00000000..a35efd21 --- /dev/null +++ b/apps/course/migrations/0033_auto_20180214_1346.py @@ -0,0 +1,19 @@ +# Generated by Django 2.0.2 on 2018-02-14 13:46 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('course', '0032_auto_20180214_1336'), + ] + + operations = [ + migrations.AlterField( + model_name='course', + name='category', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='course.Category'), + ), + ] diff --git a/apps/course/models.py b/apps/course/models.py index 1ed76ca8..a4820a7b 100644 --- a/apps/course/models.py +++ b/apps/course/models.py @@ -68,7 +68,7 @@ class Course(BaseModel, DeactivatedMixin): 'Отложенный запуск курса', help_text='Заполнить если курс отложенный', null=True, blank=True ) - category = models.ForeignKey('Category', on_delete=models.PROTECT) + category = models.ForeignKey('Category', null=True, blank=True, on_delete=models.PROTECT) duration = models.IntegerField('Продолжительность курса', default=0) is_featured = models.BooleanField(default=False) status = models.PositiveSmallIntegerField( diff --git a/apps/course/views.py b/apps/course/views.py index da8af471..dce54105 100644 --- a/apps/course/views.py +++ b/apps/course/views.py @@ -141,14 +141,18 @@ def lessoncomment(request, lesson_id): }) +@method_decorator(login_required, name='dispatch') class CourseEditView(TemplateView): template_name = 'course/course_edit.html' def get(self, request, pk=None): + drafts = Course.objects.filter(author=request.user, status=Course.DRAFT) if pk: self.object = get_object_or_404(Course, pk=pk) + elif drafts.exists(): + self.object = drafts.last() else: - self.object = None + self.object = Course.objects.create() return super().get(request) def get_context_data(self): diff --git a/apps/user/templates/user/profile.html b/apps/user/templates/user/profile.html index c4085f29..f9d85cdb 100644 --- a/apps/user/templates/user/profile.html +++ b/apps/user/templates/user/profile.html @@ -59,7 +59,7 @@ -
+
diff --git a/web/src/sass/_common.sass b/web/src/sass/_common.sass index a470c883..13a6e6e0 100755 --- a/web/src/sass/_common.sass +++ b/web/src/sass/_common.sass @@ -25,6 +25,7 @@ font-family: 'ProximaNova-Light', serif $pink: #FF9393 +$pink-light: #FDF8F9 $purple: #B995D9 $green: #8ECFC0 $green-light: #5BD700 @@ -742,6 +743,8 @@ a[name] background: url(../img/bg-elephants.jpg) 0 0 / 100px 102px &_gray background: $bg + &_pink-light + background: $pink-light &_border position: relative &:after