ernestophone.ens.fr/actu/views.py
2021-04-29 00:27:33 +02:00

37 lines
1.1 KiB
Python

from django.http import HttpResponseRedirect
from django.urls import reverse_lazy
from django.views.generic import CreateView, DeleteView, ListView, UpdateView
from actu.models import Actu
from gestion.mixins import ChefRequiredMixin
class ActuList(ChefRequiredMixin, ListView):
model = Actu
context_object_name = "actus"
template_name = "actu/actualité.html"
class ActuCreate(ChefRequiredMixin, CreateView):
model = Actu
fields = ["text", "order", "text_en"]
template_name = "actu/create_actu.html"
success_url = reverse_lazy("actu:liste")
def form_valid(self, form):
actu = form.save(commit=False)
actu.save()
return HttpResponseRedirect(self.success_url)
class ActuUpdate(ChefRequiredMixin, UpdateView):
model = Actu
fields = ["text", "order", "text_en"]
template_name = "actu/update_actu.html"
success_url = reverse_lazy("actu:liste")
class ActuDelete(ChefRequiredMixin, DeleteView):
model = Actu
template_name = "actu/delete_actu.html"
success_url = reverse_lazy("actu:liste")