Permission sur l'édition de contenu
This commit is contained in:
parent
46a0ff94b6
commit
8a4e51333e
1 changed files with 20 additions and 6 deletions
|
@ -1,6 +1,7 @@
|
||||||
from django.views import generic
|
from django.views import generic
|
||||||
from django.urls import reverse, reverse_lazy
|
from django.urls import reverse, reverse_lazy
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
|
from django.contrib.auth.mixins import PermissionRequiredMixin, LoginRequiredMixin
|
||||||
|
|
||||||
from .models import Content, Category
|
from .models import Content, Category
|
||||||
|
|
||||||
|
@ -24,11 +25,12 @@ class ContentCategoryList(generic.ListView):
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
class CreateCategory(generic.CreateView):
|
class CreateCategory(PermissionRequiredMixin, generic.CreateView):
|
||||||
"""Création de catégorie."""
|
"""Création de catégorie."""
|
||||||
model = Category
|
model = Category
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
template_name = "edit.html"
|
template_name = "edit.html"
|
||||||
|
permission_required = 'content.add_category'
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(generic.CreateView, self).get_context_data(**kwargs)
|
context = super(generic.CreateView, self).get_context_data(**kwargs)
|
||||||
|
@ -36,25 +38,27 @@ class CreateCategory(generic.CreateView):
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
class DeleteCategory(generic.DeleteView):
|
class DeleteCategory(PermissionRequiredMixin, generic.DeleteView):
|
||||||
"""Suppression de catégorie"""
|
"""Suppression de catégorie"""
|
||||||
model = Category
|
model = Category
|
||||||
success_url = reverse_lazy('settings:index')
|
success_url = reverse_lazy('settings:index')
|
||||||
template_name = "confirm_delete.html"
|
template_name = "confirm_delete.html"
|
||||||
|
permission_required = 'content.del_category'
|
||||||
|
|
||||||
|
|
||||||
class EditCategory(generic.UpdateView):
|
class EditCategory(PermissionRequiredMixin, generic.UpdateView):
|
||||||
"""Édition de catégorie."""
|
"""Édition de catégorie."""
|
||||||
model = Category
|
model = Category
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
template_name = "edit.html"
|
template_name = "edit.html"
|
||||||
|
permission_required = 'content.change_category'
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(generic.UpdateView, self).get_context_data(**kwargs)
|
context = super(generic.UpdateView, self).get_context_data(**kwargs)
|
||||||
context['title'] = "Édition de " + self.object.name
|
context['title'] = "Édition de " + self.object.name
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
class CreateContent(generic.CreateView):
|
class CreateContent(PermissionRequiredMixin, generic.CreateView):
|
||||||
"""Création de contenu."""
|
"""Création de contenu."""
|
||||||
model = Content
|
model = Content
|
||||||
fields = [
|
fields = [
|
||||||
|
@ -68,6 +72,9 @@ class CreateContent(generic.CreateView):
|
||||||
'validate' : 'Envoyer'
|
'validate' : 'Envoyer'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def has_permission(self):
|
||||||
|
return self.request.user.has_perm('users.manage_'+str(self.request.user.userprofile.school.group.pk))
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
return self.object.school_owner.get_absolute_url()
|
return self.object.school_owner.get_absolute_url()
|
||||||
|
|
||||||
|
@ -77,7 +84,7 @@ class CreateContent(generic.CreateView):
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
class DeleteContent(generic.DeleteView):
|
class DeleteContent(PermissionRequiredMixin, generic.DeleteView):
|
||||||
"""Suppression de contenu"""
|
"""Suppression de contenu"""
|
||||||
model = Content
|
model = Content
|
||||||
template_name = "confirm_delete.html"
|
template_name = "confirm_delete.html"
|
||||||
|
@ -85,8 +92,12 @@ class DeleteContent(generic.DeleteView):
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
return self.object.school_owner.get_absolute_url()
|
return self.object.school_owner.get_absolute_url()
|
||||||
|
|
||||||
|
def has_permission(self):
|
||||||
|
school = get_object_or_404(Content, pk=self.kwargs['pk']).school_owner
|
||||||
|
return self.request.user.has_perm('users.manage_'+str(school.group.pk))
|
||||||
|
|
||||||
class EditContent(generic.UpdateView):
|
|
||||||
|
class EditContent(PermissionRequiredMixin, generic.UpdateView):
|
||||||
"""Édition d'un contenu"""
|
"""Édition d'un contenu"""
|
||||||
model = Content
|
model = Content
|
||||||
template_name = "edit.html"
|
template_name = "edit.html"
|
||||||
|
@ -104,3 +115,6 @@ class EditContent(generic.UpdateView):
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
return self.object.school_owner.get_absolute_url()
|
return self.object.school_owner.get_absolute_url()
|
||||||
|
|
||||||
|
def has_permission(self):
|
||||||
|
school = get_object_or_404(Content, pk=self.kwargs['pk']).school_owner
|
||||||
|
return self.request.user.has_perm('users.manage_'+str(school.group.pk))
|
||||||
|
|
Loading…
Reference in a new issue