black + isort

This commit is contained in:
Lucie Galland 2021-04-29 00:33:58 +02:00
parent 6ba168d286
commit 0fbec31d14
10 changed files with 181 additions and 196 deletions

View file

@ -25,15 +25,12 @@ from gestion import views as gestion_views
urlpatterns = [] urlpatterns = []
urlpatterns += i18n_patterns( urlpatterns += i18n_patterns(
path("", gestion_views.Home.as_view(), name="home"), path("", gestion_views.Home.as_view(), name="home"),
path("registration", gestion_views.Inscription.as_view(), path("registration", gestion_views.Inscription.as_view(), name="registration"),
name="registration"),
path("change", gestion_views.ChangeMembre.as_view(), name="change_membre"), path("change", gestion_views.ChangeMembre.as_view(), name="change_membre"),
path("password", gestion_views.ChangePassword.as_view(), path("password", gestion_views.ChangePassword.as_view(), name="change_password"),
name="change_password"),
path("thanks", gestion_views.Thanks.as_view(), name="thanks"), path("thanks", gestion_views.Thanks.as_view(), name="thanks"),
path("changename", gestion_views.ChangeName.as_view(), name="change-doodle-name"), path("changename", gestion_views.ChangeName.as_view(), name="change-doodle-name"),
path("logout", auth_views.LogoutView.as_view(next_page="home"), path("logout", auth_views.LogoutView.as_view(next_page="home"), name="logout"),
name="logout"),
path("login", gestion_views.MyLoginView.as_view(), name="login"), path("login", gestion_views.MyLoginView.as_view(), name="login"),
path("agenda/", include("calendrier.urls", namespace="calendrier")), path("agenda/", include("calendrier.urls", namespace="calendrier")),
path("partitions/", include("partitions.urls")), path("partitions/", include("partitions.urls")),

View file

@ -10,10 +10,8 @@ urlpatterns = [
path("new", views.CreateEvent.as_view(), name="create_event"), path("new", views.CreateEvent.as_view(), name="create_event"),
path("edition/<int:pk>", EventUpdate.as_view(), name="edit_event"), path("edition/<int:pk>", EventUpdate.as_view(), name="edit_event"),
path("supprimer/<int:pk>", EventDelete.as_view(), name="delete_event"), path("supprimer/<int:pk>", EventDelete.as_view(), name="delete_event"),
path("<int:id>/changename", views.ChangeName.as_view(), path("<int:id>/changename", views.ChangeName.as_view(), name="change-doodle-name"),
name="change-doodle-name"),
path("<int:id>/reponse", views.ReponseEvent.as_view(), name="reponse"), path("<int:id>/reponse", views.ReponseEvent.as_view(), name="reponse"),
path("<int:pYear>/<int:pMonth>", views.Calendar.as_view(), path("<int:pYear>/<int:pMonth>", views.Calendar.as_view(), name="view-month"),
name="view-month"),
path("<int:id>", views.ViewEvent.as_view(), name="view-event"), path("<int:id>", views.ViewEvent.as_view(), name="view-event"),
] ]

View file

@ -4,21 +4,20 @@ from calendar import monthrange
from collections import defaultdict from collections import defaultdict
from datetime import date, datetime from datetime import date, datetime
from django.contrib.auth.mixins import LoginRequiredMixin
from django.db.models import Q from django.db.models import Q
from django.shortcuts import get_object_or_404, redirect, render from django.shortcuts import get_object_or_404, redirect, render
from django.urls import reverse, reverse_lazy from django.urls import reverse, reverse_lazy
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.views.generic import DeleteView, UpdateView from django.views.generic import DeleteView, TemplateView, UpdateView
from actu.models import Actu from actu.models import Actu
from calendrier.calend import EventCalendar from calendrier.calend import EventCalendar
from calendrier.forms import (ChangeDoodleName, EventForm, ModifEventForm, from calendrier.forms import (ChangeDoodleName, EventForm, ModifEventForm,
ParticipantsForm) ParticipantsForm)
from calendrier.models import Event, Participants from calendrier.models import Event, Participants
from gestion.models import Photo
from django.views.generic import TemplateView
from django.contrib.auth.mixins import LoginRequiredMixin
from gestion.mixins import ChefRequiredMixin from gestion.mixins import ChefRequiredMixin
from gestion.models import Photo
def generer(*args): def generer(*args):
@ -36,20 +35,19 @@ class Agenda(TemplateView):
def dispatch(self, request, *args, **kwargs): def dispatch(self, request, *args, **kwargs):
if request.user.is_authenticated: if request.user.is_authenticated:
return redirect('calendrier:home') return redirect("calendrier:home")
return super(Agenda, self).dispatch(request, *args, **kwargs) return super(Agenda, self).dispatch(request, *args, **kwargs)
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
lToday = datetime.today() lToday = datetime.today()
context['photo'] = Photo.objects.filter( context["photo"] = Photo.objects.filter(cat="liste").order_by("?").first()
cat="liste").order_by("?").first() context["events_a_venir"] = (
context['events_a_venir'] = (
Event.objects.filter(date__gte=lToday) Event.objects.filter(date__gte=lToday)
.exclude(calendrier__iexact="F") .exclude(calendrier__iexact="F")
.order_by("-date") .order_by("-date")
) )
context['events_passe'] = ( context["events_passe"] = (
Event.objects.filter(date__lt=lToday) Event.objects.filter(date__lt=lToday)
.filter(calendrier__iexact="H") .filter(calendrier__iexact="H")
.order_by("-date") .order_by("-date")
@ -62,11 +60,11 @@ class Calendar(LoginRequiredMixin, TemplateView):
@property @property
def pYear(self): def pYear(self):
return self.kwargs['pYear'] return self.kwargs["pYear"]
@property @property
def pMonth(self): def pMonth(self):
return self.kwargs['pMonth'] return self.kwargs["pMonth"]
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(Calendar, self).get_context_data(**kwargs) context = super(Calendar, self).get_context_data(**kwargs)
@ -76,8 +74,7 @@ class Calendar(LoginRequiredMixin, TemplateView):
lYear = int(self.pYear) lYear = int(self.pYear)
lMonth = int(self.pMonth) lMonth = int(self.pMonth)
lCalendarFromMonth = datetime(lYear, lMonth, 1) lCalendarFromMonth = datetime(lYear, lMonth, 1)
lCalendarToMonth = datetime(lYear, lMonth, lCalendarToMonth = datetime(lYear, lMonth, monthrange(lYear, lMonth)[1])
monthrange(lYear, lMonth)[1])
lEvents = Event.objects.filter( lEvents = Event.objects.filter(
date__gte=lCalendarFromMonth, date__lte=lCalendarToMonth date__gte=lCalendarFromMonth, date__lte=lCalendarToMonth
) )
@ -96,41 +93,33 @@ class Calendar(LoginRequiredMixin, TemplateView):
lYearBeforeThis = lYear - 1 lYearBeforeThis = lYear - 1
try: try:
events_a_venir_not_answered = Event.objects.filter( events_a_venir_not_answered = Event.objects.filter(
date__gte=lToday).exclude( date__gte=lToday
participants__participant=self.request.user.profile ).exclude(participants__participant=self.request.user.profile)
) events_a_venir_answered_yes = Event.objects.filter(date__gte=lToday).filter(
events_a_venir_answered_yes = Event.objects.filter(
date__gte=lToday).filter(
Q(participants__participant=self.request.user.profile) Q(participants__participant=self.request.user.profile)
& Q(participants__reponse="oui") & Q(participants__reponse="oui")
) )
events_a_venir_answered_no = Event.objects.filter( events_a_venir_answered_no = Event.objects.filter(date__gte=lToday).filter(
date__gte=lToday).filter(
Q(participants__participant=self.request.user.profile) Q(participants__participant=self.request.user.profile)
& Q(participants__reponse="non") & Q(participants__reponse="non")
) )
events_a_venir_answered_pe = Event.objects.filter( events_a_venir_answered_pe = Event.objects.filter(date__gte=lToday).filter(
date__gte=lToday).filter(
Q(participants__participant=self.request.user.profile) Q(participants__participant=self.request.user.profile)
& Q(participants__reponse="pe") & Q(participants__reponse="pe")
) )
except Event.DoesNotExist: except Event.DoesNotExist:
events_a_venir_not_answered = Event.objects.filter( events_a_venir_not_answered = Event.objects.filter(
date__gte=lToday).exclude( date__gte=lToday
participants__participant__user__username=self.request.user ).exclude(participants__participant__user__username=self.request.user)
) events_a_venir_answered_yes = Event.objects.filter(date__gte=lToday).filter(
events_a_venir_answered_yes = Event.objects.filter(
date__gte=lToday).filter(
Q(participants__participant__user__username=self.request.user) Q(participants__participant__user__username=self.request.user)
& Q(participants__reponse="oui") & Q(participants__reponse="oui")
) )
events_a_venir_answered_no = Event.objects.filter( events_a_venir_answered_no = Event.objects.filter(date__gte=lToday).filter(
date__gte=lToday).filter(
Q(participants__participant__user__username=self.request.user) Q(participants__participant__user__username=self.request.user)
& Q(participants__reponse="non") & Q(participants__reponse="non")
) )
events_a_venir_answered_pe = Event.objects.filter( events_a_venir_answered_pe = Event.objects.filter(date__gte=lToday).filter(
date__gte=lToday).filter(
Q(participants__participant__user__username=self.request.user) Q(participants__participant__user__username=self.request.user)
& Q(participants__reponse="pe") & Q(participants__reponse="pe")
) )
@ -173,7 +162,7 @@ class ViewEvent(LoginRequiredMixin, TemplateView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(ViewEvent, self).get_context_data(**kwargs) context = super(ViewEvent, self).get_context_data(**kwargs)
event = get_object_or_404(Event, id=self.kwargs['id']) event = get_object_or_404(Event, id=self.kwargs["id"])
participants = event.participants_set.all() participants = event.participants_set.all()
multi_instrumentistes = event.participants_set.filter( multi_instrumentistes = event.participants_set.filter(
Q(participant__multi_instrumentiste="Oui") & ~Q(reponse="non") Q(participant__multi_instrumentiste="Oui") & ~Q(reponse="non")
@ -213,8 +202,7 @@ class ViewEvent(LoginRequiredMixin, TemplateView):
) )
else: else:
namesnon += [participant.participant.get_doodlename()] namesnon += [participant.participant.get_doodlename()]
instrument_count[instru] = (sure, maybe, namesoui, instrument_count[instru] = (sure, maybe, namesoui, namespe, namesnon)
namespe, namesnon)
instrument_count = [ instrument_count = [
(instrument, sure, maybe, namesoui, namespe, namesnon) (instrument, sure, maybe, namesoui, namespe, namesnon)
@ -243,8 +231,8 @@ class ChangeName(LoginRequiredMixin, TemplateView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context['form'] = self.form_class(instance=self.request.user) context["form"] = self.form_class(instance=self.request.user)
context["id"] = self.kwargs['id'] context["id"] = self.kwargs["id"]
return context return context
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
@ -254,10 +242,10 @@ class ChangeName(LoginRequiredMixin, TemplateView):
if form.is_valid(): if form.is_valid():
form.save() form.save()
success = True success = True
return redirect("calendrier:view-event", id=self.kwargs['id']) return redirect("calendrier:view-event", id=self.kwargs["id"])
else: else:
context = self.get_context_data() context = self.get_context_data()
context['success'] = success context["success"] = success
return render(request, self.template_name, context) return render(request, self.template_name, context)
@ -267,7 +255,7 @@ class CreateEvent(LoginRequiredMixin, TemplateView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context['form'] = self.form_class() context["form"] = self.form_class()
return context return context
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
@ -298,14 +286,14 @@ class ReponseEvent(LoginRequiredMixin, TemplateView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context['form'] = self.form_class() context["form"] = self.form_class()
context['ev'] = get_object_or_404(Event, id=self.kwargs['id']) context["ev"] = get_object_or_404(Event, id=self.kwargs["id"])
context['id'] = self.kwargs['id'] context["id"] = self.kwargs["id"]
return context return context
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
form = self.form_class(request.POST) form = self.form_class(request.POST)
ev = get_object_or_404(Event, id=self.kwargs['id']) ev = get_object_or_404(Event, id=self.kwargs["id"])
part = request.user.profile part = request.user.profile
if form.is_valid(): if form.is_valid():
try: try:
@ -317,7 +305,7 @@ class ReponseEvent(LoginRequiredMixin, TemplateView):
obj.event = ev obj.event = ev
obj.participant = part obj.participant = part
obj.save() obj.save()
return redirect("calendrier:view-event", id=self.kwargs['id']) return redirect("calendrier:view-event", id=self.kwargs["id"])
else: else:
context = self.get_context_data() context = self.get_context_data()
return render(request, self.template_name, context) return render(request, self.template_name, context)
@ -334,8 +322,7 @@ class EventUpdate(ChefRequiredMixin, UpdateView):
return ctx return ctx
def get_success_url(self): def get_success_url(self):
return reverse("calendrier:view-event", return reverse("calendrier:view-event", kwargs={"id": self.get_object().id})
kwargs={"id": self.get_object().id})
class EventDelete(ChefRequiredMixin, DeleteView): class EventDelete(ChefRequiredMixin, DeleteView):

View file

@ -29,11 +29,9 @@ class Photo(models.Model):
raise ValidationError("La taille max est %sMB" % str(mb_limit)) raise ValidationError("La taille max est %sMB" % str(mb_limit))
name = models.CharField(max_length=127) name = models.CharField(max_length=127)
cat = models.CharField(max_length=127, choices=PHOTO_PLACEMENT, cat = models.CharField(max_length=127, choices=PHOTO_PLACEMENT, default="n")
default="n")
auteur = models.CharField( auteur = models.CharField(
max_length=127, verbose_name=_("Auteur de l'image"), null=True, max_length=127, verbose_name=_("Auteur de l'image"), null=True, blank=True
blank=True
) )
url = models.URLField( url = models.URLField(
verbose_name=_("Lien vers le site de l'auteur"), null=True, blank=True verbose_name=_("Lien vers le site de l'auteur"), null=True, blank=True
@ -52,10 +50,8 @@ class Photo(models.Model):
class ErnestoUser(models.Model): class ErnestoUser(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, user = models.OneToOneField(User, on_delete=models.CASCADE, related_name="profile")
related_name="profile") is_ernesto = models.BooleanField(_("Membre de l'Ernestophone"), default=True)
is_ernesto = models.BooleanField(_("Membre de l'Ernestophone"),
default=True)
is_chef = models.BooleanField(_("Chef Fanfare"), default=False) is_chef = models.BooleanField(_("Chef Fanfare"), default=False)
phone = models.CharField( phone = models.CharField(
_("Téléphone"), _("Téléphone"),
@ -101,8 +97,7 @@ class ErnestoUser(models.Model):
_("Lequel ?"), null=True, max_length=100, blank=True _("Lequel ?"), null=True, max_length=100, blank=True
) )
slug = models.CharField(max_length=7, editable=False, unique=True) slug = models.CharField(max_length=7, editable=False, unique=True)
doodlename = models.CharField(_("Nom pour le doodle"), max_length=30, doodlename = models.CharField(_("Nom pour le doodle"), max_length=30, blank=True)
blank=True)
trombonoscope = models.CharField( trombonoscope = models.CharField(
_("Je souhaite apparaitre dans le trombonoscope:"), _("Je souhaite apparaitre dans le trombonoscope:"),

View file

@ -3,17 +3,17 @@ import string
from django.conf import settings from django.conf import settings
from django.contrib.auth.forms import PasswordChangeForm from django.contrib.auth.forms import PasswordChangeForm
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.views import LoginView from django.contrib.auth.views import LoginView
from django.shortcuts import redirect, render from django.shortcuts import redirect, render
from django.utils.translation import gettext_lazy as _
from django.views.generic import TemplateView
from calendrier.forms import ChangeDoodleName from calendrier.forms import ChangeDoodleName
from gestion.forms import (ChangeFormUser, ChangeMembreForm, from gestion.forms import (ChangeFormUser, ChangeMembreForm,
InscriptionMembreForm, RegistrationFormUser) InscriptionMembreForm, RegistrationFormUser)
from gestion.models import ErnestoUser, Photo, VideoGallery from gestion.models import ErnestoUser, Photo, VideoGallery
from partitions.models import Category from partitions.models import Category
from django.views.generic import TemplateView
from django.contrib.auth.mixins import LoginRequiredMixin
from django.utils.translation import gettext_lazy as _
def generer(*args): def generer(*args):
@ -27,22 +27,24 @@ class Home(TemplateView):
def dispatch(self, request, *args, **kwargs): def dispatch(self, request, *args, **kwargs):
if request.user.is_authenticated: if request.user.is_authenticated:
return redirect('calendrier:home') return redirect("calendrier:home")
return super(Home, self).dispatch(request, *args, **kwargs) return super(Home, self).dispatch(request, *args, **kwargs)
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context["categories"] = Category.objects.filter( context["categories"] = Category.objects.filter(
name="Partitions actives").prefetch_related( name="Partitions actives"
"partitionset_set" ).prefetch_related("partitionset_set")
) context["videos"] = VideoGallery.objects.all()
context['videos'] = VideoGallery.objects.all() context["photo_rep"] = (
context['photo_rep'] = Photo.objects.filter( Photo.objects.filter(cat="home_rep").order_by("?").first()
cat="home_rep").order_by("?").first() )
context['photo_join'] = Photo.objects.filter( context["photo_join"] = (
cat="home_join").order_by("?").first() Photo.objects.filter(cat="home_join").order_by("?").first()
context['photo_contact'] = Photo.objects.filter( )
cat="home_contact").order_by("?").first() context["photo_contact"] = (
Photo.objects.filter(cat="home_contact").order_by("?").first()
)
return context return context
@ -52,8 +54,7 @@ class MyLoginView(LoginView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context["photo"] = Photo.objects.filter( context["photo"] = Photo.objects.filter(cat="login").order_by("?").first()
cat="login").order_by("?").first()
return context return context
@ -67,19 +68,18 @@ class ChangeName(LoginRequiredMixin, TemplateView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context['form'] = self.form_class(instance=self.request.user) context["form"] = self.form_class(instance=self.request.user)
return context return context
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
requbis = request.POST.copy() requbis = request.POST.copy()
form = self.form_class(requbis, form = self.form_class(requbis, instance=request.user)
instance=request.user)
if form.is_valid(): if form.is_valid():
form.save() form.save()
return redirect("change_membre") return redirect("change_membre")
context = self.get_context_data() context = self.get_context_data()
context['form'] = form context["form"] = form
return render(request, self.template_name, context) return render(request, self.template_name, context)
@ -94,14 +94,14 @@ class ChangeMembre(LoginRequiredMixin, TemplateView):
user_form = self.user_form_class(instance=self.request.user) user_form = self.user_form_class(instance=self.request.user)
context["comp_form"] = comp_form context["comp_form"] = comp_form
context["user_form"] = user_form context["user_form"] = user_form
context["photo"] = Photo.objects.filter( context["photo"] = (
cat="change_membre").order_by("?").first() Photo.objects.filter(cat="change_membre").order_by("?").first()
)
return context return context
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
success = False success = False
comp_form = self.comp_form_class(request.POST, comp_form = self.comp_form_class(request.POST, instance=request.user.profile)
instance=request.user.profile)
user_form = self.user_form_class(request.POST, instance=request.user) user_form = self.user_form_class(request.POST, instance=request.user)
if user_form.is_valid() and comp_form.is_valid(): if user_form.is_valid() and comp_form.is_valid():
user_form.save() user_form.save()
@ -109,9 +109,9 @@ class ChangeMembre(LoginRequiredMixin, TemplateView):
success = True success = True
context = self.get_context_data() context = self.get_context_data()
context['success'] = success context["success"] = success
context['comp_form'] = comp_form context["comp_form"] = comp_form
context['user_form'] = user_form context["user_form"] = user_form
return render(request, self.template_name, context) return render(request, self.template_name, context)
@ -121,7 +121,7 @@ class ChangePassword(LoginRequiredMixin, TemplateView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context['form'] = self.form_class(self.request.user) context["form"] = self.form_class(self.request.user)
return context return context
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
@ -132,8 +132,8 @@ class ChangePassword(LoginRequiredMixin, TemplateView):
form.save() form.save()
success = True success = True
context = self.get_context_data() context = self.get_context_data()
context['success'] = success context["success"] = success
context['form'] = form context["form"] = form
return render(request, self.template_name, context) return render(request, self.template_name, context)
@ -144,10 +144,11 @@ class Inscription(TemplateView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context['comp_form'] = self.comp_form_class() context["comp_form"] = self.comp_form_class()
context['user_form'] = self.user_form_class() context["user_form"] = self.user_form_class()
context['photo'] = Photo.objects.filter( context["photo"] = (
cat="inscription_membre").order_by("?").first() Photo.objects.filter(cat="inscription_membre").order_by("?").first()
)
return context return context
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
@ -160,9 +161,9 @@ class Inscription(TemplateView):
): ):
error = _("Le champ Validation ne correspond pas à celui attendu") error = _("Le champ Validation ne correspond pas à celui attendu")
context = self.get_context_data() context = self.get_context_data()
context['user_form'] = user_form context["user_form"] = user_form
context['comp_form'] = comp_form context["comp_form"] = comp_form
context['error'] = error context["error"] = error
return render(request, self.template_name, context) return render(request, self.template_name, context)
member = user_form.save(commit=False) member = user_form.save(commit=False)
temp = True temp = True
@ -173,8 +174,7 @@ class Inscription(TemplateView):
except ErnestoUser.DoesNotExist: except ErnestoUser.DoesNotExist:
temp = False temp = False
member.save() member.save()
(profile, k) = ErnestoUser.objects.get_or_create(user=member, (profile, k) = ErnestoUser.objects.get_or_create(user=member, slug=code)
slug=code)
comp_form = self.comp_form_class(request.POST, instance=profile) comp_form = self.comp_form_class(request.POST, instance=profile)
obj = comp_form.save(commit=False) obj = comp_form.save(commit=False)
obj.slug = code obj.slug = code
@ -182,6 +182,6 @@ class Inscription(TemplateView):
return redirect("thanks") return redirect("thanks")
else: else:
context = self.get_context_data() context = self.get_context_data()
context['user_form'] = user_form context["user_form"] = user_form
context['comp_form'] = comp_form context["comp_form"] = comp_form
return render(request, self.template_name, context) return render(request, self.template_name, context)

View file

@ -5,10 +5,8 @@ from . import views
app_name = "instruments" app_name = "instruments"
urlpatterns = [ urlpatterns = [
path("", views.ListeInstru.as_view(), name="liste"), path("", views.ListeInstru.as_view(), name="liste"),
path("delete/<int:pk>", views.DeleteInstru.as_view(), path("delete/<int:pk>", views.DeleteInstru.as_view(), name="delete_instru"),
name="delete_instru"), path("delete_reparation/<int:pk>", views.DeleteRep.as_view(), name="delete_rep"),
path("delete_reparation/<int:pk>", views.DeleteRep.as_view(),
name="delete_rep"),
path("new", views.CreateInstru.as_view(), name="ajouter_instru"), path("new", views.CreateInstru.as_view(), name="ajouter_instru"),
path("new_rep/<int:pk>", views.CreateRep.as_view(), name="ajouter_rep"), path("new_rep/<int:pk>", views.CreateRep.as_view(), name="ajouter_rep"),
path("update_rep/<int:pk>", views.UpdateRep.as_view(), name="update_rep"), path("update_rep/<int:pk>", views.UpdateRep.as_view(), name="update_rep"),

View file

@ -1,12 +1,11 @@
from django.contrib.auth.mixins import LoginRequiredMixin
from django.shortcuts import get_object_or_404, redirect, render from django.shortcuts import get_object_or_404, redirect, render
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.views.generic import CreateView, DeleteView, UpdateView from django.views.generic import (CreateView, DeleteView, TemplateView,
from django.views.generic import TemplateView UpdateView)
from gestion.mixins import ChefRequiredMixin from gestion.mixins import ChefRequiredMixin
from django.contrib.auth.mixins import LoginRequiredMixin
from gestion.models import Photo from gestion.models import Photo
from instruments.forms import ChefEditInstrumentForm, ChefReparationForm from instruments.forms import ChefEditInstrumentForm, ChefReparationForm
from instruments.models import Instrument, Reparation from instruments.models import Instrument, Reparation
@ -17,19 +16,19 @@ class ListeInstru(LoginRequiredMixin, TemplateView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context['photo'] = Photo.objects.filter( context["photo"] = Photo.objects.filter(cat="instru").order_by("?").first()
cat="instru").order_by("?").first() context["instrus_dispo"] = (
context['instrus_dispo'] = Instrument.objects.all().order_by( Instrument.objects.all().order_by("type").filter(statut="Disponible")
"type").filter(statut="Disponible") )
context['instrus_prete'] = Instrument.objects.all().order_by( context["instrus_prete"] = (
"type").filter(statut="Prêté") Instrument.objects.all().order_by("type").filter(statut="Prêté")
)
return context return context
class CreateInstru(ChefRequiredMixin, CreateView): class CreateInstru(ChefRequiredMixin, CreateView):
model = Instrument model = Instrument
fields = ["owner", "etat", "type", "marque", fields = ["owner", "etat", "type", "marque", "model", "serial", "annee", "prix"]
"model", "serial", "annee", "prix"]
template_name = "instruments/create_instru.html" template_name = "instruments/create_instru.html"
success_url = reverse_lazy("instruments:liste") success_url = reverse_lazy("instruments:liste")
@ -41,7 +40,7 @@ class CreateRep(ChefRequiredMixin, TemplateView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context["form"] = self.form_class() context["form"] = self.form_class()
context["pk"] = self.kwargs['pk'] context["pk"] = self.kwargs["pk"]
return context return context
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
@ -53,12 +52,12 @@ class CreateRep(ChefRequiredMixin, TemplateView):
rep.description_en = form.cleaned_data["description_en"] rep.description_en = form.cleaned_data["description_en"]
rep.prix = form.cleaned_data["prix"] rep.prix = form.cleaned_data["prix"]
rep.lieux = form.cleaned_data["lieux"] rep.lieux = form.cleaned_data["lieux"]
rep.instru = get_object_or_404(Instrument, id=self.kwargs['pk']) rep.instru = get_object_or_404(Instrument, id=self.kwargs["pk"])
rep.save() rep.save()
return redirect("instruments:fiche_instru", pk=self.kwargs['pk']) return redirect("instruments:fiche_instru", pk=self.kwargs["pk"])
else: else:
context = self.get_context_data() context = self.get_context_data()
context['form'] = form context["form"] = form
return render(request, self.template_name, context) return render(request, self.template_name, context)
@ -68,7 +67,7 @@ class DeleteRep(ChefRequiredMixin, TemplateView):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
rep = get_object_or_404(self.model, id=self.kwargs['pk']) rep = get_object_or_404(self.model, id=self.kwargs["pk"])
id_instru = rep.instru.id id_instru = rep.instru.id
rep.delete() rep.delete()
return redirect("instruments:fiche_instru", pk=id_instru) return redirect("instruments:fiche_instru", pk=id_instru)
@ -81,9 +80,10 @@ class FicheInstru(LoginRequiredMixin, TemplateView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
instru = get_object_or_404(self.model, id=self.kwargs['pk']) instru = get_object_or_404(self.model, id=self.kwargs["pk"])
reparations = Reparation.objects.filter( reparations = Reparation.objects.filter(instru=self.kwargs["pk"]).order_by(
instru=self.kwargs['pk']).order_by("-date") "-date"
)
form = ChefEditInstrumentForm(instance=instru) form = ChefEditInstrumentForm(instance=instru)
infos = mark_safe(instru.infos) infos = mark_safe(instru.infos)
@ -97,13 +97,13 @@ class FicheInstru(LoginRequiredMixin, TemplateView):
return context return context
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
instru = get_object_or_404(self.model, id=self.kwargs['pk']) instru = get_object_or_404(self.model, id=self.kwargs["pk"])
form = ChefEditInstrumentForm(request.POST, instance=instru) form = ChefEditInstrumentForm(request.POST, instance=instru)
if request.user.profile.is_chef: if request.user.profile.is_chef:
if form.is_valid(): if form.is_valid():
form.save() form.save()
context = self.get_context_data() context = self.get_context_data()
context['form'] = form context["form"] = form
return render(request, self.template_name, context) return render(request, self.template_name, context)
@ -113,10 +113,8 @@ class UpdateRep(ChefRequiredMixin, UpdateView):
template_name = "instruments/update_rep.html" template_name = "instruments/update_rep.html"
def get_success_url(self): def get_success_url(self):
id_instru = get_object_or_404(Reparation, id_instru = get_object_or_404(Reparation, id=self.kwargs["pk"]).instru.id
id=self.kwargs["pk"]).instru.id return reverse_lazy("instruments:fiche_instru", kwargs={"pk": id_instru})
return reverse_lazy("instruments:fiche_instru",
kwargs={"pk": id_instru})
class DeleteInstru(ChefRequiredMixin, DeleteView): class DeleteInstru(ChefRequiredMixin, DeleteView):

View file

@ -6,22 +6,27 @@ app_name = "partitions"
urlpatterns = [ urlpatterns = [
path("", views.Repertoire.as_view(), name="liste"), path("", views.Repertoire.as_view(), name="liste"),
path("download", views.download_musecores, name="download_musecores"), path("download", views.download_musecores, name="download_musecores"),
path("<str:nom>/<str:auteur>/upload", views.Upload.as_view(), path("<str:nom>/<str:auteur>/upload", views.Upload.as_view(), name="upload"),
name="upload"),
path("<str:nom>/<str:auteur>", views.Morceau.as_view(), name="listepart"), path("<str:nom>/<str:auteur>", views.Morceau.as_view(), name="listepart"),
path("<str:nom>/<str:auteur>/see/<int:partition_id>", views.see, path("<str:nom>/<str:auteur>/see/<int:partition_id>", views.see, name="see"),
name="see"), path("<str:nom>/<str:auteur>/<int:partition_id>", views.download, name="download"),
path("<str:nom>/<str:auteur>/<int:partition_id>", views.download,
name="download"),
path("<str:nom>/<str:auteur>/<int:id>/conf", views.ConfDelete.as_view(),
name="conf_delete"),
path("<str:nom>/<str:auteur>/<int:id>/delete", views.DeletePart.as_view(),
name="delete"),
path("<str:nom>/<str:auteur>/delete", views.DeleteMorc.as_view(),
name="delete_morc"),
path( path(
"<str:nom>/<str:auteur>/conf", views.ConfDeleteMorc.as_view(), "<str:nom>/<str:auteur>/<int:id>/conf",
name="conf_delete_morc" views.ConfDelete.as_view(),
name="conf_delete",
),
path(
"<str:nom>/<str:auteur>/<int:id>/delete",
views.DeletePart.as_view(),
name="delete",
),
path(
"<str:nom>/<str:auteur>/delete", views.DeleteMorc.as_view(), name="delete_morc"
),
path(
"<str:nom>/<str:auteur>/conf",
views.ConfDeleteMorc.as_view(),
name="conf_delete_morc",
), ),
path("new", views.CreateMorc.as_view(), name="ajouter_morceau"), path("new", views.CreateMorc.as_view(), name="ajouter_morceau"),
] ]

View file

@ -2,6 +2,7 @@ import io
import os import os
import zipfile import zipfile
from django.contrib.auth.mixins import LoginRequiredMixin
from django.core.files import File from django.core.files import File
from django.db.models import Q from django.db.models import Q
from django.http import Http404 from django.http import Http404
@ -9,15 +10,14 @@ from django.shortcuts import HttpResponse, get_object_or_404, redirect, render
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.utils.text import slugify from django.utils.text import slugify
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.views.generic import TemplateView
from gestion.mixins import ChefRequiredMixin
from gestion.models import Photo from gestion.models import Photo
from partitions.forms import UploadFileForm, UploadMorceauForm from partitions.forms import UploadFileForm, UploadMorceauForm
from partitions.models import Category, Partition, PartitionSet from partitions.models import Category, Partition, PartitionSet
from django.contrib.auth.mixins import LoginRequiredMixin
from django.views.generic import TemplateView
from .forms import ChefEditMorceauForm from .forms import ChefEditMorceauForm
from gestion.mixins import ChefRequiredMixin
def download_musecores(request): def download_musecores(request):
@ -74,10 +74,10 @@ class Repertoire(TemplateView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context['categories'] = Category.objects.prefetch_related( context["categories"] = Category.objects.prefetch_related(
"partitionset_set").order_by("order") "partitionset_set"
context['photo'] = Photo.objects.filter( ).order_by("order")
cat="part").order_by("?").first() context["photo"] = Photo.objects.filter(cat="part").order_by("?").first()
return context return context
@ -87,8 +87,9 @@ class Morceau(LoginRequiredMixin, TemplateView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(Morceau, self).get_context_data(**kwargs) context = super(Morceau, self).get_context_data(**kwargs)
p = get_object_or_404(PartitionSet, nom=self.kwargs['nom'], p = get_object_or_404(
auteur=self.kwargs['auteur']) PartitionSet, nom=self.kwargs["nom"], auteur=self.kwargs["auteur"]
)
part = p.partition_set.all().order_by("nom") part = p.partition_set.all().order_by("nom")
form = self.form_class(instance=p) form = self.form_class(instance=p)
infos = mark_safe(p.infos) infos = mark_safe(p.infos)
@ -99,14 +100,15 @@ class Morceau(LoginRequiredMixin, TemplateView):
context["infos_en"] = infos_en context["infos_en"] = infos_en
context["form"] = form context["form"] = form
context["part"] = part context["part"] = part
context["nom"] = self.kwargs['nom'] context["nom"] = self.kwargs["nom"]
context["auteur"] = self.kwargs['auteur'] context["auteur"] = self.kwargs["auteur"]
return context return context
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
p = get_object_or_404(PartitionSet, nom=self.kwargs['nom'], p = get_object_or_404(
auteur=self.kwargs['auteur']) PartitionSet, nom=self.kwargs["nom"], auteur=self.kwargs["auteur"]
)
if request.user.profile.is_chef: if request.user.profile.is_chef:
form = self.form_class(request.POST, instance=p) form = self.form_class(request.POST, instance=p)
if form.is_valid(): if form.is_valid():
@ -126,8 +128,8 @@ class Upload(ChefRequiredMixin, TemplateView):
form = self.form_class() form = self.form_class()
context["sauvegarde"] = self.sauvegarde context["sauvegarde"] = self.sauvegarde
context["nom"] = self.kwargs['nom'] context["nom"] = self.kwargs["nom"]
context["auteur"] = self.kwargs['auteur'] context["auteur"] = self.kwargs["auteur"]
context["form"] = form context["form"] = form
context["error"] = self.error context["error"] = self.error
return context return context
@ -142,8 +144,9 @@ class Upload(ChefRequiredMixin, TemplateView):
self.error = _("Le caractère / n'est pas autorisé dans le nom") self.error = _("Le caractère / n'est pas autorisé dans le nom")
context = self.get_context_data() context = self.get_context_data()
return render(request, self.template_name, context) return render(request, self.template_name, context)
mor = get_object_or_404(PartitionSet, nom=self.kwargs['nom'], mor = get_object_or_404(
auteur=self.kwargs['auteur']) PartitionSet, nom=self.kwargs["nom"], auteur=self.kwargs["auteur"]
)
partition.morceau = mor partition.morceau = mor
try: try:
mor.partition_set.get(nom=partition.nom) mor.partition_set.get(nom=partition.nom)
@ -153,7 +156,7 @@ class Upload(ChefRequiredMixin, TemplateView):
self.sauvegarde = True self.sauvegarde = True
context = self.get_context_data() context = self.get_context_data()
context['form'] = form context["form"] = form
return render(request, self.template_name, context) return render(request, self.template_name, context)
@ -197,15 +200,17 @@ class DeletePart(ChefRequiredMixin, TemplateView):
model = PartitionSet model = PartitionSet
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
p = get_object_or_404(self.model, nom=self.kwargs['nom'], p = get_object_or_404(
auteur=self.kwargs['auteur']) self.model, nom=self.kwargs["nom"], auteur=self.kwargs["auteur"]
)
try: try:
part = p.partition_set.get(id=self.kwargs['id']) part = p.partition_set.get(id=self.kwargs["id"])
except Partition.DoesNotExist: except Partition.DoesNotExist:
raise Http404 raise Http404
part.delete() part.delete()
return redirect("partitions:listepart", nom=self.kwargs['nom'], return redirect(
auteur=self.kwargs['auteur']) "partitions:listepart", nom=self.kwargs["nom"], auteur=self.kwargs["auteur"]
)
class CreateMorc(ChefRequiredMixin, TemplateView): class CreateMorc(ChefRequiredMixin, TemplateView):
@ -214,7 +219,7 @@ class CreateMorc(ChefRequiredMixin, TemplateView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(CreateMorc, self).get_context_data(**kwargs) context = super(CreateMorc, self).get_context_data(**kwargs)
context['form'] = self.form_class() context["form"] = self.form_class()
return context return context
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
@ -228,7 +233,7 @@ class CreateMorc(ChefRequiredMixin, TemplateView):
if "/" in partitionset.auteur or "/" in partitionset.nom: if "/" in partitionset.auteur or "/" in partitionset.nom:
error = _("Le caractère / n'est pas autorisé") error = _("Le caractère / n'est pas autorisé")
context = self.get_context_data() context = self.get_context_data()
context['error'] = error context["error"] = error
return render(request, self.template_name, context) return render(request, self.template_name, context)
try: try:
PartitionSet.objects.get( PartitionSet.objects.get(
@ -247,9 +252,9 @@ class CreateMorc(ChefRequiredMixin, TemplateView):
sauvegarde = True sauvegarde = True
return redirect("partitions:liste") return redirect("partitions:liste")
context = self.get_context_data() context = self.get_context_data()
context['sauvegarde'] = sauvegarde context["sauvegarde"] = sauvegarde
context['error'] = error context["error"] = error
context['form'] = form context["form"] = form
return render(request, self.template_name, context) return render(request, self.template_name, context)
@ -258,9 +263,9 @@ class ConfDelete(ChefRequiredMixin, TemplateView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context['nom'] = self.kwargs.get("nom") context["nom"] = self.kwargs.get("nom")
context['auteur'] = self.kwargs.get("auteur") context["auteur"] = self.kwargs.get("auteur")
context['id'] = self.kwargs.get("id") context["id"] = self.kwargs.get("id")
return context return context
@ -268,8 +273,9 @@ class DeleteMorc(ChefRequiredMixin, TemplateView):
model = PartitionSet model = PartitionSet
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
p = get_object_or_404(self.model, nom=self.kwargs['nom'], p = get_object_or_404(
auteur=self.kwargs['auteur']) self.model, nom=self.kwargs["nom"], auteur=self.kwargs["auteur"]
)
part = p.partition_set.all() part = p.partition_set.all()
for pa in part: for pa in part:
pa.delete() pa.delete()
@ -282,8 +288,8 @@ class ConfDeleteMorc(ChefRequiredMixin, TemplateView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context['nom'] = self.kwargs.get("nom") context["nom"] = self.kwargs.get("nom")
context['auteur'] = self.kwargs.get("auteur") context["auteur"] = self.kwargs.get("auteur")
return context return context

View file

@ -1,9 +1,9 @@
from django.contrib.auth.mixins import LoginRequiredMixin
from django.shortcuts import redirect, render from django.shortcuts import redirect, render
from django.views.generic import TemplateView
from gestion.models import ErnestoUser from gestion.models import ErnestoUser
from trombonoscope.forms import ChangeTrombonoscope from trombonoscope.forms import ChangeTrombonoscope
from django.contrib.auth.mixins import LoginRequiredMixin
from django.views.generic import TemplateView
class ChangeTrombonoscope(LoginRequiredMixin, TemplateView): class ChangeTrombonoscope(LoginRequiredMixin, TemplateView):
@ -13,17 +13,18 @@ class ChangeTrombonoscope(LoginRequiredMixin, TemplateView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
form = self.form_class(instance=self.request.user.profile) form = self.form_class(instance=self.request.user.profile)
context['form'] = form context["form"] = form
return context return context
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
form = self.form_class(request.POST, request.FILES, form = self.form_class(
instance=request.user.profile) request.POST, request.FILES, instance=request.user.profile
)
if form.is_valid(): if form.is_valid():
form.save() form.save()
return redirect("trombonoscope:view") return redirect("trombonoscope:view")
context = self.get_context_data() context = self.get_context_data()
context['form'] = form context["form"] = form
return render(request, self.template_name, context) return render(request, self.template_name, context)
@ -32,8 +33,8 @@ class Trombonoscope(LoginRequiredMixin, TemplateView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context['trombonoscope_vieux'] = ErnestoUser.objects.filter( context["trombonoscope_vieux"] = ErnestoUser.objects.filter(trombonoscope="o_v")
trombonoscope="o_v") context["trombonoscope_actuel"] = ErnestoUser.objects.filter(
context['trombonoscope_actuel'] = ErnestoUser.objects.filter( trombonoscope="o_a"
trombonoscope="o_a") )
return context return context