Commit 635a5cd4 authored by Борис Ким's avatar Борис Ким

Добавил миксин PermissionRequired для вьюх

parent c97964de
......@@ -12,12 +12,10 @@
<a class="p-2" href="{% url 'webapp:course_edit' course.id %}"> <i class="fas fa-edit"></i> </a>
<a class="p-2" href="{% url 'webapp:course_delete' course.id %}"> <i class="fas fa-trash-alt"></i> </a>
</div>
<div class="card-body" style="height: 150px;">
<h5 class="card-title"> {{course.title}} </h5>
<p class="card-text"> {{course.description}} </p>
</div>
<div class="card-buttons" style="text-align: center;">
<a class="btn btn-primary p-2" href="{% url 'webapp:course_detail' course.id %}"> See more <i class="fas fa-eye"></i> </a>
<div class="card-body" style="height: 200px;">
<a class="card-title" href="{% url 'webapp:course_detail' course.id %}"> <h5>{{course.title}}</h5> </a>
<p class="card-text"> {{ course.description|truncatewords:30 }} </p>
<p class="card-text"> <b>Teacher:</b> {{course.teacher}} </p>
</div>
</div>
</div>
......
......@@ -30,7 +30,7 @@
</div>
<div class="card-body text-dark">
<h5 class="card-title">Topic: {{ class.title }} </h5>
<p class="card-text"> Description: {{ class.description|truncatewords:30 }} </p>
<p class="card-text"> Description: {{ class.description }} </p>
{{ class.file }}
<hr>
<p> <b>Created at:</b> {{ class.created_at }} - <b>by:</b> {{ course.teacher }}</p>
......
from django.shortcuts import get_object_or_404, redirect
from django.urls.base import reverse, reverse_lazy
from django.views.generic import CreateView, DeleteView, UpdateView
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin
from webapp.models import Class, Course
from webapp.forms import ClassForm
class CreateClassView(LoginRequiredMixin ,CreateView):
class CreateClassView(LoginRequiredMixin, PermissionRequiredMixin, CreateView):
model = Class
fields = ['title', 'description', 'file']
template_name = 'courses/create.html'
permission_required = 'webapp.add_class'
def form_valid(self, form):
course_pk = self.kwargs.get('pk')
......
......@@ -3,17 +3,18 @@ from django.shortcuts import redirect
from django.urls.base import reverse_lazy
from django.views.generic import ListView, CreateView, DetailView, DeleteView
from django.views.generic import UpdateView
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin
from webapp.models import Course
from webapp.forms import CourseForm
class CourseCreateView(LoginRequiredMixin, CreateView):
class CourseCreateView(LoginRequiredMixin, PermissionRequiredMixin, CreateView):
template_name = 'courses/create.html'
form_class = CourseForm
model = Course
pk_url_kwarg = 'project_pk'
permission_required = 'webapp.add_course'
def get_form(self, form_class=None):
form = super().get_form()
......@@ -27,20 +28,23 @@ class CoursesListView(ListView):
paginate_by = 6
class CourseDetailView(LoginRequiredMixin, DetailView):
class CourseDetailView(LoginRequiredMixin, PermissionRequiredMixin, DetailView):
model = Course
template_name = 'courses/detail.html'
pk_url_kwarg = 'course_pk'
permission_required = 'webapp.view_course'
class CourseDeleteView(LoginRequiredMixin, DeleteView):
class CourseDeleteView(LoginRequiredMixin, PermissionRequiredMixin, DeleteView):
model = Course
template_name = 'courses/delete.html'
success_url = reverse_lazy('webapp:courses_list')
permission_required = 'webapp.delete_course'
class CourseEditView(LoginRequiredMixin, UpdateView):
class CourseEditView(LoginRequiredMixin, PermissionRequiredMixin, UpdateView):
model = Course
fields = ['title', 'description', 'start_date']
template_name = 'courses/edit.html'
permission_required = 'webapp.change_course'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment