ernestophone.ens.fr/pads/views.py
Lucie Galland d7fd5e5537 new respos
2021-10-23 11:16:07 +02:00

41 lines
1.2 KiB
Python

from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import HttpResponseRedirect
from django.urls import reverse_lazy
from django.utils import timezone
from django.views.generic import CreateView, DeleteView, ListView, UpdateView
from gestion.mixins import ChefRequiredMixin, ChefEventRequiredMixin
from pads.models import Pad
class PadList(LoginRequiredMixin, ListView):
model = Pad
context_object_name = "pads"
ordering = ["-date"]
template_name = "pads/list.html"
class PadCreate(ChefEventRequiredMixin, CreateView):
model = Pad
fields = ["nom", "url"]
template_name = "pads/create.html"
success_url = reverse_lazy("pads:list")
def form_valid(self, form):
pad = form.save(commit=False)
pad.date = timezone.now()
pad.save()
return HttpResponseRedirect(self.success_url)
class PadUpdate(ChefEventRequiredMixin, UpdateView):
model = Pad
fields = ["nom", "url"]
template_name = "pads/update.html"
success_url = reverse_lazy("pads:list")
class PadDelete(ChefEventRequiredMixin, DeleteView):
model = Pad
template_name = "pads/delete.html"
success_url = reverse_lazy("pads:list")