ernestophone.ens.fr/trombonoscope/views.py

41 lines
1.4 KiB
Python
Raw Normal View History

2021-04-29 00:33:58 +02:00
from django.contrib.auth.mixins import LoginRequiredMixin
2021-04-29 00:27:33 +02:00
from django.shortcuts import redirect, render
2021-04-29 00:33:58 +02:00
from django.views.generic import TemplateView
2021-04-29 00:27:33 +02:00
from gestion.models import ErnestoUser
from trombonoscope.forms import ChangeTrombonoscope
2021-04-29 00:27:33 +02:00
class ChangeTrombonoscope(LoginRequiredMixin, TemplateView):
form_class = ChangeTrombonoscope
template_name = "trombonoscope/changetrombonoscope.html"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
form = self.form_class(instance=self.request.user.profile)
2021-04-29 00:33:58 +02:00
context["form"] = form
2021-04-29 00:27:33 +02:00
return context
2021-04-29 00:27:33 +02:00
def post(self, request, *args, **kwargs):
2021-04-29 00:33:58 +02:00
form = self.form_class(
request.POST, request.FILES, instance=request.user.profile
)
if form.is_valid():
form.save()
2021-04-29 00:27:33 +02:00
return redirect("trombonoscope:view")
context = self.get_context_data()
2021-04-29 00:33:58 +02:00
context["form"] = form
2021-04-29 00:27:33 +02:00
return render(request, self.template_name, context)
class Trombonoscope(LoginRequiredMixin, TemplateView):
template_name = "trombonoscope/trombonoscope.html"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
2021-04-29 00:33:58 +02:00
context["trombonoscope_vieux"] = ErnestoUser.objects.filter(trombonoscope="o_v")
context["trombonoscope_actuel"] = ErnestoUser.objects.filter(
trombonoscope="o_a"
)
2021-04-29 00:27:33 +02:00
return context