diff --git a/api/v1/serializers/course.py b/api/v1/serializers/course.py index fecd2b3a..551830ad 100644 --- a/api/v1/serializers/course.py +++ b/api/v1/serializers/course.py @@ -137,6 +137,7 @@ class CourseCreateSerializer(DispatchContentMixin, 'from_author', 'cover', 'price', + 'age', 'is_infinite', 'deferred_start_at', 'category', @@ -288,6 +289,7 @@ class CourseSerializer(serializers.ModelSerializer): 'from_author', 'cover', 'price', + 'age', 'is_infinite', 'deferred_start_at', 'category', diff --git a/apps/course/filters.py b/apps/course/filters.py index 6e4e873e..cfecd0a0 100644 --- a/apps/course/filters.py +++ b/apps/course/filters.py @@ -5,7 +5,8 @@ from .models import Course class CourseFilter(django_filters.FilterSet): category = django_filters.CharFilter(field_name='category') + age = django_filters.ChoiceFilter(field_name='age', choices=Course.AGE_CHOICES) class Meta: model = Course - fields = ['category'] + fields = ['category', 'age'] diff --git a/apps/course/migrations/0044_course_age.py b/apps/course/migrations/0044_course_age.py new file mode 100644 index 00000000..a45fd5eb --- /dev/null +++ b/apps/course/migrations/0044_course_age.py @@ -0,0 +1,18 @@ +# Generated by Django 2.0.6 on 2018-09-07 00:20 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('course', '0043_auto_20180824_2132'), + ] + + operations = [ + migrations.AddField( + model_name='course', + name='age', + field=models.SmallIntegerField(choices=[(0, 'Любой возраст'), (1, 'до 5'), (2, '5-7'), (3, '7-9'), (4, '9-12'), (5, '12-15'), (6, '15-18'), (7, 'от 18')], default=0), + ), + ] diff --git a/apps/course/models.py b/apps/course/models.py index 41dcfe29..c7927600 100644 --- a/apps/course/models.py +++ b/apps/course/models.py @@ -50,6 +50,23 @@ class Course(BaseModel, DeactivatedMixin): (ARCHIVED, 'Archived'), (DENIED, 'Denied') ) + AGE_LT5 = 1 + AGE_57 = 2 + AGE_79 = 3 + AGE_912 = 4 + AGE_1215 = 5 + AGE_1518 = 6 + AGE_GT18 = 7 + AGE_CHOICES = ( + (0, 'Любой возраст'), + (AGE_LT5, 'до 5'), + (AGE_57, '5-7'), + (AGE_79, '7-9'), + (AGE_912, '9-12'), + (AGE_1215, '12-15'), + (AGE_1518, '15-18'), + (AGE_GT18, 'от 18'), + ) slug = models.SlugField( allow_unicode=True, null=True, blank=True, max_length=100, unique=True, db_index=True, @@ -73,6 +90,7 @@ class Course(BaseModel, DeactivatedMixin): 'Цена курса', help_text='Если цена не выставлена, то курс бесплатный', max_digits=10, decimal_places=2, null=True, blank=True ) + age = models.SmallIntegerField(choices=AGE_CHOICES, default=0) is_infinite = models.BooleanField(default=False) deferred_start_at = models.DateTimeField( 'Отложенный запуск курса', help_text='Заполнить если курс отложенный', diff --git a/apps/course/templates/course/_items.html b/apps/course/templates/course/_items.html index b4356f2b..f27bd326 100644 --- a/apps/course/templates/course/_items.html +++ b/apps/course/templates/course/_items.html @@ -54,7 +54,7 @@ {% endif %} {{ course.title }} -
{{ course.short_description }} +
{{ course.short_description | safe | linebreaks | truncatechars_html:300 }}
diff --git a/apps/course/templates/course/course.html b/apps/course/templates/course/course.html index e031fe23..2502b9a0 100644 --- a/apps/course/templates/course/course.html +++ b/apps/course/templates/course/course.html @@ -4,14 +4,14 @@ {% load rupluralize from plural %} {% block title %}{{ course.title }} - {{ block.super }}{% endblock title %} {% comment %} seo tags {% endcomment %} -{% block description %}{{ course.short_description }}{% endblock description%} +{% block description %}{{ course.short_description | striptags }}{% 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 and course.cover.image %} {% block ogimage %}http://{{request.META.HTTP_HOST}}{% if course.cover %}{{ course.cover.image.url }}{% else %}{% static 'img/og_courses.jpg' %}{% endif %}{% endblock ogimage %} {% endif %} -{% block ogdescription %}{{ course.short_description }}{% endblock ogdescription %} +{% block ogdescription %}{{ course.short_description | striptags }}{% endblock ogdescription %} {% block content %}
@@ -25,6 +25,9 @@
Вернуться
+ {% if has_full_access %} + Редактировать + {% endif %} {% if course.author != request.user and not paid and course.price %} @@ -25,6 +25,9 @@
Вернуться
+ {% if has_full_access %} + Редактировать + {% endif %} {% if not paid and course.price and not has_full_access %} Содержание курса
{% for lesson in lessons %} - {% if course.author == request.user or request.user.role >= request.user.TEACHER_ROLE or paid %} - - {% else %} - - {% endif %}
+
-
-
{{ forloop.counter }}. {{ lesson.title }}
-
{{ lesson.short_description | truncatechars_html:800 | safe }}
- Перейти к уроку -
- {% endfor %}
diff --git a/apps/course/templates/course/courses.html b/apps/course/templates/course/courses.html index 8f6f57d2..f56279f6 100644 --- a/apps/course/templates/course/courses.html +++ b/apps/course/templates/course/courses.html @@ -23,15 +23,32 @@
Категории
-
-
Все курсы
+
+
Все категории
{% category_items category %}
+
+
+
+
{% if age_name %}{{ age_name }}{% else %}Возраст{% endif %}
+
+
+
Любой возраст
+
+ {% for a in ages %} +
+
{{ a.1 }}
+
+ {% endfor %} +
+
+
+
@@ -40,7 +57,7 @@
{% if page_obj.has_next %} - + {% endif %}
diff --git a/apps/course/templates/course/inclusion/category_items.html b/apps/course/templates/course/inclusion/category_items.html index 5549ffa4..9ebd98ed 100644 --- a/apps/course/templates/course/inclusion/category_items.html +++ b/apps/course/templates/course/inclusion/category_items.html @@ -1,6 +1,6 @@ {% for cat in category_items %} -
+
{{ cat.title }}
-{% endfor %} \ No newline at end of file +{% endfor %} diff --git a/apps/course/templates/course/lesson.html b/apps/course/templates/course/lesson.html index 990f4e35..547bb402 100644 --- a/apps/course/templates/course/lesson.html +++ b/apps/course/templates/course/lesson.html @@ -31,15 +31,9 @@
-
-
- -
-
{{ lesson.title }}
-
{{ lesson.short_description | linebreaks }}
+
{{ lesson.short_description | safe | linebreaks }}
{% if lesson.author.photo %} @@ -60,6 +54,12 @@
+
+
+ +
+
diff --git a/apps/course/views.py b/apps/course/views.py index 857a57d0..6b578923 100644 --- a/apps/course/views.py +++ b/apps/course/views.py @@ -167,9 +167,8 @@ class CourseEditView(TemplateView): self.object = Course.objects.create( author=request.user, ) - #TODO - #if (request.user != self.object.author and request.user.role < User.AUTHOR_ROLE) or request.user.role != User.ADMIN_ROLE: - # raise Http404 + if request.user != self.object.author and request.user.role != User.ADMIN_ROLE: + raise Http404 return super().get(request) def get_context_data(self): @@ -283,6 +282,14 @@ class CoursesView(ListView): filtered = CourseFilter(self.request.GET) context.update(filtered.data) context['course_items'] = Course.shuffle(context.get('course_items')) + context['ages'] = Course.AGE_CHOICES[1:] + age = context.get('age') + if age and age[0]: + age = int(age[0]) + context['age'] = [age] + context['age_name'] = dict(Course.AGE_CHOICES).get(age, '') + else: + context['age_name'] = '' return context def get_template_names(self): diff --git a/apps/school/templates/school/livelesson_detail.html b/apps/school/templates/school/livelesson_detail.html index 96db3a06..d3e5c5af 100644 --- a/apps/school/templates/school/livelesson_detail.html +++ b/apps/school/templates/school/livelesson_detail.html @@ -14,7 +14,7 @@
{{ livelesson.title }}
-
{{ livelesson.short_description | linebreaks }}
+
{{ livelesson.short_description | safe | linebreaks }}
{% if livelesson.stream_index %}