|
|
|
|
@ -71,7 +71,10 @@ class CategorySerializer(serializers.ModelSerializer): |
|
|
|
|
|
|
|
|
|
class CourseCreateSerializer(serializers.ModelSerializer): |
|
|
|
|
slug = serializers.SlugField(allow_unicode=True, required=False) |
|
|
|
|
content = serializers.ListSerializer(child=ContentCreateSerializer(), required=False) |
|
|
|
|
content = serializers.ListSerializer( |
|
|
|
|
child=ContentCreateSerializer(), |
|
|
|
|
required=False, |
|
|
|
|
) |
|
|
|
|
materials = MaterialSerializer(many=True, required=False) |
|
|
|
|
|
|
|
|
|
class Meta: |
|
|
|
|
@ -115,7 +118,7 @@ class CourseCreateSerializer(serializers.ModelSerializer): |
|
|
|
|
|
|
|
|
|
for c in content: |
|
|
|
|
if c['type'] == 'text': |
|
|
|
|
if 'id' in c['data']: |
|
|
|
|
if 'id' in c['data'] and c['data']['id']: |
|
|
|
|
t = Text.objects.get(id=c['data']['id']) |
|
|
|
|
t.position = c['data']['position'] |
|
|
|
|
t.title = c['data']['title'] |
|
|
|
|
@ -130,7 +133,7 @@ class CourseCreateSerializer(serializers.ModelSerializer): |
|
|
|
|
txt=c['data']['txt'], |
|
|
|
|
) |
|
|
|
|
elif c['type'] == 'image': |
|
|
|
|
if 'id' in c['data']: |
|
|
|
|
if 'id' in c['data'] and c['data']['id']: |
|
|
|
|
i = Image.objects.get(id=c['data']['id']) |
|
|
|
|
i.position = c['data']['position'] |
|
|
|
|
i.title = c['data']['title'] |
|
|
|
|
@ -145,7 +148,7 @@ class CourseCreateSerializer(serializers.ModelSerializer): |
|
|
|
|
img=Image.objects.get(id=c['data']['img']['id']), |
|
|
|
|
) |
|
|
|
|
elif c['type'] == 'image-text': |
|
|
|
|
if 'id' in c['data']: |
|
|
|
|
if 'id' in c['data'] and c['data']['id']: |
|
|
|
|
it = ImageText.objects.get(id=c['data']['id']) |
|
|
|
|
it.position = c['data']['position'] |
|
|
|
|
it.title = c['data']['title'] |
|
|
|
|
@ -162,7 +165,7 @@ class CourseCreateSerializer(serializers.ModelSerializer): |
|
|
|
|
txt=c['data']['txt'], |
|
|
|
|
) |
|
|
|
|
elif c['type'] == 'video': |
|
|
|
|
if 'id' in c['data']: |
|
|
|
|
if 'id' in c['data'] and c['data']['id']: |
|
|
|
|
v = Video.objects.get(id=c['data']['id']) |
|
|
|
|
v.position = c['data']['position'] |
|
|
|
|
v.title = c['data']['title'] |
|
|
|
|
@ -177,7 +180,7 @@ class CourseCreateSerializer(serializers.ModelSerializer): |
|
|
|
|
url=c['data']['url'], |
|
|
|
|
) |
|
|
|
|
for material in materials: |
|
|
|
|
if 'id' in material: |
|
|
|
|
if 'id' in material and material['id']: |
|
|
|
|
m = Material.objects.get(id=material['id']) |
|
|
|
|
m.title = material['title'] |
|
|
|
|
m.cover = ImageObject.objects.get(id=material['cover']) |
|
|
|
|
@ -199,7 +202,7 @@ class CourseCreateSerializer(serializers.ModelSerializer): |
|
|
|
|
|
|
|
|
|
for c in content: |
|
|
|
|
if c['type'] == 'text': |
|
|
|
|
if 'id' in c['data']: |
|
|
|
|
if 'id' in c['data'] and c['data']['id']: |
|
|
|
|
t = Text.objects.get(id=c['data']['id']) |
|
|
|
|
t.position = c['data']['position'] |
|
|
|
|
t.title = c['data']['title'] |
|
|
|
|
@ -214,7 +217,7 @@ class CourseCreateSerializer(serializers.ModelSerializer): |
|
|
|
|
txt=c['data']['txt'], |
|
|
|
|
) |
|
|
|
|
elif c['type'] == 'image': |
|
|
|
|
if 'id' in c['data']: |
|
|
|
|
if 'id' in c['data'] and c['data']['id']: |
|
|
|
|
i = Image.objects.get(id=c['data']['id']) |
|
|
|
|
i.position = c['data']['position'] |
|
|
|
|
i.title = c['data']['title'] |
|
|
|
|
@ -229,7 +232,7 @@ class CourseCreateSerializer(serializers.ModelSerializer): |
|
|
|
|
img=Image.objects.get(id=c['data']['img']['id']), |
|
|
|
|
) |
|
|
|
|
elif c['type'] == 'imagetext': |
|
|
|
|
if 'id' in c['data']: |
|
|
|
|
if 'id' in c['data'] and c['data']['id']: |
|
|
|
|
it = ImageText.objects.get(id=c['data']['id']) |
|
|
|
|
it.position = c['data']['position'] |
|
|
|
|
it.title = c['data']['title'] |
|
|
|
|
@ -246,7 +249,7 @@ class CourseCreateSerializer(serializers.ModelSerializer): |
|
|
|
|
txt=c['data']['txt'], |
|
|
|
|
) |
|
|
|
|
elif c['type'] == 'video': |
|
|
|
|
if 'id' in c['data']: |
|
|
|
|
if 'id' in c['data'] and c['data']['id']: |
|
|
|
|
v = Video.objects.get(id=c['data']['id']) |
|
|
|
|
v.position = c['data']['position'] |
|
|
|
|
v.title = c['data']['title'] |
|
|
|
|
@ -261,7 +264,7 @@ class CourseCreateSerializer(serializers.ModelSerializer): |
|
|
|
|
url=c['data']['url'], |
|
|
|
|
) |
|
|
|
|
for material in materials: |
|
|
|
|
if 'id' in material: |
|
|
|
|
if 'id' in material and material['id']: |
|
|
|
|
m = Material.objects.get(id=material['id']) |
|
|
|
|
m.title = material['title'] |
|
|
|
|
m.cover = ImageObject.objects.get(id=material['cover']) |
|
|
|
|
|