2020-01-09 18:05:18 +01:00
|
|
|
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
|
2020-01-09 18:05:18 +01:00
|
|
|
from django.utils import timezone
|
|
|
|
from django.views.generic import CreateView, DeleteView, ListView, UpdateView
|
2021-04-29 00:27:33 +02:00
|
|
|
|
2020-01-09 18:05:18 +01:00
|
|
|
from gestion.mixins import ChefRequiredMixin
|
2016-06-21 00:33:32 +02:00
|
|
|
from pads.models import Pad
|
|
|
|
|
|
|
|
|
2020-01-09 18:05:18 +01:00
|
|
|
class PadList(LoginRequiredMixin, ListView):
|
|
|
|
model = Pad
|
|
|
|
context_object_name = "pads"
|
|
|
|
ordering = ["-date"]
|
|
|
|
template_name = "pads/list.html"
|
2016-07-14 01:58:52 +02:00
|
|
|
|
2016-06-21 00:33:32 +02:00
|
|
|
|
2020-01-09 18:05:18 +01:00
|
|
|
class PadCreate(ChefRequiredMixin, CreateView):
|
|
|
|
model = Pad
|
|
|
|
fields = ["nom", "url"]
|
|
|
|
template_name = "pads/create.html"
|
|
|
|
success_url = reverse_lazy("pads:list")
|
2016-07-14 01:58:52 +02:00
|
|
|
|
2020-01-09 18:05:18 +01:00
|
|
|
def form_valid(self, form):
|
|
|
|
pad = form.save(commit=False)
|
|
|
|
pad.date = timezone.now()
|
|
|
|
pad.save()
|
|
|
|
return HttpResponseRedirect(self.success_url)
|
2016-06-21 00:33:32 +02:00
|
|
|
|
2016-07-14 01:58:52 +02:00
|
|
|
|
2020-01-09 18:05:18 +01:00
|
|
|
class PadUpdate(ChefRequiredMixin, UpdateView):
|
2016-06-21 00:33:32 +02:00
|
|
|
model = Pad
|
2020-01-09 18:05:18 +01:00
|
|
|
fields = ["nom", "url"]
|
2016-07-14 01:58:52 +02:00
|
|
|
template_name = "pads/update.html"
|
2020-01-09 18:05:18 +01:00
|
|
|
success_url = reverse_lazy("pads:list")
|
2016-06-21 00:33:32 +02:00
|
|
|
|
|
|
|
|
2020-01-09 18:05:18 +01:00
|
|
|
class PadDelete(ChefRequiredMixin, DeleteView):
|
2016-06-21 00:33:32 +02:00
|
|
|
model = Pad
|
|
|
|
template_name = "pads/delete.html"
|
2020-01-09 18:05:18 +01:00
|
|
|
success_url = reverse_lazy("pads:list")
|