From fa8e9bbbf071f83a93363aca7f04964f89338102 Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Thu, 15 Feb 2018 12:56:02 +0300 Subject: [PATCH 01/21] Fix courses in profile --- apps/course/templates/course/_items.html | 6 ++++++ apps/user/templates/user/profile.html | 8 ++++---- apps/user/views.py | 2 +- web/src/sass/_common.sass | 2 ++ 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/apps/course/templates/course/_items.html b/apps/course/templates/course/_items.html index 407526ca..81b06691 100644 --- a/apps/course/templates/course/_items.html +++ b/apps/course/templates/course/_items.html @@ -22,6 +22,12 @@
{% endif %} + {% if course.status == 1 %} +
+
КУРС ПРОХОДИТ МОДЕРАЦИЮ
+
+
+ {% endif %}
ОПУБЛИКОВАННЫЕ КУРСЫ - + {% endcomment %}
@@ -92,7 +92,7 @@
-
+ {% comment %}
{% include "course/course_items.html" with course_items=pending %} @@ -105,7 +105,7 @@ {% include "course/course_items.html" with course_items=drafts %}
-
+
{% endcomment %} diff --git a/apps/user/views.py b/apps/user/views.py index fe977a57..911cb06f 100644 --- a/apps/user/views.py +++ b/apps/user/views.py @@ -37,7 +37,7 @@ class UserView(DetailView): def get_context_data(self, object): context = super().get_context_data() context['published'] = Course.objects.filter( - author=self.object, status=Course.PUBLISHED + author=self.object, ) context['pending'] = Course.objects.filter( author=self.object, status=Course.PENDING diff --git a/web/src/sass/_common.sass b/web/src/sass/_common.sass index 13a6e6e0..0f733bc1 100755 --- a/web/src/sass/_common.sass +++ b/web/src/sass/_common.sass @@ -2755,6 +2755,8 @@ a.grey-link height: 56px margin-bottom: 40px border-bottom: 1px solid $border + align-items: center; + justify-content: center; +m margin: 0 -15px 30px &__btn From d6a7533b452426ca16c96f9c76af9e35a4d07355 Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Thu, 15 Feb 2018 14:30:48 +0300 Subject: [PATCH 02/21] Fix auto assign author --- api/v1/serializers/course.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/v1/serializers/course.py b/api/v1/serializers/course.py index 226c8bfc..0ee480bd 100644 --- a/api/v1/serializers/course.py +++ b/api/v1/serializers/course.py @@ -142,7 +142,7 @@ class CourseCreateSerializer(DispatchContentMixin, materials = validated_data.pop('materials', []) gallery = validated_data.pop('gallery', {}) author = validated_data.get('author', None) - if not instance.author or not author: + if not instance.author or author and instance.author != author: validated_data['author'] = self.context['request'].user course = super().update(instance, validated_data) self.dispatch_materials(course, materials) From c6280f55593f36d8bd87d91ad2fbffe6590a9a87 Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Thu, 15 Feb 2018 14:39:20 +0300 Subject: [PATCH 03/21] LIL-250. Fix course title & short description in course template --- apps/course/templates/course/course.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/course/templates/course/course.html b/apps/course/templates/course/course.html index 62ad1a2c..f0e5794d 100644 --- a/apps/course/templates/course/course.html +++ b/apps/course/templates/course/course.html @@ -317,8 +317,8 @@
-
Как просто научиться рисовать простых персонажей.
-
Этот курс поможет детям узнать о том как из простых форм создавать веселый и харизматичных персонажей.
+
{{ course.title }}
+
{{ course.short_description }}
{% if course.author.photo %} From ccbc63ade0212db0496f4b8eb976814cc9a5f400 Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Thu, 15 Feb 2018 14:52:00 +0300 Subject: [PATCH 04/21] LIL-249. Add moderate notification page --- .../templates/course/course_on_moderation.html | 13 +++++++++++++ apps/course/views.py | 5 +++++ project/urls.py | 7 ++++++- 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 apps/course/templates/course/course_on_moderation.html diff --git a/apps/course/templates/course/course_on_moderation.html b/apps/course/templates/course/course_on_moderation.html new file mode 100644 index 00000000..6162f39e --- /dev/null +++ b/apps/course/templates/course/course_on_moderation.html @@ -0,0 +1,13 @@ +{% extends "templates/lilcity/index.html" %} +{% load static %} + +{% block content %} + +{% endblock content %} diff --git a/apps/course/views.py b/apps/course/views.py index dce54105..f0cf1c57 100644 --- a/apps/course/views.py +++ b/apps/course/views.py @@ -141,6 +141,11 @@ def lessoncomment(request, lesson_id): }) +@method_decorator(login_required, name='dispatch') +class CourseOnModerationView(TemplateView): + template_name = 'course/course_on_moderation.html' + + @method_decorator(login_required, name='dispatch') class CourseEditView(TemplateView): template_name = 'course/course_edit.html' diff --git a/project/urls.py b/project/urls.py index 4b426d97..a2ac246b 100644 --- a/project/urls.py +++ b/project/urls.py @@ -22,9 +22,13 @@ from apps.course.views import ( CoursesView, likes, coursecomment, CourseView, LessonView, SearchView, lessoncomment, CourseEditView, + CourseOnModerationView, ) from apps.course.models import Course -from apps.user.views import UserView, UserEditView, NotificationEditView, PaymentHistoryView, resend_email_verify +from apps.user.views import ( + UserView, UserEditView, NotificationEditView, + PaymentHistoryView, resend_email_verify, +) urlpatterns = [ path('admin/', admin.site.urls), @@ -34,6 +38,7 @@ urlpatterns = [ path('course//', CourseView.as_view(), name='course'), path('course//like', likes, name='likes'), path('course/create', CourseEditView.as_view(), name='course_create'), + path('course/on-moderation', CourseOnModerationView.as_view(), name='course-on-moderation'), path('course//edit', CourseEditView.as_view(), name='course_edit'), path('course//comment', coursecomment, name='coursecomment'), path('lesson//', LessonView.as_view(), name='lesson'), From ac572abc9a6b1a2133eb70380b13148cefe1501e Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Thu, 15 Feb 2018 15:30:56 +0300 Subject: [PATCH 05/21] LIL-246. Lesson list --- apps/course/templates/course/course.html | 36 ++- .../templates/course/course_only_lessons.html | 273 ++++++++++++++++++ project/urls.py | 7 +- 3 files changed, 304 insertions(+), 12 deletions(-) create mode 100644 apps/course/templates/course/course_only_lessons.html diff --git a/apps/course/templates/course/course.html b/apps/course/templates/course/course.html index f0e5794d..2186602a 100644 --- a/apps/course/templates/course/course.html +++ b/apps/course/templates/course/course.html @@ -131,15 +131,25 @@
- + Описание курса + {% if request.user.role == request.user.AUTHOR_ROLE or request.user.role == request.user.ADMIN_ROLE %} + УРОКИ + {% comment %} + + {% endcomment %} + + {% else %} + {% endif %}
{% if course.cover %} @@ -231,7 +241,11 @@
Содержание курса
{% for lesson in course.lessons.all %} - + {% if request.user.role == request.user.AUTHOR_ROLE or request.user.role == request.user.ADMIN_ROLE %} + + {% else %} +
+ {% endif %}
{{ lesson.title }}
@@ -247,7 +261,11 @@
{{ lesson.short_description | safe }}
-
+ {% if request.user.role == request.user.AUTHOR_ROLE or request.user.role == request.user.ADMIN_ROLE %} + + {% else %} +
+ {% endif %} {% endfor %}
{% comment %}
diff --git a/apps/course/templates/course/course_only_lessons.html b/apps/course/templates/course/course_only_lessons.html new file mode 100644 index 00000000..88667fc0 --- /dev/null +++ b/apps/course/templates/course/course_only_lessons.html @@ -0,0 +1,273 @@ +{% extends "templates/lilcity/index.html" %} +{% load static %} +{% load data_liked from data_liked %} +{% load rupluralize from plural %} +{% block title %}{{ course.title }} - {{ block.super }}{% endblock title %} +{% comment %} seo tags {% endcomment %} +{% block description %}{{ course.short_description }}{% endblock description%} +{% block twurl %}{{ request.build_absolute_uri }}{% endblock twurl %} +{% block ogtitle %}{{ course.title }} - {{ block.super }}{% endblock ogtitle %} +{% block ogurl %}{{ request.build_absolute_uri }}{% endblock ogurl %} +{% if course.cover %} +{% block ogimage %}{{ request.build_absolute_uri }}{{ course.cover.url }}{% endblock ogimage %} +{% endif %} +{% block ogdescription %}{{ course.short_description }}{% endblock ogdescription %} + +{% block content %} +
+
+
+ +
+ + + +
+
Вернуться
+
+ +
+
+
+
{{ course.category.title | upper }}
+ {% data_liked user course as liked %} + +
+
{{ course.title }}
+
{{ course.short_description }}
+ +
+ {% if course.author.photo %} +
+ +
+ {% else %} +
+ +
+ {% endif %} +
+
{{ course.author.get_full_name }}
+
+
{{ course.created_at_humanize }}
+
+
+
+
+
+
+
+
+ + + +
+
{{ course.duration | rupluralize:"день,дня,дней" }}
+
+
+
+ + + +
+
{{ course.created_at | date:"d F Yг." }}
+
+
+
+ + + +
+
{{ course.price|floatformat:"-2" }}₽
+
+
+
+
+
+ + + +
+
{{ course.lessons.count | rupluralize:"урок,урока,уроков" }}
+
+
+
+ + + +
+
{{ course.count_videos_in_lessons }} видео
+
+
+
+ +
+
+{% if user.is_authenticated and course.lessons.exists %} +
+
+
+
Содержание курса
+ + {% comment %}
+ +
{% endcomment %} +
+
+
+{% comment %}
+
+
Материалы, которые понадобятся
+
+ {% for material in course.materials.all %} +
+ {% if material.cover %} +
+ +
+ {% else %} +
+ +
+ {% endif %} +
+
{{ material.title }}
+
{{ material.short_description }}
+
+
+ {% endfor %} +
+
+
{% endcomment %} +{% endif %} +{% if course.gallery %} +
+
+ {% include "course/content/gallery.html" with results=True %} +
+
+{% endif %} +
+
+
Задавайте вопросы:
+
+ {% if user.is_authenticated %} +
+ +
+ +
+
+ +
+ +
+ +
+
+ {% else %} +
Только зарегистрированные пользователи могут оставлять комментарии.
+ {% endif %} +
+ {% include "./blocks/comments.html" with object=course %} +
+
+
+
+
+
+ +
+
+{% endblock content %} \ No newline at end of file diff --git a/project/urls.py b/project/urls.py index a2ac246b..2df911b7 100644 --- a/project/urls.py +++ b/project/urls.py @@ -34,12 +34,13 @@ urlpatterns = [ path('admin/', admin.site.urls), path('auth/', include(('apps.auth.urls', 'lilcity'))), path('courses/', CoursesView.as_view(), name='courses'), - path('course//', CourseView.as_view(), name='course'), - path('course//', CourseView.as_view(), name='course'), - path('course//like', likes, name='likes'), path('course/create', CourseEditView.as_view(), name='course_create'), path('course/on-moderation', CourseOnModerationView.as_view(), name='course-on-moderation'), + path('course//', CourseView.as_view(), name='course'), + path('course//', CourseView.as_view(), name='course'), path('course//edit', CourseEditView.as_view(), name='course_edit'), + path('course//lessons', CourseView.as_view(template_name='course/course_only_lessons.html'), name='course-only-lessons'), + path('course//like', likes, name='likes'), path('course//comment', coursecomment, name='coursecomment'), path('lesson//', LessonView.as_view(), name='lesson'), path('lesson//comment', lessoncomment, name='lessoncomment'), From 96cd76366ddfc30f5a54d5c74c06fd3da6041481 Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Thu, 15 Feb 2018 15:33:31 +0300 Subject: [PATCH 06/21] Fix user succes url --- apps/user/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/user/views.py b/apps/user/views.py index 911cb06f..58927b26 100644 --- a/apps/user/views.py +++ b/apps/user/views.py @@ -117,4 +117,4 @@ class UserEditView(UpdateView): return super().post(request, *args, **kwargs) def get_success_url(self): - return reverse('user-edit', args=[self.object.id]) + return reverse('user-edit-profile', args=[self.object.id]) From 20c0ffba00e395dc0a61e21e655d7e773c5ef2d9 Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Thu, 15 Feb 2018 15:33:54 +0300 Subject: [PATCH 07/21] Birthday not required --- apps/user/forms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/user/forms.py b/apps/user/forms.py index 697d3910..669a0fa0 100644 --- a/apps/user/forms.py +++ b/apps/user/forms.py @@ -10,7 +10,7 @@ class UserEditForm(forms.ModelForm): # email = forms.CharField() # city = forms.CharField() # country = forms.CharField() - birthday = forms.DateField(input_formats=['%d.%m.%Y']) + birthday = forms.DateField(input_formats=['%d.%m.%Y'], required=False) # gender = forms.ChoiceField(choices=User.GENDER_CHOICES, required=False) gender = forms.CharField(required=False) # about = forms.CharField() From e9747e521c27453a1fccb30a1bedc93ddc95b660 Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Thu, 15 Feb 2018 15:34:36 +0300 Subject: [PATCH 08/21] Clean not needed --- apps/user/templates/user/profile-settings.html | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/user/templates/user/profile-settings.html b/apps/user/templates/user/profile-settings.html index c9b3633d..68d41375 100644 --- a/apps/user/templates/user/profile-settings.html +++ b/apps/user/templates/user/profile-settings.html @@ -31,7 +31,6 @@
{% endif %} -{{form.errors}}
From 275d7fc25e8c282bf7c4e2c21d9a2ec4fca1ddc8 Mon Sep 17 00:00:00 2001 From: nikita Date: Thu, 15 Feb 2018 15:43:01 +0300 Subject: [PATCH 09/21] Save status message fix --- web/src/sass/_common.sass | 1 + 1 file changed, 1 insertion(+) diff --git a/web/src/sass/_common.sass b/web/src/sass/_common.sass index 003754f4..7eaa7d7c 100755 --- a/web/src/sass/_common.sass +++ b/web/src/sass/_common.sass @@ -334,6 +334,7 @@ a.btn padding: 10px 15px background: white &__status + width: 100px margin-right: 5px +fb font-size: 12px From f6a8d0eece98f7bce9da9e65b19766a460753e9e Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Thu, 15 Feb 2018 15:46:59 +0300 Subject: [PATCH 10/21] Add title for draft course --- apps/course/templates/course/_items.html | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apps/course/templates/course/_items.html b/apps/course/templates/course/_items.html index 81b06691..f49be5eb 100644 --- a/apps/course/templates/course/_items.html +++ b/apps/course/templates/course/_items.html @@ -28,6 +28,12 @@
{% endif %} + {% elif course.status == 0 %} +
+
ЧЕРНОВИК
+
+
+ {% endif %}
- {% endif %} {% elif course.status == 0 %}
From 8a1e88d7c0629490f03588e72632ff1d81814ee2 Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Thu, 15 Feb 2018 16:24:28 +0300 Subject: [PATCH 14/21] Delete play icon from cover --- apps/course/templates/course/course.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/course/templates/course/course.html b/apps/course/templates/course/course.html index 2186602a..04339663 100644 --- a/apps/course/templates/course/course.html +++ b/apps/course/templates/course/course.html @@ -163,9 +163,9 @@
{{ course.deferred_start_at_humanize }}
{% else %} - + {% comment %} - + {% endcomment %} {% endif %} From 9c3161275715528869998eabcb32631f78313035 Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Thu, 15 Feb 2018 16:27:40 +0300 Subject: [PATCH 15/21] Fix user social links & about --- apps/user/templates/user/profile.html | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/apps/user/templates/user/profile.html b/apps/user/templates/user/profile.html index c6a6497f..9af22213 100644 --- a/apps/user/templates/user/profile.html +++ b/apps/user/templates/user/profile.html @@ -17,31 +17,31 @@
Изменить From 52cd3c49e8acf4ab11f354038b34b1dea064784b Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Thu, 15 Feb 2018 16:48:50 +0300 Subject: [PATCH 16/21] Dont show lesson cover --- apps/course/templates/course/course.html | 6 +++--- apps/course/templates/course/lesson.html | 14 ++++++++------ apps/course/views.py | 6 ++++++ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/apps/course/templates/course/course.html b/apps/course/templates/course/course.html index 04339663..6bd03bbc 100644 --- a/apps/course/templates/course/course.html +++ b/apps/course/templates/course/course.html @@ -242,14 +242,14 @@
{% for lesson in course.lessons.all %} {% if request.user.role == request.user.AUTHOR_ROLE or request.user.role == request.user.ADMIN_ROLE %} - + {% else %}
{% endif %}
{{ lesson.title }}
- {% if lesson.cover %} + {% comment %} {% if lesson.cover %}
@@ -257,7 +257,7 @@
- {% endif %} + {% endif %} {% endcomment %}
{{ lesson.short_description | safe }}
diff --git a/apps/course/templates/course/lesson.html b/apps/course/templates/course/lesson.html index 09ba9168..9286f106 100644 --- a/apps/course/templates/course/lesson.html +++ b/apps/course/templates/course/lesson.html @@ -6,7 +6,7 @@
diff --git a/apps/course/views.py b/apps/course/views.py index f0cf1c57..3bab031a 100644 --- a/apps/course/views.py +++ b/apps/course/views.py @@ -264,6 +264,12 @@ class LessonView(DetailView): raise Http404 return response + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context['next'] = self.request.GET.get('next', None) + context['next_lesson'] = self.request.GET.get('next_lesson', None) + return context + class SearchView(CoursesView): template_name = 'course/result.html' From 87d858a445cb3b99761e07bd764ccef28f4b15c7 Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Thu, 15 Feb 2018 17:00:12 +0300 Subject: [PATCH 17/21] Fix user perms for course detail page --- apps/course/views.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/course/views.py b/apps/course/views.py index 3bab031a..7431cda4 100644 --- a/apps/course/views.py +++ b/apps/course/views.py @@ -151,7 +151,9 @@ 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) + drafts = Course.objects.filter( + author=request.user, status=Course.DRAFT + ) if pk: self.object = get_object_or_404(Course, pk=pk) elif drafts.exists(): @@ -175,9 +177,7 @@ class CourseView(DetailView): def get(self, request, *args, **kwargs): response = super().get(request, *args, **kwargs) - if (self.object.status != Course.PUBLISHED and - (request.user.role not in [User.AUTHOR_ROLE, User.ADMIN_ROLE] or - self.object.author != request.user)): + if (self.object.status != Course.PUBLISHED and request.user.role not in [User.AUTHOR_ROLE, User.ADMIN_ROLE]) or self.object.author != request.user: raise Http404 return response From c6ab2c0772a927cb03b39e85eac2dcdb9006896c Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Thu, 15 Feb 2018 17:24:25 +0300 Subject: [PATCH 18/21] Fix user perms --- apps/course/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/course/views.py b/apps/course/views.py index 7431cda4..2d409cf6 100644 --- a/apps/course/views.py +++ b/apps/course/views.py @@ -177,7 +177,7 @@ class CourseView(DetailView): def get(self, request, *args, **kwargs): response = super().get(request, *args, **kwargs) - if (self.object.status != Course.PUBLISHED and request.user.role not in [User.AUTHOR_ROLE, User.ADMIN_ROLE]) or self.object.author != request.user: + if (self.object.status != Course.PUBLISHED and request.user.role != User.ADMIN_ROLE) or (self.object.status != Course.PUBLISHED and request.user.role != User.AUTHOR_ROLE and self.object.author != request.user): raise Http404 return response From 577a12164c827de0e01eacf80fc3841f2c061836 Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Thu, 15 Feb 2018 17:27:02 +0300 Subject: [PATCH 19/21] Allow any view course --- apps/course/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/course/views.py b/apps/course/views.py index 2d409cf6..cb85918a 100644 --- a/apps/course/views.py +++ b/apps/course/views.py @@ -169,7 +169,7 @@ class CourseEditView(TemplateView): return context -@method_decorator(login_required, name='dispatch') +# @method_decorator(login_required, name='dispatch') class CourseView(DetailView): model = Course context_object_name = 'course' From e1165a710c199008b17f28e1e84fa218189f6734 Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Thu, 15 Feb 2018 17:38:14 +0300 Subject: [PATCH 20/21] Fix user perms --- apps/course/views.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/course/views.py b/apps/course/views.py index cb85918a..01c3ea95 100644 --- a/apps/course/views.py +++ b/apps/course/views.py @@ -177,10 +177,13 @@ class CourseView(DetailView): def get(self, request, *args, **kwargs): response = super().get(request, *args, **kwargs) - if (self.object.status != Course.PUBLISHED and request.user.role != User.ADMIN_ROLE) or (self.object.status != Course.PUBLISHED and request.user.role != User.AUTHOR_ROLE and self.object.author != request.user): + if (not request.user.is_authenticated and self.object.status != Course.PUBLISHED): raise Http404 return response + # ((self.object.status != Course.PUBLISHED and request.user.role != User.ADMIN_ROLE) or + # (self.object.status != Course.PUBLISHED and request.user.role != User.AUTHOR_ROLE and self.object.author != request.user)): + def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['next'] = self.request.GET.get('next', None) From 502d087be793beb27ed925eff0792489a795fc41 Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Thu, 15 Feb 2018 18:00:07 +0300 Subject: [PATCH 21/21] Fix dublication --- api/v1/serializers/mixins.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/api/v1/serializers/mixins.py b/api/v1/serializers/mixins.py index e709002e..71dd2029 100644 --- a/api/v1/serializers/mixins.py +++ b/api/v1/serializers/mixins.py @@ -85,10 +85,15 @@ class DispatchContentMixin(object): g.save() if 'images' in cdata: for image in cdata['images']: - gi = GalleryImage.objects.create( - gallery=g, - img=ImageObject.objects.get(id=image['img']) - ) + if 'id' in image and image['id']: + gi = GalleryImage.objects.get(id=image['id']) + gi.img = ImageObject.objects.get(id=image['img']) + gi.save() + else: + gi = GalleryImage.objects.create( + gallery=g, + img=ImageObject.objects.get(id=image['img']) + ) else: g = Gallery.objects.create( course=course, @@ -97,10 +102,15 @@ class DispatchContentMixin(object): ) if 'images' in cdata: for image in cdata['images']: - gi = GalleryImage.objects.create( - gallery=g, - img=ImageObject.objects.get(id=image['img']), - ) + if 'id' in image and image['id']: + gi = GalleryImage.objects.get(id=image['id']) + gi.img = ImageObject.objects.get(id=image['img']) + gi.save() + else: + gi = GalleryImage.objects.create( + gallery=g, + img=ImageObject.objects.get(id=image['img']) + ) class DispatchMaterialMixin(object):