38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
|
from django.shortcuts import render
|
||
|
from gestion.mixins import ChefRequiredMixin
|
||
|
from django.views.generic import CreateView, DeleteView, ListView, UpdateView
|
||
|
from django.urls import reverse_lazy
|
||
|
from actu.models import Actu
|
||
|
from django.http import HttpResponseRedirect
|
||
|
|
||
|
|
||
|
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")
|