|
|
|
|
@ -163,7 +163,7 @@ class CourseCreateSerializer(DispatchContentMixin, |
|
|
|
|
return CourseSerializer(instance=instance, context=self.context).to_representation(instance) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LessonCreateSerializer(serializers.ModelSerializer): |
|
|
|
|
class LessonCreateSerializer(DispatchContentMixin, serializers.ModelSerializer): |
|
|
|
|
content = serializers.ListSerializer( |
|
|
|
|
child=ContentCreateSerializer(), |
|
|
|
|
required=False, |
|
|
|
|
@ -190,110 +190,6 @@ class LessonCreateSerializer(serializers.ModelSerializer): |
|
|
|
|
'deactivated_at', |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
def dispatch_content(self, lesson, content): |
|
|
|
|
for c in content: |
|
|
|
|
if 'type' not in c or not c['type'] or 'data' not in c or not c['data']: |
|
|
|
|
continue |
|
|
|
|
ctype = c['type'] |
|
|
|
|
cdata = c['data'] |
|
|
|
|
if ctype == 'text': |
|
|
|
|
if 'id' in cdata and cdata['id']: |
|
|
|
|
t = Text.objects.get(id=cdata['id']) |
|
|
|
|
t.position = cdata['position'] |
|
|
|
|
t.title = cdata['title'] |
|
|
|
|
t.lesson = lesson |
|
|
|
|
t.txt = cdata['txt'] |
|
|
|
|
t.uuid = cdata['uuid'] |
|
|
|
|
t.save() |
|
|
|
|
else: |
|
|
|
|
t = Text.objects.create( |
|
|
|
|
position=cdata['position'], |
|
|
|
|
title=cdata['title'], |
|
|
|
|
lesson=lesson, |
|
|
|
|
txt=cdata['txt'], |
|
|
|
|
uuid=cdata['uuid'], |
|
|
|
|
) |
|
|
|
|
elif ctype == 'image': |
|
|
|
|
if 'id' in cdata and cdata['id']: |
|
|
|
|
image = Image.objects.get(id=cdata['id']) |
|
|
|
|
image.position = cdata['position'] |
|
|
|
|
image.title = cdata['title'] |
|
|
|
|
image.lesson = lesson |
|
|
|
|
image.img = ImageObject.objects.get(id=cdata['img']) |
|
|
|
|
image.uuid = cdata['uuid'] |
|
|
|
|
image.save() |
|
|
|
|
else: |
|
|
|
|
image = Image.objects.create( |
|
|
|
|
position=cdata['position'], |
|
|
|
|
title=cdata['title'], |
|
|
|
|
lesson=lesson, |
|
|
|
|
img=ImageObject.objects.get(id=cdata['img']), |
|
|
|
|
uuid=cdata['uuid'], |
|
|
|
|
) |
|
|
|
|
elif ctype == 'image-text': |
|
|
|
|
if 'id' in cdata and cdata['id']: |
|
|
|
|
it = ImageText.objects.get(id=cdata['id']) |
|
|
|
|
it.position = cdata['position'] |
|
|
|
|
it.title = cdata['title'] |
|
|
|
|
it.lesson = lesson |
|
|
|
|
it.img = ImageObject.objects.get(id=cdata['img']) |
|
|
|
|
it.txt = cdata['txt'] |
|
|
|
|
it.uuid = cdata['uuid'] |
|
|
|
|
it.save() |
|
|
|
|
else: |
|
|
|
|
it = ImageText.objects.create( |
|
|
|
|
position=cdata['position'], |
|
|
|
|
title=cdata['title'], |
|
|
|
|
lesson=lesson, |
|
|
|
|
img=ImageObject.objects.get(id=cdata['img']), |
|
|
|
|
txt=cdata['txt'], |
|
|
|
|
uuid=cdata['uuid'], |
|
|
|
|
) |
|
|
|
|
elif ctype == 'video': |
|
|
|
|
if 'id' in cdata and cdata['id']: |
|
|
|
|
v = Video.objects.get(id=cdata['id']) |
|
|
|
|
v.position = cdata['position'] |
|
|
|
|
v.title = cdata['title'] |
|
|
|
|
v.lesson = lesson |
|
|
|
|
v.url = cdata['url'] |
|
|
|
|
v.uuid = cdata['uuid'] |
|
|
|
|
v.save() |
|
|
|
|
else: |
|
|
|
|
v = Video.objects.create( |
|
|
|
|
position=cdata['position'], |
|
|
|
|
title=cdata['title'], |
|
|
|
|
lesson=lesson, |
|
|
|
|
url=cdata['url'], |
|
|
|
|
uuid=cdata['uuid'], |
|
|
|
|
) |
|
|
|
|
elif ctype == 'images': |
|
|
|
|
if 'id' in cdata and cdata['id']: |
|
|
|
|
g = Gallery.objects.get(id=cdata['id']) |
|
|
|
|
g.position = cdata['position'] |
|
|
|
|
g.title = cdata['title'] |
|
|
|
|
g.lesson = lesson |
|
|
|
|
g.uuid = cdata['uuid'] |
|
|
|
|
g.save() |
|
|
|
|
if 'images' in cdata: |
|
|
|
|
for image in cdata['images']: |
|
|
|
|
gi = GalleryImage.objects.create( |
|
|
|
|
gallery=g, |
|
|
|
|
img=ImageObject.objects.get(id=image['img']), |
|
|
|
|
) |
|
|
|
|
else: |
|
|
|
|
g = Gallery.objects.create( |
|
|
|
|
lesson=lesson, |
|
|
|
|
position=cdata['position'], |
|
|
|
|
title=cdata['title'], |
|
|
|
|
uuid=cdata['uuid'], |
|
|
|
|
) |
|
|
|
|
if 'images' in cdata: |
|
|
|
|
for image in cdata['images']: |
|
|
|
|
gi = GalleryImage.objects.create( |
|
|
|
|
gallery=g, |
|
|
|
|
img=ImageObject.objects.get(id=image['img']), |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
def create(self, validated_data): |
|
|
|
|
content = validated_data.pop('content', []) |
|
|
|
|
lesson = super().create(validated_data) |
|
|
|
|
|