Désactive l'upload selon les settings.
This commit is contained in:
parent
382247e2ce
commit
34527049b0
2 changed files with 19 additions and 9 deletions
|
@ -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)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
{% load static %}
|
||||
{% load bootstrap4 %}
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
|
@ -41,14 +42,7 @@ h1.site-title
|
|||
<main role="main" class="container">
|
||||
<br/>
|
||||
<br/>
|
||||
{% for message in messages %}
|
||||
<div class="alert alert-{{message.tags}} alert-dismissible fade show" role="alert">
|
||||
{{message}}
|
||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% bootstrap_messages %}
|
||||
{% block content %}{% endblock %}
|
||||
</main>
|
||||
<br/>
|
||||
|
|
Loading…
Reference in a new issue