from django.contrib.auth.decorators import login_required from django.shortcuts import render from django.urls import reverse_lazy from django.views.generic import UpdateView, DeleteView from django.utils.decorators import method_decorator from datetime import date from pads.models import Pad from pads.forms import PadForm from partitions.decorators import chef_required @login_required def liste_pads(request): pads = Pad.objects.all().order_by("-date") return render(request, "pads/liste.html", locals()) @chef_required def add_pad(request): if request.method == "POST": form = PadForm(request.POST) if form.is_valid(): obj = form.save(commit=False) obj.date = date.today() obj.save() envoi = True else: form = PadForm() return render(request, "pads/create.html", locals()) class PadUpdate(UpdateView): model = Pad template_name = "pads/update.html" success_url = reverse_lazy(liste_pads) form_class = PadForm @method_decorator(chef_required) def dispatch(self, *args, **kwargs): return super(PadUpdate, self).dispatch(*args, **kwargs) class PadDelete(DeleteView): model = Pad template_name = "pads/delete.html" success_url = reverse_lazy(liste_pads) @method_decorator(chef_required) def dispatch(self, *args, **kwargs): return super(PadDelete, self).dispatch(*args, **kwargs) # Create your views here.