From d7fd5e553725e7251b384fb4c7425f3b0426b7f0 Mon Sep 17 00:00:00 2001 From: Lucie Galland Date: Sat, 23 Oct 2021 11:16:07 +0200 Subject: [PATCH] new respos --- calendrier/admin.py | 3 +- calendrier/views.py | 33 ++++++++++++------- gestion/migrations/0008_auto_20211022_1923.py | 28 ++++++++++++++++ gestion/mixins.py | 23 +++++++++++++ gestion/models.py | 2 ++ gestion/templates/gestion/base.html | 10 ++++-- gestion/templates/gestion/chef.html | 11 ++++++- gestion/views.py | 21 ++++++------ .../templates/instruments/instru_liste.html | 6 ++-- .../templates/instruments/update_instru.html | 10 +++--- instruments/views.py | 12 +++---- pads/templates/pads/create.html | 2 +- pads/templates/pads/list.html | 4 +-- pads/views.py | 8 ++--- 14 files changed, 125 insertions(+), 48 deletions(-) create mode 100644 gestion/migrations/0008_auto_20211022_1923.py diff --git a/calendrier/admin.py b/calendrier/admin.py index bd7204d..423de4a 100644 --- a/calendrier/admin.py +++ b/calendrier/admin.py @@ -1,6 +1,7 @@ from django.contrib import admin -from .models import Event +from .models import Event, Participants # Add event by admin page return a 502 error admin.site.register(Event) +admin.site.register(Participants) diff --git a/calendrier/views.py b/calendrier/views.py index cbe70ce..a11a211 100644 --- a/calendrier/views.py +++ b/calendrier/views.py @@ -232,20 +232,29 @@ class ViewEvent(LoginRequiredMixin, TemplateView): else: namesnon += [participant.participant.get_doodlename()] instrument_count[instru] = (sure, maybe, namesoui, namespe, namesnon) - - instrument_count = [ - (instrument, sure, maybe, namesoui, namespe, namesnon) - for instrument, ( - sure, - maybe, - namesoui, - namespe, - namesnon, - ) in instrument_count.items() - ] + instrument_count_l = [] + 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, + )) + 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, + )) context["event"] = event - context["instrument_count"] = instrument_count + context["instrument_count"] = instrument_count_l context["participants"] = participants context["nboui"] = len(participants.filter(reponse="oui")) context["nbpe"] = len(participants.filter(reponse="pe")) diff --git a/gestion/migrations/0008_auto_20211022_1923.py b/gestion/migrations/0008_auto_20211022_1923.py new file mode 100644 index 0000000..6c427b9 --- /dev/null +++ b/gestion/migrations/0008_auto_20211022_1923.py @@ -0,0 +1,28 @@ +# Generated by Django 2.2.24 on 2021-10-22 17:23 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('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'), + ), + migrations.AddField( + 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'), + ), + ] diff --git a/gestion/mixins.py b/gestion/mixins.py index c5967ce..81bb535 100644 --- a/gestion/mixins.py +++ b/gestion/mixins.py @@ -12,3 +12,26 @@ class ChefEventRequiredMixin(UserPassesTestMixin): 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 + 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 + 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_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 diff --git a/gestion/models.py b/gestion/models.py index e098191..a6a7484 100644 --- a/gestion/models.py +++ b/gestion/models.py @@ -82,6 +82,8 @@ class ErnestoUser(models.Model): is_ernesto = models.BooleanField(_("Membre de l'Ernestophone"), default=True) is_chef = models.BooleanField(_("Chef Fanfare"), default=False) is_chef_event = models.BooleanField(_("Respo événements"), default=False) + is_chef_com = models.BooleanField(_("Respo com"), default=False) + is_chef_instru = models.BooleanField(_("Respo instruments"), default=False) phone = models.CharField( _("Téléphone"), max_length=20, diff --git a/gestion/templates/gestion/base.html b/gestion/templates/gestion/base.html index 4107643..e588efa 100644 --- a/gestion/templates/gestion/base.html +++ b/gestion/templates/gestion/base.html @@ -67,7 +67,7 @@ - {% if user.is_superuser or user.profile.is_chef or user.profile.is_chef_event %} + {% if user.is_superuser or user.profile.is_chef or user.profile.is_chef_event or user.profile.is_chef_com %}
  • {{ p.nom }} - {% if user.profile.is_chef %} + {% if user.profile.is_chef_event or user.profile.is_chef %}   {% trans "Modifier" %}   {% trans "Supprimer" %} {% endif %} diff --git a/pads/views.py b/pads/views.py index c3ef998..a2c1741 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 +from gestion.mixins import ChefRequiredMixin, ChefEventRequiredMixin from pads.models import Pad @@ -15,7 +15,7 @@ class PadList(LoginRequiredMixin, ListView): template_name = "pads/list.html" -class PadCreate(ChefRequiredMixin, CreateView): +class PadCreate(ChefEventRequiredMixin, CreateView): model = Pad fields = ["nom", "url"] template_name = "pads/create.html" @@ -28,14 +28,14 @@ class PadCreate(ChefRequiredMixin, CreateView): return HttpResponseRedirect(self.success_url) -class PadUpdate(ChefRequiredMixin, UpdateView): +class PadUpdate(ChefEventRequiredMixin, UpdateView): model = Pad fields = ["nom", "url"] template_name = "pads/update.html" success_url = reverse_lazy("pads:list") -class PadDelete(ChefRequiredMixin, DeleteView): +class PadDelete(ChefEventRequiredMixin, DeleteView): model = Pad template_name = "pads/delete.html" success_url = reverse_lazy("pads:list")