From 548cc16ee3ec58977be42496a1bfc84519581964 Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Wed, 11 Apr 2018 11:02:19 +0300 Subject: [PATCH] Fix perms for LiveLessonsView & LiveLessonEditView --- apps/school/templates/school/lesson.html | 142 +++++++++++++++++++++++ apps/school/views.py | 13 ++- 2 files changed, 152 insertions(+), 3 deletions(-) create mode 100644 apps/school/templates/school/lesson.html diff --git a/apps/school/templates/school/lesson.html b/apps/school/templates/school/lesson.html new file mode 100644 index 00000000..9150710d --- /dev/null +++ b/apps/school/templates/school/lesson.html @@ -0,0 +1,142 @@ +{% extends "templates/lilcity/index.html" %} +{% load static %} +{% block title %}{{ lesson.title }} - {{ block.super }}{% endblock title %} + +{% block content %} +
+
+ +
+
{{ lesson.title }}
+
{{ lesson.short_description }}
+ {% comment %} + {% if lesson.cover %} + + {% else %} + + {% endif %} + + + + {% endcomment %} +
+
+
+{% for content in lesson.content.all %} + + {% with template="course/content/"|add:content.ctype|add:".html" %} + {% include template %} + {% endwith %} + +{% endfor %} +{% comment %}
+
+
Примеры техники
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
{% endcomment %} +
+
+
Задавайте вопросы:
+
+ {% if request.user.is_authenticated %} +
+
+ +
+
+
+ +
+ +
+
+ {% else %} +
Только зарегистрированные пользователи могут оставлять комментарии.
+ {% endif %} +
+ {% include "./blocks/comments.html" with object=lesson %} +
+
+
+
+
+
+ +
+
+{% endblock content %} diff --git a/apps/school/views.py b/apps/school/views.py index d367a6ed..b33f126e 100644 --- a/apps/school/views.py +++ b/apps/school/views.py @@ -1,4 +1,6 @@ +from django.contrib.auth.decorators import login_required from django.shortcuts import get_object_or_404 +from django.utils.decorators import method_decorator from django.views.generic import ListView, UpdateView, TemplateView from .models import LiveLesson @@ -8,18 +10,23 @@ class LiveLessonsView(ListView): model = LiveLesson template_name = 'school/livelessons_list.html' + def get(self, request, pk=None): + if request.user.role not in [User.ADMIN_ROLE, User.TEACHER_ROLE]: + raise Http404 + return super().get(request) + -# @method_decorator(login_required, name='dispatch') +@method_decorator(login_required, name='dispatch') class LiveLessonEditView(TemplateView): template_name = 'course/course_edit.html' def get(self, request, pk=None): + if request.user.role not in [User.ADMIN_ROLE, User.TEACHER_ROLE]: + raise Http404 if pk: self.object = get_object_or_404(LiveLesson, pk=pk) else: self.object = LiveLesson.objects.create() - # if request.user != self.object.author and request.user.role not in [User.ADMIN_ROLE, User.AUTHOR_ROLE]: - # raise Http404 return super().get(request) def get_context_data(self):