2016-06-21 00:33:32 +02:00
|
|
|
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
|
2016-06-21 00:33:32 +02:00
|
|
|
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
|
|
|
|
|
2016-07-14 01:58:52 +02:00
|
|
|
|
2016-06-21 00:33:32 +02:00
|
|
|
@login_required
|
|
|
|
def liste_pads(request):
|
|
|
|
pads = Pad.objects.all().order_by("-date")
|
|
|
|
return render(request, "pads/liste.html", locals())
|
|
|
|
|
2016-07-14 01:58:52 +02:00
|
|
|
|
2016-06-21 00:33:32 +02:00
|
|
|
@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())
|
|
|
|
|
2016-07-14 01:58:52 +02:00
|
|
|
|
2016-06-21 00:33:32 +02:00
|
|
|
class PadUpdate(UpdateView):
|
|
|
|
model = Pad
|
2016-07-14 01:58:52 +02:00
|
|
|
template_name = "pads/update.html"
|
|
|
|
success_url = reverse_lazy(liste_pads)
|
2018-06-25 20:37:19 +02:00
|
|
|
form_class = PadForm
|
2016-06-21 00:33:32 +02:00
|
|
|
|
|
|
|
@method_decorator(chef_required)
|
|
|
|
def dispatch(self, *args, **kwargs):
|
|
|
|
return super(PadUpdate, self).dispatch(*args, **kwargs)
|
|
|
|
|
2016-07-14 01:58:52 +02:00
|
|
|
|
2016-06-21 00:33:32 +02:00
|
|
|
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.
|