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) 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): diff --git a/apps/course/templates/course/_items.html b/apps/course/templates/course/_items.html index 407526ca..5d3642e0 100644 --- a/apps/course/templates/course/_items.html +++ b/apps/course/templates/course/_items.html @@ -8,9 +8,9 @@ > {% if course.cover %} - + {% else %} - + {% endif %}
Подробнее
{% if course.is_featured %} @@ -22,6 +22,17 @@
{% endif %} + {% if course.status == 1 %} +
+
КУРС ПРОХОДИТ МОДЕРАЦИЮ
+
+
+ {% elif course.status == 0 %} +
+
ЧЕРНОВИК
+
+
+ {% endif %}
- + Описание курса + {% if request.user.role == request.user.AUTHOR_ROLE or request.user.role == request.user.ADMIN_ROLE %} + УРОКИ + {% comment %} + + {% endcomment %} + + {% else %} + {% endif %}
{% if course.cover %} @@ -153,9 +163,9 @@
{{ course.deferred_start_at_humanize }}
{% else %} - + {% comment %} - + {% endcomment %} {% endif %}
@@ -231,11 +241,15 @@
Содержание курса
{% 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 %}
@@ -243,11 +257,15 @@
- {% endif %} + {% endif %} {% endcomment %}
{{ lesson.short_description | safe }}
-
+ {% if request.user.role == request.user.AUTHOR_ROLE or request.user.role == request.user.ADMIN_ROLE %} + + {% else %} +
+ {% endif %} {% endfor %}
{% comment %}
@@ -317,8 +335,8 @@
-
Как просто научиться рисовать простых персонажей.
-
Этот курс поможет детям узнать о том как из простых форм создавать веселый и харизматичных персонажей.
+
{{ course.title }}
+
{{ course.short_description }}
{% if course.author.photo %} 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/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/apps/course/templates/course/lesson.html b/apps/course/templates/course/lesson.html index 8c9080d4..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 dce54105..01c3ea95 100644 --- a/apps/course/views.py +++ b/apps/course/views.py @@ -141,12 +141,19 @@ 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' 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(): @@ -162,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' @@ -170,12 +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 not in [User.AUTHOR_ROLE, User.ADMIN_ROLE] or - 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) @@ -259,6 +267,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' 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() 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}}
diff --git a/apps/user/templates/user/profile.html b/apps/user/templates/user/profile.html index 0e094c31..9af22213 100644 --- a/apps/user/templates/user/profile.html +++ b/apps/user/templates/user/profile.html @@ -17,31 +17,31 @@
Изменить @@ -69,13 +71,13 @@ - + {% endcomment %}
@@ -92,7 +94,7 @@
-
+ {% comment %}
{% include "course/course_items.html" with course_items=pending %} @@ -105,7 +107,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..58927b26 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 @@ -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]) diff --git a/project/urls.py b/project/urls.py index 4b426d97..2df911b7 100644 --- a/project/urls.py +++ b/project/urls.py @@ -22,19 +22,25 @@ 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), path('auth/', include(('apps.auth.urls', 'lilcity'))), path('courses/', CoursesView.as_view(), name='courses'), + 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//like', likes, name='likes'), - path('course/create', CourseEditView.as_view(), name='course_create'), 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'), diff --git a/web/src/sass/_common.sass b/web/src/sass/_common.sass index 0363006f..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 @@ -2757,6 +2758,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