From b62d6f47a4ed4cd504e919344d58beaf220e8bd5 Mon Sep 17 00:00:00 2001 From: Maurice Debray Date: Thu, 6 Jan 2022 13:11:16 +0100 Subject: [PATCH] Migrations + black/isort --- actu/migrations/0002_actu_rainbow.py | 18 +++++ actu/models.py | 10 ++- calendrier/calend.py | 6 +- calendrier/forms.py | 8 +- .../migrations/0005_auto_20210726_0949.py | 38 +++++++--- .../migrations/0006_auto_20210929_1629.py | 30 ++++++-- calendrier/models.py | 7 +- calendrier/views.py | 76 +++++++++++++------ gestion/migrations/0006_auto_20210608_1029.py | 13 +++- .../0007_ernestouser_is_chef_event.py | 10 ++- gestion/migrations/0008_auto_20211022_1923.py | 20 ++--- gestion/mixins.py | 48 +++++++++--- gestion/models.py | 34 +++++---- gestion/views.py | 6 +- instruments/views.py | 14 +++- pads/views.py | 2 +- 16 files changed, 245 insertions(+), 95 deletions(-) create mode 100644 actu/migrations/0002_actu_rainbow.py diff --git a/actu/migrations/0002_actu_rainbow.py b/actu/migrations/0002_actu_rainbow.py new file mode 100644 index 0000000..782ed5d --- /dev/null +++ b/actu/migrations/0002_actu_rainbow.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.25 on 2022-01-06 12:09 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('actu', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='actu', + name='rainbow', + field=models.CharField(choices=[('y', 'Oui'), ('n', 'Non')], default='n', max_length=1, verbose_name="Actu en arc-en-ciel (ne pas mettre d'émoji, il prennent aussi la couleur et c'est moche)"), + ), + ] diff --git a/actu/models.py b/actu/models.py index 8e0a240..cfb1bc8 100644 --- a/actu/models.py +++ b/actu/models.py @@ -7,7 +7,15 @@ class Actu(models.Model): text = models.TextField(_("Info"), null=True, blank=False) text_en = models.TextField(("Info en anglais"), null=True, blank=True) order = models.IntegerField(verbose_name=_("ordre")) - rainbow = models.CharField(verbose_name = _("Actu en arc-en-ciel (ne pas mettre d'émoji, il prennent aussi la couleur et c'est moche)"), max_length=1, choices = (('y', 'Oui'), ('n', 'Non')), default='n', blank = False) + rainbow = models.CharField( + verbose_name=_( + "Actu en arc-en-ciel (ne pas mettre d'émoji, il prennent aussi la couleur et c'est moche)" + ), + max_length=1, + choices=(("y", "Oui"), ("n", "Non")), + default="n", + blank=False, + ) def __str__(self): return self.text diff --git a/calendrier/calend.py b/calendrier/calend.py index 6d698b4..bb5c9fd 100644 --- a/calendrier/calend.py +++ b/calendrier/calend.py @@ -22,11 +22,11 @@ class EventCalendar(HTMLCalendar): for ev in self.events[day]: body.append(''+esc(ev.nom)) + body.append('style="color:#160083">' + esc(ev.nom)) elif ev.calendrier == "D": - body.append('style="color:#770083">'+esc(ev.nom)) + body.append('style="color:#770083">' + esc(ev.nom)) else: - body.append('>'+esc(ev.nom)) + body.append(">" + esc(ev.nom)) body.append("
") return self.day_cell( cssclass, diff --git a/calendrier/forms.py b/calendrier/forms.py index 47c126f..38aaf76 100644 --- a/calendrier/forms.py +++ b/calendrier/forms.py @@ -37,7 +37,13 @@ class EventForm(forms.ModelForm): class ParticipantsForm(forms.ModelForm): class Meta: model = Participants - fields = ("reponse", "details", "dont_play_main", "instrument","instrument_autre") + fields = ( + "reponse", + "details", + "dont_play_main", + "instrument", + "instrument_autre", + ) widgets = { "details": forms.Textarea(attrs={"placeholder": _("50 caractères max")}), } diff --git a/calendrier/migrations/0005_auto_20210726_0949.py b/calendrier/migrations/0005_auto_20210726_0949.py index 59164a4..a75295e 100644 --- a/calendrier/migrations/0005_auto_20210726_0949.py +++ b/calendrier/migrations/0005_auto_20210726_0949.py @@ -6,23 +6,41 @@ from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ - ('calendrier', '0004_auto_20210606_1640'), + ("calendrier", "0004_auto_20210606_1640"), ] operations = [ migrations.AlterField( - model_name='event', - name='calendrier', - field=models.CharField(choices=[('F', 'Visible seulement par les fanfarons'), ('T', 'Afficher dans le calendrier pour tous'), ('H', 'Hall of fame'), ('C', 'Visible seulement par les cheff·e·s'), ('D', "Visible seulement par les cheff·e·s et sur l'agenda public")], default='F', max_length=1), + model_name="event", + name="calendrier", + field=models.CharField( + choices=[ + ("F", "Visible seulement par les fanfarons"), + ("T", "Afficher dans le calendrier pour tous"), + ("H", "Hall of fame"), + ("C", "Visible seulement par les cheff·e·s"), + ("D", "Visible seulement par les cheff·e·s et sur l'agenda public"), + ], + default="F", + max_length=1, + ), ), migrations.AlterField( - model_name='event', - name='desc_users', - field=models.TextField(blank=True, null=True, verbose_name='Infos (visible seulement des fanfaron·ne·s)'), + model_name="event", + name="desc_users", + field=models.TextField( + blank=True, + null=True, + verbose_name="Infos (visible seulement des fanfaron·ne·s)", + ), ), migrations.AlterField( - model_name='event', - name='desc_users_en', - field=models.TextField(blank=True, null=True, verbose_name='Infos en anglais (visible seulement des fanfaron·ne·s'), + model_name="event", + name="desc_users_en", + field=models.TextField( + blank=True, + null=True, + verbose_name="Infos en anglais (visible seulement des fanfaron·ne·s", + ), ), ] diff --git a/calendrier/migrations/0006_auto_20210929_1629.py b/calendrier/migrations/0006_auto_20210929_1629.py index 85cc209..a763d21 100644 --- a/calendrier/migrations/0006_auto_20210929_1629.py +++ b/calendrier/migrations/0006_auto_20210929_1629.py @@ -6,18 +6,36 @@ from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ - ('calendrier', '0005_auto_20210726_0949'), + ("calendrier", "0005_auto_20210726_0949"), ] operations = [ migrations.AddField( - model_name='participants', - name='instrument_autre', + model_name="participants", + name="instrument_autre", field=models.CharField(blank=True, max_length=50, null=True), ), migrations.AlterField( - model_name='participants', - name='instrument', - field=models.CharField(blank=True, choices=[('Clarinette', 'Clarinette'), ('Euphonium', 'Euphonium'), ('Percussion', 'Percussion'), ('Piccolo', 'Piccolo'), ('Saxophone Alto', 'Saxophone Alto'), ('Saxophone Ténor', 'Saxophone Ténor'), ('Saxophone Baryton', 'Saxophone Baryton'), ('Souba', 'Souba'), ('Trombone', 'Trombone'), ('Trompette', 'Trompette'), ('Autre', 'Autre'), ('ne sais pas', 'Je ne sais pas encore')], max_length=50, null=True), + model_name="participants", + name="instrument", + field=models.CharField( + blank=True, + choices=[ + ("Clarinette", "Clarinette"), + ("Euphonium", "Euphonium"), + ("Percussion", "Percussion"), + ("Piccolo", "Piccolo"), + ("Saxophone Alto", "Saxophone Alto"), + ("Saxophone Ténor", "Saxophone Ténor"), + ("Saxophone Baryton", "Saxophone Baryton"), + ("Souba", "Souba"), + ("Trombone", "Trombone"), + ("Trompette", "Trompette"), + ("Autre", "Autre"), + ("ne sais pas", "Je ne sais pas encore"), + ], + max_length=50, + null=True, + ), ), ] diff --git a/calendrier/models.py b/calendrier/models.py index c24449d..f6754b3 100644 --- a/calendrier/models.py +++ b/calendrier/models.py @@ -3,8 +3,7 @@ import uuid from django.db import models from django.utils.translation import gettext_lazy as _ -from gestion.models import INSTRU_CHOICES -from gestion.models import ErnestoUser +from gestion.models import INSTRU_CHOICES, ErnestoUser ANSWERS = ( ("oui", _("Oui")), @@ -62,7 +61,9 @@ class Participants(models.Model): reponse = models.CharField( _("Réponse"), max_length=20, default="non", choices=ANSWERS ) - instrument = models.CharField(max_length=50, blank=True, null=True, choices=INSTRU_CHOICES) + instrument = models.CharField( + max_length=50, blank=True, null=True, choices=INSTRU_CHOICES + ) instrument_autre = models.CharField(max_length=50, blank=True, null=True) dont_play_main = models.CharField( _("Je veux jouer d'un instrument different de mon instrument principal:"), diff --git a/calendrier/views.py b/calendrier/views.py index c77fcf3..702b4bd 100644 --- a/calendrier/views.py +++ b/calendrier/views.py @@ -16,7 +16,7 @@ from calendrier.calend import EventCalendar from calendrier.forms import (ChangeDoodleName, EventForm, ModifEventForm, ParticipantsForm) from calendrier.models import Event, Participants -from gestion.mixins import ChefRequiredMixin, ChefEventRequiredMixin +from gestion.mixins import ChefEventRequiredMixin, ChefRequiredMixin from gestion.models import Photo @@ -76,9 +76,13 @@ class Calendar(LoginRequiredMixin, TemplateView): lMonth = self.pMonth lCalendarFromMonth = datetime(lYear, lMonth, 1) lCalendarToMonth = datetime(lYear, lMonth, monthrange(lYear, lMonth)[1]) - lEvents = Event.objects.filter( - date__gte=lCalendarFromMonth, date__lte=lCalendarToMonth - ).exclude(calendrier__iexact="C").exclude(calendrier__iexact="D") + lEvents = ( + Event.objects.filter( + date__gte=lCalendarFromMonth, date__lte=lCalendarToMonth + ) + .exclude(calendrier__iexact="C") + .exclude(calendrier__iexact="D") + ) lEvents_chef = Event.objects.filter( date__gte=lCalendarFromMonth, date__lte=lCalendarToMonth ) @@ -170,7 +174,6 @@ class Calendar(LoginRequiredMixin, TemplateView): class Home(Calendar): - @property def pYear(self): lToday = datetime.now() @@ -234,25 +237,52 @@ class ViewEvent(LoginRequiredMixin, TemplateView): namesnon += [participant.participant.get_doodlename()] instrument_count[instru] = (sure, maybe, namesoui, namespe, namesnon) instrument_count_l = [] - instru_order = ["Clarinette","Piccolo","Flute","Glockenspiel","Saxophone Alto","Trompette","Trombone","Cor","Saxophone Ténor","Saxophone Baryton","Clarinette Basse","Euphonium","Souba","Percussion"] + instru_order = [ + "Clarinette", + "Piccolo", + "Flute", + "Glockenspiel", + "Saxophone Alto", + "Trompette", + "Trombone", + "Cor", + "Saxophone Ténor", + "Saxophone Baryton", + "Clarinette Basse", + "Euphonium", + "Souba", + "Percussion", + ] for instrument in instru_order: if instrument in instrument_count.keys(): - (sure,maybe,namesoui,namespe,namesnon) =instrument_count[instrument] - instrument_count_l.append(( instrument, sure, - maybe, - namesoui, - namespe, - namesnon, - )) + (sure, maybe, namesoui, namespe, namesnon) = instrument_count[ + instrument + ] + instrument_count_l.append( + ( + instrument, + sure, + maybe, + namesoui, + namespe, + namesnon, + ) + ) for instrument in sorted(instrument_count.keys()): if instrument not in instru_order: - (sure,maybe,namesoui,namespe,namesnon) =instrument_count[instrument] - instrument_count_l.append(( instrument, sure, - maybe, - namesoui, - namespe, - namesnon, - )) + (sure, maybe, namesoui, namespe, namesnon) = instrument_count[ + instrument + ] + instrument_count_l.append( + ( + instrument, + sure, + maybe, + namesoui, + namespe, + namesnon, + ) + ) context["event"] = event context["instrument_count"] = instrument_count_l @@ -261,7 +291,7 @@ class ViewEvent(LoginRequiredMixin, TemplateView): context["nbpe"] = len(participants.filter(reponse="pe")) context["nbnon"] = len(participants.filter(reponse="non")) context["multi_instrumentistes"] = multi_instrumentistes - context["chef_only"] = (event.calendrier == "C")|(event.calendrier == "D") + context["chef_only"] = (event.calendrier == "C") | (event.calendrier == "D") return context @@ -337,7 +367,9 @@ class ReponseEvent(LoginRequiredMixin, TemplateView): context["form"] = self.form_class() context["ev"] = get_object_or_404(Event, id=self.kwargs["id"]) context["id"] = self.kwargs["id"] - context["chef_only"] = (context["ev"].calendrier == "C")|(context["ev"].calendrier == "D") + context["chef_only"] = (context["ev"].calendrier == "C") | ( + context["ev"].calendrier == "D" + ) return context def post(self, request, *args, **kwargs): diff --git a/gestion/migrations/0006_auto_20210608_1029.py b/gestion/migrations/0006_auto_20210608_1029.py index 0829dd0..4aac7ae 100644 --- a/gestion/migrations/0006_auto_20210608_1029.py +++ b/gestion/migrations/0006_auto_20210608_1029.py @@ -1,19 +1,24 @@ # Generated by Django 2.2.17 on 2021-06-08 10:29 from django.db import migrations, models + import gestion.models class Migration(migrations.Migration): dependencies = [ - ('gestion', '0005_auto_20210427_1834'), + ("gestion", "0005_auto_20210427_1834"), ] operations = [ migrations.AlterField( - model_name='photo', - name='image', - field=models.ImageField(default=None, upload_to='trombonoscope/deco', validators=[gestion.models.Photo.validate_image]), + model_name="photo", + name="image", + field=models.ImageField( + default=None, + upload_to="trombonoscope/deco", + validators=[gestion.models.Photo.validate_image], + ), ), ] diff --git a/gestion/migrations/0007_ernestouser_is_chef_event.py b/gestion/migrations/0007_ernestouser_is_chef_event.py index 9978aa0..aac4655 100644 --- a/gestion/migrations/0007_ernestouser_is_chef_event.py +++ b/gestion/migrations/0007_ernestouser_is_chef_event.py @@ -6,13 +6,15 @@ from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ - ('gestion', '0006_auto_20210608_1029'), + ("gestion", "0006_auto_20210608_1029"), ] operations = [ migrations.AddField( - model_name='ernestouser', - name='is_chef_event', - field=models.BooleanField(default=False, verbose_name='Respo événement Fanfare'), + model_name="ernestouser", + name="is_chef_event", + field=models.BooleanField( + default=False, verbose_name="Respo événement Fanfare" + ), ), ] diff --git a/gestion/migrations/0008_auto_20211022_1923.py b/gestion/migrations/0008_auto_20211022_1923.py index 6c427b9..d579dc4 100644 --- a/gestion/migrations/0008_auto_20211022_1923.py +++ b/gestion/migrations/0008_auto_20211022_1923.py @@ -6,23 +6,23 @@ from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ - ('gestion', '0007_ernestouser_is_chef_event'), + ("gestion", "0007_ernestouser_is_chef_event"), ] operations = [ migrations.AddField( - model_name='ernestouser', - name='is_chef_com', - field=models.BooleanField(default=False, verbose_name='Respo com'), + model_name="ernestouser", + name="is_chef_com", + field=models.BooleanField(default=False, verbose_name="Respo com"), ), migrations.AddField( - model_name='ernestouser', - name='is_chef_instru', - field=models.BooleanField(default=False, verbose_name='Respo instruments'), + model_name="ernestouser", + name="is_chef_instru", + field=models.BooleanField(default=False, verbose_name="Respo instruments"), ), migrations.AlterField( - model_name='ernestouser', - name='is_chef_event', - field=models.BooleanField(default=False, verbose_name='Respo événements'), + model_name="ernestouser", + name="is_chef_event", + field=models.BooleanField(default=False, verbose_name="Respo événements"), ), ] diff --git a/gestion/mixins.py b/gestion/mixins.py index 81bb535..2b22a22 100644 --- a/gestion/mixins.py +++ b/gestion/mixins.py @@ -6,32 +6,60 @@ class ChefRequiredMixin(UserPassesTestMixin): user = self.request.user return (user is not None) and hasattr(user, "profile") and user.profile.is_chef + class ChefEventRequiredMixin(UserPassesTestMixin): def test_func(self): user = self.request.user - is_chef = (user is not None) and hasattr(user, "profile") and user.profile.is_chef - is_chef_event = (user is not None) and hasattr(user, "profile") and user.profile.is_chef_event + is_chef = ( + (user is not None) and hasattr(user, "profile") and user.profile.is_chef + ) + is_chef_event = ( + (user is not None) + and hasattr(user, "profile") + and user.profile.is_chef_event + ) return is_chef or is_chef_event + class ChefInstruRequiredMixin(UserPassesTestMixin): def test_func(self): user = self.request.user - is_chef = (user is not None) and hasattr(user, "profile") and user.profile.is_chef - is_chef_instru = (user is not None) and hasattr(user, "profile") and user.profile.is_chef_instru + is_chef = ( + (user is not None) and hasattr(user, "profile") and user.profile.is_chef + ) + is_chef_instru = ( + (user is not None) + and hasattr(user, "profile") + and user.profile.is_chef_instru + ) return is_chef or is_chef_instru class ChefComRequiredMixin(UserPassesTestMixin): def test_func(self): user = self.request.user - is_chef = (user is not None) and hasattr(user, "profile") and user.profile.is_chef - is_chef_com = (user is not None) and hasattr(user, "profile") and user.profile.is_chef_com + is_chef = ( + (user is not None) and hasattr(user, "profile") and user.profile.is_chef + ) + is_chef_com = ( + (user is not None) and hasattr(user, "profile") and user.profile.is_chef_com + ) return is_chef or is_chef_com + + class AllChefRequiredMixin(UserPassesTestMixin): def test_func(self): user = self.request.user - is_chef = (user is not None) and hasattr(user, "profile") and user.profile.is_chef + is_chef = ( + (user is not None) and hasattr(user, "profile") and user.profile.is_chef + ) is_su = (user is not None) and user.is_superuser - is_chef_com = (user is not None) and hasattr(user, "profile") and user.profile.is_chef_com - is_chef_event = (user is not None) and hasattr(user, "profile") and user.profile.is_chef_event - return is_chef or is_chef_com or is_chef_event or is_su + is_chef_com = ( + (user is not None) and hasattr(user, "profile") and user.profile.is_chef_com + ) + is_chef_event = ( + (user is not None) + and hasattr(user, "profile") + and user.profile.is_chef_event + ) + return is_chef or is_chef_com or is_chef_event or is_su diff --git a/gestion/models.py b/gestion/models.py index a6a7484..dff5182 100644 --- a/gestion/models.py +++ b/gestion/models.py @@ -1,27 +1,30 @@ # -*- coding: utf-8 -*- +import os + from colorful.fields import RGBColorField +from django.conf import settings from django.contrib.auth.models import User from django.core.exceptions import ValidationError from django.db import models from django.utils.translation import gettext_lazy as _ -import os -from django.conf import settings INSTRU_CHOICES = [ - ("Clarinette", _("Clarinette")), - ("Euphonium", _("Euphonium")), - ("Percussion", _("Percussion")), - ("Piccolo", _("Piccolo")), - ("Saxophone Alto", _("Saxophone Alto")), - ("Saxophone Ténor", _("Saxophone Ténor")), - ("Saxophone Baryton", _("Saxophone Baryton")), - ("Souba", _("Souba")), - ("Trombone", _("Trombone")), - ("Trompette", _("Trompette")), - ("Autre", _("Autre")), - ("ne sais pas", _("Je ne sais pas encore")), - ] + ("Clarinette", _("Clarinette")), + ("Euphonium", _("Euphonium")), + ("Percussion", _("Percussion")), + ("Piccolo", _("Piccolo")), + ("Saxophone Alto", _("Saxophone Alto")), + ("Saxophone Ténor", _("Saxophone Ténor")), + ("Saxophone Baryton", _("Saxophone Baryton")), + ("Souba", _("Souba")), + ("Trombone", _("Trombone")), + ("Trompette", _("Trompette")), + ("Autre", _("Autre")), + ("ne sais pas", _("Je ne sais pas encore")), +] + + class Photo(models.Model): PHOTO_PLACEMENT = ( ("home_join", _("Rejoignez nous")), @@ -91,7 +94,6 @@ class ErnestoUser(models.Model): help_text=_("seulement visible par les chef·fe·s"), ) - COLORS_CHOICES = [ ("#e4522f#ffffff", _("Orange et Blanc")), ("#ffffff#000000", _("Blanc et Noir")), diff --git a/gestion/views.py b/gestion/views.py index 9c1e9f1..3b5f784 100644 --- a/gestion/views.py +++ b/gestion/views.py @@ -1,3 +1,4 @@ +import os import random import string @@ -11,12 +12,12 @@ from django.urls import reverse_lazy from django.utils.translation import gettext_lazy as _ from django.views.generic import (CreateView, DeleteView, ListView, TemplateView, UpdateView) -import os from calendrier.forms import ChangeDoodleName from gestion.forms import (ChangeFormUser, ChangeMembreForm, InscriptionMembreForm, RegistrationFormUser) -from gestion.mixins import ChefRequiredMixin, AllChefRequiredMixin, ChefComRequiredMixin +from gestion.mixins import (AllChefRequiredMixin, ChefComRequiredMixin, + ChefRequiredMixin) from gestion.models import ErnestoUser, Photo, VideoGallery from partitions.models import Category @@ -79,6 +80,7 @@ class Profil(LoginRequiredMixin, TemplateView): class Chef(AllChefRequiredMixin, TemplateView): template_name = "gestion/chef.html" + class YearBook2021(TemplateView): template_name = "gestion/yearbook2021.html" diff --git a/instruments/views.py b/instruments/views.py index 1bdfc03..f69d920 100644 --- a/instruments/views.py +++ b/instruments/views.py @@ -5,7 +5,7 @@ from django.utils.safestring import mark_safe from django.views.generic import (CreateView, DeleteView, TemplateView, UpdateView) -from gestion.mixins import ChefRequiredMixin, ChefInstruRequiredMixin +from gestion.mixins import ChefInstruRequiredMixin, ChefRequiredMixin from gestion.models import Photo from instruments.forms import ChefEditInstrumentForm, ChefReparationForm from instruments.models import Instrument, Reparation @@ -28,7 +28,17 @@ class ListeInstru(LoginRequiredMixin, TemplateView): class CreateInstru(ChefInstruRequiredMixin, CreateView): model = Instrument - fields = ["owner","user", "etat", "type", "marque", "model", "serial", "annee", "prix"] + fields = [ + "owner", + "user", + "etat", + "type", + "marque", + "model", + "serial", + "annee", + "prix", + ] template_name = "instruments/create_instru.html" success_url = reverse_lazy("instruments:liste") diff --git a/pads/views.py b/pads/views.py index a2c1741..b524c05 100644 --- a/pads/views.py +++ b/pads/views.py @@ -4,7 +4,7 @@ from django.urls import reverse_lazy from django.utils import timezone from django.views.generic import CreateView, DeleteView, ListView, UpdateView -from gestion.mixins import ChefRequiredMixin, ChefEventRequiredMixin +from gestion.mixins import ChefEventRequiredMixin, ChefRequiredMixin from pads.models import Pad