|
|
|
@ -13,7 +13,7 @@ from apps.course.models import ( |
|
|
|
from .content import ( |
|
|
|
from .content import ( |
|
|
|
ImageObjectSerializer, ContentSerializer, ContentCreateSerializer, |
|
|
|
ImageObjectSerializer, ContentSerializer, ContentCreateSerializer, |
|
|
|
GallerySerializer, ) |
|
|
|
GallerySerializer, ) |
|
|
|
from .mixins import DispatchContentMixin, DispatchGalleryMixin, DispatchMaterialMixin |
|
|
|
from .mixins import DispatchContentMixin, DispatchGalleryMixin, DispatchMaterialMixin, DispatchTagsMixin |
|
|
|
from .user import UserSerializer |
|
|
|
from .user import UserSerializer |
|
|
|
|
|
|
|
|
|
|
|
User = get_user_model() |
|
|
|
User = get_user_model() |
|
|
|
@ -22,7 +22,7 @@ User = get_user_model() |
|
|
|
class TagSerializer(serializers.ModelSerializer): |
|
|
|
class TagSerializer(serializers.ModelSerializer): |
|
|
|
class Meta: |
|
|
|
class Meta: |
|
|
|
model = Tag |
|
|
|
model = Tag |
|
|
|
fields = ('tag',) |
|
|
|
fields = ('__all__') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MaterialCreateSerializer(serializers.ModelSerializer): |
|
|
|
class MaterialCreateSerializer(serializers.ModelSerializer): |
|
|
|
@ -109,6 +109,7 @@ class CourseBulkChangeCategorySerializer(serializers.Serializer): |
|
|
|
class CourseCreateSerializer(DispatchContentMixin, |
|
|
|
class CourseCreateSerializer(DispatchContentMixin, |
|
|
|
DispatchGalleryMixin, |
|
|
|
DispatchGalleryMixin, |
|
|
|
DispatchMaterialMixin, |
|
|
|
DispatchMaterialMixin, |
|
|
|
|
|
|
|
DispatchTagsMixin, |
|
|
|
serializers.ModelSerializer |
|
|
|
serializers.ModelSerializer |
|
|
|
): |
|
|
|
): |
|
|
|
title = serializers.CharField(allow_blank=True) |
|
|
|
title = serializers.CharField(allow_blank=True) |
|
|
|
@ -169,12 +170,14 @@ class CourseCreateSerializer(DispatchContentMixin, |
|
|
|
materials = validated_data.pop('materials', []) |
|
|
|
materials = validated_data.pop('materials', []) |
|
|
|
gallery = validated_data.pop('gallery', {}) |
|
|
|
gallery = validated_data.pop('gallery', {}) |
|
|
|
author = validated_data.get('author', None) |
|
|
|
author = validated_data.get('author', None) |
|
|
|
|
|
|
|
tags = validated_data.pop('tags', []) |
|
|
|
if not author: |
|
|
|
if not author: |
|
|
|
validated_data['author'] = self.context['request'].user |
|
|
|
validated_data['author'] = self.context['request'].user |
|
|
|
course = super().create(validated_data) |
|
|
|
course = super().create(validated_data) |
|
|
|
self.dispatch_content(course, content) |
|
|
|
self.dispatch_content(course, content) |
|
|
|
self.dispatch_materials(course, materials) |
|
|
|
self.dispatch_materials(course, materials) |
|
|
|
self.dispatch_gallery(course, gallery) |
|
|
|
self.dispatch_gallery(course, gallery) |
|
|
|
|
|
|
|
self.dispatch_tags(course, tags) |
|
|
|
return course |
|
|
|
return course |
|
|
|
|
|
|
|
|
|
|
|
def update(self, instance, validated_data): |
|
|
|
def update(self, instance, validated_data): |
|
|
|
@ -182,12 +185,14 @@ class CourseCreateSerializer(DispatchContentMixin, |
|
|
|
materials = validated_data.pop('materials', []) |
|
|
|
materials = validated_data.pop('materials', []) |
|
|
|
gallery = validated_data.pop('gallery', {}) |
|
|
|
gallery = validated_data.pop('gallery', {}) |
|
|
|
author = validated_data.get('author', None) |
|
|
|
author = validated_data.get('author', None) |
|
|
|
|
|
|
|
tags = validated_data.pop('tags', []) |
|
|
|
if not instance.author or author and instance.author != author: |
|
|
|
if not instance.author or author and instance.author != author: |
|
|
|
validated_data['author'] = self.context['request'].user |
|
|
|
validated_data['author'] = self.context['request'].user |
|
|
|
course = super().update(instance, validated_data) |
|
|
|
course = super().update(instance, validated_data) |
|
|
|
self.dispatch_materials(course, materials) |
|
|
|
self.dispatch_materials(course, materials) |
|
|
|
self.dispatch_content(course, content) |
|
|
|
self.dispatch_content(course, content) |
|
|
|
self.dispatch_gallery(course, gallery) |
|
|
|
self.dispatch_gallery(course, gallery) |
|
|
|
|
|
|
|
self.dispatch_tags(course, tags) |
|
|
|
return course |
|
|
|
return course |
|
|
|
|
|
|
|
|
|
|
|
def to_representation(self, instance): |
|
|
|
def to_representation(self, instance): |
|
|
|
|