ernestophone.ens.fr/pads/views.py

54 lines
1.4 KiB
Python
Raw Normal View History

from django.contrib.auth.decorators import login_required
from django.shortcuts import render
2018-01-04 23:33:31 +01:00
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)
2018-06-25 20:37:19 +02:00
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.