From 38b0f1220193c45ceede127be8d5a5ab4249215b Mon Sep 17 00:00:00 2001 From: Lucie Galland Date: Wed, 6 Oct 2021 13:46:45 +0200 Subject: [PATCH] add respo event --- calendrier/templates/calendrier/home.html | 6 +++--- .../templates/calendrier/view_event.html | 13 +++++++------ calendrier/views.py | 8 ++++---- gestion/admin.py | 2 ++ .../0007_ernestouser_is_chef_event.py | 18 ++++++++++++++++++ gestion/mixins.py | 7 +++++++ gestion/models.py | 1 + gestion/templates/gestion/base.html | 7 ++++++- 8 files changed, 48 insertions(+), 14 deletions(-) create mode 100644 gestion/migrations/0007_ernestouser_is_chef_event.py diff --git a/calendrier/templates/calendrier/home.html b/calendrier/templates/calendrier/home.html index 87d7e62..0aed2a8 100644 --- a/calendrier/templates/calendrier/home.html +++ b/calendrier/templates/calendrier/home.html @@ -60,7 +60,7 @@
- {% if user.is_superuser or user.profile.is_chef %} + {% if user.profile.is_chef_event or user.profile.is_chef %} {% ifequal current_language "fr" %} {{Calendar_chef|translate}} {% else %} @@ -74,7 +74,7 @@ {% endifequal %} {% endif%}
-{% if user.is_superuser or user.profile.is_chef %} +{% if user.profile.is_chef_event or user.profile.is_chef %} {% trans "Ajouter un évènement" %} {% endif %} @@ -98,7 +98,7 @@ {% endif %} - {% if user.is_superuser or user.profile.is_chef %} + {% if user.profile.is_chef_event or user.profile.is_chef %} {% if events_a_venir_chef %}

{% blocktrans count counter=events_a_venir_chef|length %}Doodle seulement visible par les cheff·e·s :{% plural %}Doodles seulement visibles par les cheff·e·s :{% endblocktrans %}

diff --git a/calendrier/templates/calendrier/view_event.html b/calendrier/templates/calendrier/view_event.html index 64284e3..590e308 100644 --- a/calendrier/templates/calendrier/view_event.html +++ b/calendrier/templates/calendrier/view_event.html @@ -8,12 +8,12 @@
- {% if not user.is_superuser or not user.profile.is_chef %} + {% if not user.profile.is_chef and not user.profile.is_chef_event %} {% if chef_only %} {% trans "Cet événement est encore en construction ! Reviens plus tard." %} {% endif %} {% endif %} - {% if user.is_superuser or user.profile.is_chef or not chef_only%} + {% if user.profile.is_chef_event or user.profile.is_chef or not chef_only%}
@@ -87,7 +87,7 @@ {% endif %}
-{% if instrument_count and user.profile.is_chef %} +{% if user.profile.is_chef or user.profile.is_chef_event %} @@ -159,8 +159,8 @@ {% endfor %}
{% trans "Instrument" %}
{% endif %} -{% if multi_instrumentistes and user.profile.is_chef %} - +{% if user.profile.is_chef or user.profile.is_chef_event %} +{% if multi_instrumentistes %}

{% blocktrans count counter=multi_instrumentistes|length %}Multi-instrumentiste présent :{% plural %}Multi-instrumentistes présents{% endblocktrans %}

@@ -204,10 +204,11 @@ {% endfor %}
{% endif %} +{% endif %}
{% if user.is_authenticated %} -
{% if user.profile.is_chef %} +
{% if user.profile.is_chef or user.profile.is_chef_event %}

{% trans "Modifier l'événement" %}   {% trans "Supprimer l'événement" %}

{% endif %}

{% trans "Changer mon nom pour le doodle" %}   {% trans "Retour au calendrier" %}

diff --git a/calendrier/views.py b/calendrier/views.py index 26a4af9..cbe70ce 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 +from gestion.mixins import ChefRequiredMixin, ChefEventRequiredMixin from gestion.models import Photo @@ -279,7 +279,7 @@ class ChangeName(LoginRequiredMixin, TemplateView): return render(request, self.template_name, context) -class CreateEvent(LoginRequiredMixin, TemplateView): +class CreateEvent(ChefEventRequiredMixin, TemplateView): form_class = EventForm template_name = "calendrier/create.html" @@ -350,7 +350,7 @@ class ReponseEvent(LoginRequiredMixin, TemplateView): return render(request, self.template_name, context) -class EventUpdate(ChefRequiredMixin, UpdateView): +class EventUpdate(ChefEventRequiredMixin, UpdateView): model = Event template_name = "calendrier/update.html" form_class = ModifEventForm @@ -364,7 +364,7 @@ class EventUpdate(ChefRequiredMixin, UpdateView): return reverse("calendrier:view-event", kwargs={"id": self.get_object().id}) -class EventDelete(ChefRequiredMixin, DeleteView): +class EventDelete(ChefEventRequiredMixin, DeleteView): model = Event template_name = "calendrier/delete.html" success_url = reverse_lazy("calendrier:home") diff --git a/gestion/admin.py b/gestion/admin.py index c937797..79f1e64 100644 --- a/gestion/admin.py +++ b/gestion/admin.py @@ -36,6 +36,7 @@ User.profile_phone = ProfileInfo("phone", "Téléphone") User.profile_instru = ProfileInfo("instru", "Instrument joué") User.profile_is_ern = ProfileInfo("is_ernesto", "Ernestophoniste") User.profile_is_chef = ProfileInfo("is_chef", "Chef Fanfare") +User.profile_is_chef_event = ProfileInfo("is_chef_event", "Respo événement") User.profile_get_mails = ProfileInfo("mails", "Recevoir les mails") @@ -57,6 +58,7 @@ class UserProfileAdmin(UserAdmin): "profile_instru", "profile_is_ern", "profile_is_chef", + "profile_is_chef_event", ] list_display_links = ["username", "email", "first_name", "last_name"] list_filter = ["profile__instru"] diff --git a/gestion/migrations/0007_ernestouser_is_chef_event.py b/gestion/migrations/0007_ernestouser_is_chef_event.py new file mode 100644 index 0000000..9978aa0 --- /dev/null +++ b/gestion/migrations/0007_ernestouser_is_chef_event.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.24 on 2021-10-06 09:09 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('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'), + ), + ] diff --git a/gestion/mixins.py b/gestion/mixins.py index f4469e9..c5967ce 100644 --- a/gestion/mixins.py +++ b/gestion/mixins.py @@ -5,3 +5,10 @@ class ChefRequiredMixin(UserPassesTestMixin): def test_func(self): 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 + return is_chef or is_chef_event diff --git a/gestion/models.py b/gestion/models.py index 5e41990..e098191 100644 --- a/gestion/models.py +++ b/gestion/models.py @@ -81,6 +81,7 @@ 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) is_chef = models.BooleanField(_("Chef Fanfare"), default=False) + is_chef_event = models.BooleanField(_("Respo événements"), 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 a3a4b88..8faaa20 100644 --- a/gestion/templates/gestion/base.html +++ b/gestion/templates/gestion/base.html @@ -66,19 +66,24 @@
- {% if user.is_superuser or user.profile.is_chef %} + {% if user.is_superuser or user.profile.is_chef or user.profile.is_chef_event %}