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 += i18n_patterns(
path("", gestion_views.Home.as_view(), name="home"),
path("registration", gestion_views.Inscription.as_view(),
name="registration"),
path("registration", gestion_views.Inscription.as_view(), name="registration"),
path("change", gestion_views.ChangeMembre.as_view(), name="change_membre"),
path("password", gestion_views.ChangePassword.as_view(),
name="change_password"),
path("password", gestion_views.ChangePassword.as_view(), name="change_password"),
path("thanks", gestion_views.Thanks.as_view(), name="thanks"),
path("changename", gestion_views.ChangeName.as_view(), name="change-doodle-name"),
path("logout", auth_views.LogoutView.as_view(next_page="home"),
name="logout"),
path("logout", auth_views.LogoutView.as_view(next_page="home"), name="logout"),
path("login", gestion_views.MyLoginView.as_view(), name="login"),
path("agenda/", include("calendrier.urls", namespace="calendrier")),
path("partitions/", include("partitions.urls")),

View file

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

View file

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

View file

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

View file

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

View file

@ -6,22 +6,27 @@ app_name = "partitions"
urlpatterns = [
path("", views.Repertoire.as_view(), name="liste"),
path("download", views.download_musecores, name="download_musecores"),
path("<str:nom>/<str:auteur>/upload", views.Upload.as_view(),
name="upload"),
path("<str:nom>/<str:auteur>/upload", views.Upload.as_view(), name="upload"),
path("<str:nom>/<str:auteur>", views.Morceau.as_view(), name="listepart"),
path("<str:nom>/<str:auteur>/see/<int:partition_id>", views.see,
name="see"),
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("<str:nom>/<str:auteur>/see/<int:partition_id>", views.see, name="see"),
path("<str:nom>/<str:auteur>/<int:partition_id>", views.download, name="download"),
path(
"<str:nom>/<str:auteur>/conf", views.ConfDeleteMorc.as_view(),
name="conf_delete_morc"
"<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(
"<str:nom>/<str:auteur>/conf",
views.ConfDeleteMorc.as_view(),
name="conf_delete_morc",
),
path("new", views.CreateMorc.as_view(), name="ajouter_morceau"),
]

View file

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

View file

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