ernestophone.ens.fr/actu/views.py

38 lines
1.1 KiB
Python
Raw Normal View History

2021-04-29 00:27:33 +02:00
from django.http import HttpResponseRedirect
from django.urls import reverse_lazy
2021-04-29 00:27:33 +02:00
from django.views.generic import CreateView, DeleteView, ListView, UpdateView
from actu.models import Actu
2021-04-29 00:27:33 +02:00
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
2021-04-29 00:27:33 +02:00
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
2021-04-29 00:27:33 +02:00
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")