ernestophone.ens.fr/pads/views.py

42 lines
1.1 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
from gestion.mixins import ChefRequiredMixin
from pads.models import Pad
class PadList(LoginRequiredMixin, ListView):
model = Pad
context_object_name = "pads"
ordering = ["-date"]
template_name = "pads/list.html"
class PadCreate(ChefRequiredMixin, 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(ChefRequiredMixin, UpdateView):
model = Pad
fields = ["nom", "url"]
template_name = "pads/update.html"
success_url = reverse_lazy("pads:list")
class PadDelete(ChefRequiredMixin, DeleteView):
model = Pad
template_name = "pads/delete.html"
success_url = reverse_lazy("pads:list")