ernestophone.ens.fr/pads/views.py

42 lines
1.2 KiB
Python
Raw Normal View History

from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import HttpResponseRedirect
2018-01-04 23:33:31 +01:00
from django.urls import reverse_lazy
from django.utils import timezone
from django.views.generic import CreateView, DeleteView, ListView, UpdateView
2021-04-29 00:27:33 +02:00
2021-10-23 11:16:07 +02:00
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"
2021-10-23 11:16:07 +02:00
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)
2021-10-23 11:16:07 +02:00
class PadUpdate(ChefEventRequiredMixin, UpdateView):
model = Pad
fields = ["nom", "url"]
template_name = "pads/update.html"
success_url = reverse_lazy("pads:list")
2021-10-23 11:16:07 +02:00
class PadDelete(ChefEventRequiredMixin, DeleteView):
model = Pad
template_name = "pads/delete.html"
success_url = reverse_lazy("pads:list")