diff --git a/content/views.py b/content/views.py index c3cc25a..0548aef 100644 --- a/content/views.py +++ b/content/views.py @@ -1,9 +1,11 @@ from django.views import generic from django.urls import reverse, reverse_lazy -from django.shortcuts import get_object_or_404 +from django.shortcuts import get_object_or_404, redirect from django.contrib.auth.mixins import PermissionRequiredMixin, LoginRequiredMixin +from django.contrib import messages from .models import Content, Category +from settings.models import SiteSettings class ContentCategoryList(generic.ListView): @@ -83,6 +85,13 @@ class CreateContent(PermissionRequiredMixin, generic.CreateView): r = super().form_valid(form) return r + def dispatch(self, request, *args, **kwargs): + settings,_ = SiteSettings.objects.get_or_create() + if not settings.allow_upload : + messages.error(request, "Le téléversement de contenu n'est pas autorisé actuellement.") + return redirect(reverse("home")) + return super().dispatch(request, *args, **kwargs) + class DeleteContent(PermissionRequiredMixin, generic.DeleteView): """Suppression de contenu""" @@ -118,3 +127,10 @@ class EditContent(PermissionRequiredMixin, generic.UpdateView): 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)) + + def dispatch(self, request, *args, **kwargs): + settings,_ = SiteSettings.objects.get_or_create() + if not settings.allow_upload : + messages.error(request, "Le téléversement de contenu n'est pas autorisé actuellement.") + return redirect(reverse("home")) + return super().dispatch(request, *args, **kwargs) diff --git a/templates/base.html b/templates/base.html index 270fe19..1aef4ac 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,4 +1,5 @@ {% load static %} +{% load bootstrap4 %}
@@ -41,14 +42,7 @@ h1.site-title