new respos

This commit is contained in:
Lucie Galland 2021-10-23 11:16:07 +02:00
parent 662764b581
commit d7fd5e5537
14 changed files with 125 additions and 48 deletions

View file

@ -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)

View file

@ -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"))

View file

@ -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'),
),
]

View file

@ -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

View file

@ -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,

View file

@ -67,7 +67,7 @@
</div>
</li>
{% 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 %}
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="{% url 'chef' %}" id="navbardrop" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<b>{% trans 'Le pouvoir des cheff·e·s'%}</b>
@ -81,9 +81,13 @@
<a class="dropdown-item" href="{% url 'actu:liste' %}">{% trans "Modifier les actualités" %}</a>
<a class="dropdown-item" href="{% url 'liste_photo' %}">{% trans "Modifier les photos" %}</a>
<a class="dropdown-item" href="{% url 'liste_video' %}">{% trans "Modifier les vidéos" %}</a>
{% endif %}
{% if user.profile.is_chef_event %}
{% elif user.profile.is_chef_event %}
<a class="dropdown-item" href="{% url 'calendrier:create_event' %}">{% trans "Ajouter un événement" %}</a>
{% elif user.profile.is_chef_com %}
<a class="dropdown-item" href="{% url 'liste_photo' %}">{% trans "Modifier les photos" %}</a>
<a class="dropdown-item" href="{% url 'liste_video' %}">{% trans "Modifier les vidéos" %}</a>
{% endif %}
</div>

View file

@ -10,11 +10,20 @@
<div class="6u 12u$(small)">
<h2>{% trans "Le pouvoir des cheff·e·s" %} :</h2>
<ul>
{% if user.profile.is_chef or user.is_superuser %}
<li> <a href="/admin/">{% trans "Administration" %}</a></li>
<li> <a href="{% url 'calendrier:create_event' %}">{% trans "Ajouter un événement" %}</a></li>
{% endif %}
{% if user.profile.is_chef %}
<li><a href="{% url 'actu:liste' %}">{% trans "Modifier les actualités" %}</a></li>
{% endif %}
{% if user.profile.is_chef or user.profile.is_chef_event%}
<li> <a href="{% url 'calendrier:create_event' %}">{% trans "Ajouter un événement" %}</a></li>
{% endif %}
{% if user.profile.is_chef or user.profile.is_chef_com%}
<li><a href="{% url 'liste_photo' %}">{% trans "Modifier les photos" %}</a></li>
<li><a href="{% url 'liste_video' %}">{% trans "Modifier les vidéos" %}</a></li>
{% endif %}
</ul>
</div>

View file

@ -16,12 +16,13 @@ import os
from calendrier.forms import ChangeDoodleName
from gestion.forms import (ChangeFormUser, ChangeMembreForm,
InscriptionMembreForm, RegistrationFormUser)
from gestion.mixins import ChefRequiredMixin
from gestion.mixins import ChefRequiredMixin, AllChefRequiredMixin, ChefComRequiredMixin
from gestion.models import ErnestoUser, Photo, VideoGallery
from partitions.models import Category
def generer(*args):
caracteres = string.ascii_letters + string.digits
aleatoire = [random.choice(caracteres) for i in range(6)]
return "".join(aleatoire)
@ -75,7 +76,7 @@ class Profil(LoginRequiredMixin, TemplateView):
template_name = "gestion/profile.html"
class Chef(ChefRequiredMixin, TemplateView):
class Chef(AllChefRequiredMixin, TemplateView):
template_name = "gestion/chef.html"
@ -204,14 +205,14 @@ class Inscription(TemplateView):
return render(request, self.template_name, context)
class PhotoList(ChefRequiredMixin, ListView):
class PhotoList(ChefComRequiredMixin, ListView):
model = Photo
context_object_name = "photos"
ordering = "cat"
template_name = "gestion/photo.html"
class PhotoCreate(ChefRequiredMixin, CreateView):
class PhotoCreate(ChefComRequiredMixin, CreateView):
model = Photo
fields = ["name", "cat", "auteur", "url", "color", "image"]
template_name = "gestion/create_photo.html"
@ -223,27 +224,27 @@ class PhotoCreate(ChefRequiredMixin, CreateView):
return HttpResponseRedirect(self.success_url)
class PhotoUpdate(ChefRequiredMixin, UpdateView):
class PhotoUpdate(ChefComRequiredMixin, UpdateView):
model = Photo
fields = ["name", "cat", "auteur", "url", "color", "image"]
template_name = "gestion/update_photo.html"
success_url = reverse_lazy("liste_photo")
class PhotoDelete(ChefRequiredMixin, DeleteView):
class PhotoDelete(ChefComRequiredMixin, DeleteView):
model = Photo
template_name = "gestion/delete_photo.html"
success_url = reverse_lazy("liste_photo")
class VideoList(ChefRequiredMixin, ListView):
class VideoList(ChefComRequiredMixin, ListView):
model = VideoGallery
ordering = "order"
context_object_name = "videos"
template_name = "gestion/video.html"
class VideoCreate(ChefRequiredMixin, CreateView):
class VideoCreate(ChefComRequiredMixin, CreateView):
model = VideoGallery
fields = ["name", "url", "order"]
template_name = "gestion/create_video.html"
@ -255,14 +256,14 @@ class VideoCreate(ChefRequiredMixin, CreateView):
return HttpResponseRedirect(self.success_url)
class VideoUpdate(ChefRequiredMixin, UpdateView):
class VideoUpdate(ChefComRequiredMixin, UpdateView):
model = VideoGallery
fields = ["name", "url", "order"]
template_name = "gestion/update_video.html"
success_url = reverse_lazy("liste_video")
class VideoDelete(ChefRequiredMixin, DeleteView):
class VideoDelete(ChefComRequiredMixin, DeleteView):
model = VideoGallery
template_name = "gestion/delete_video.html"
success_url = reverse_lazy("liste_video")

View file

@ -21,7 +21,7 @@
<div class="icon fa-copyright" style="color:#000000"> Lucas Gierzack</div></div>
{% endif %}
</span>
{% if user.profile.is_chef %}
{% if user.profile.is_chef or user.profile.is_chef_instru %}
<a href="{% url "instruments:ajouter_instru" %}" class="button alt big">{% trans "Ajouter un instrument" %}</a>
{% endif %}
<p></p>
@ -44,7 +44,7 @@
<td> {{ instrument.etat }} </td>
<td>
<a href="{% url "instruments:fiche_instru" instrument.id %}" class="button small">{% trans "Consulter" %}<a/>
{% if user.profile.is_chef %}
{% if user.profile.is_chef or user.profile.is_chef_instru %}
<a href="{% url "instruments:delete_instru" instrument.id %}" class="button small">{% trans "Supprimer" %}
{% endif %}
@ -81,7 +81,7 @@
<td> {{ instrument.etat}} </td>
<td>
<a href="{% url "instruments:fiche_instru" instrument.id %}" class="button small">{% trans "Consulter" %}<a/>
{% if user.profile.is_chef %}
{% if user.profile.is_chef or user.profile.is_chef_instru %}
<a href="{% url "instruments:delete_instru" instrument.id %}" class="button small">{% trans "Supprimer" %}
{% endif %}

View file

@ -22,7 +22,7 @@
{% trans "Modele : "%} {% if instru.model %}{{instru.model}} {% else %}-{% endif %}<br>
{% trans "Numéro de série : "%} {% if instru.serial %}{{instru.serial}}{% else %}-{% endif %} <br>
{% trans "Prix : "%} {% if instru.prix %}{{instru.prix}} {% else %}-{% endif %}<br>
{% trans "Acheté·e en" %}{% if instru.annee %}{{annee}}{% else %}-{% endif %}
{% trans "Acheté·e en" %}{% if instru.annee %}{{annee}}{% else %}-{% endif %}
</p>
{% if infos or infos_en %}
@ -35,7 +35,7 @@
{% if suppression %}
<p>{{ suppression }}</p>
{% endif %}
{% if not user.profile.is_chef %}
{% if not user.profile.is_chef or not user.profile.is_chef_instru %}
</div>
<div class="5u 12u$(small)">
{% endif %}
@ -66,7 +66,7 @@
{% endifequal %} </td>
<td> {{ rep.prix }} </td>
<td> {{ rep.lieux }} </td>
{% if user.profile.is_chef %}
{%if user.profile.is_chef or user.profile.is_chef_instru %}
<td>
<a href="{% url "instruments:update_rep" rep.id %}" class="button small">{% trans "Modifier" %}</a>
<a href="{% url "instruments:delete_rep" rep.id %}" class="button small">{% trans "Supprimer" %}</a>
@ -80,13 +80,13 @@
</div>
<p>
<a class='button ' href="{% url "instruments:liste" %}">Retour aux instruments</a>
{% if user.profile.is_chef %}
{% if user.profile.is_chef or user.profile.is_chef_instru %}
<a class='button ' href="{% url "instruments:ajouter_rep" instru.id %}">Ajouter une réparation</a>
{% endif %}
</p>
</div>
{% if user.profile.is_chef %}
{% if user.profile.is_chef or user.profile.is_chef_instru %}
<div class="5u 12u$(small)">
<div class="info_part">

View file

@ -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
from gestion.mixins import ChefRequiredMixin, ChefInstruRequiredMixin
from gestion.models import Photo
from instruments.forms import ChefEditInstrumentForm, ChefReparationForm
from instruments.models import Instrument, Reparation
@ -26,14 +26,14 @@ class ListeInstru(LoginRequiredMixin, TemplateView):
return context
class CreateInstru(ChefRequiredMixin, CreateView):
class CreateInstru(ChefInstruRequiredMixin, CreateView):
model = Instrument
fields = ["owner","user", "etat", "type", "marque", "model", "serial", "annee", "prix"]
template_name = "instruments/create_instru.html"
success_url = reverse_lazy("instruments:liste")
class CreateRep(ChefRequiredMixin, TemplateView):
class CreateRep(ChefInstruRequiredMixin, TemplateView):
form_class = ChefReparationForm
template_name = "instruments/create_rep.html"
@ -57,7 +57,7 @@ class CreateRep(ChefRequiredMixin, TemplateView):
return render(request, self.template_name, context)
class DeleteRep(ChefRequiredMixin, TemplateView):
class DeleteRep(ChefInstruRequiredMixin, TemplateView):
model = Reparation
template_name = "instruments/delete_instru.html"
@ -103,7 +103,7 @@ class FicheInstru(LoginRequiredMixin, TemplateView):
return render(request, self.template_name, context)
class UpdateRep(ChefRequiredMixin, UpdateView):
class UpdateRep(ChefInstruRequiredMixin, UpdateView):
model = Reparation
fields = ["date", "description", "description_en", "prix", "lieux"]
template_name = "instruments/update_rep.html"
@ -113,7 +113,7 @@ class UpdateRep(ChefRequiredMixin, UpdateView):
return reverse_lazy("instruments:fiche_instru", kwargs={"pk": id_instru})
class DeleteInstru(ChefRequiredMixin, DeleteView):
class DeleteInstru(ChefInstruRequiredMixin, DeleteView):
model = Instrument
template_name = "instruments/delete_instru.html"
success_url = reverse_lazy("instruments:liste")

View file

@ -15,5 +15,5 @@
</form>
</div>
</section>
</siv>
</div>
{% endblock %}

View file

@ -9,7 +9,7 @@
<div class="inner">
<h4>{% trans "Liste des pads :" %}</h4>
{% if user.profile.is_chef %}
{% if user.profile.is_chef_event or user.profile.is_chef %}
<p><a href="{% url "pads:add" %}" class="button">{% trans "Ajouter un pad" %}</a></p>
{% endif %}
@ -17,7 +17,7 @@
{% for p in pads %}
<li>
<a class="fichier" href="{{ p.url }}" target="_blank">{{ p.nom }}</a>
{% if user.profile.is_chef %}
{% if user.profile.is_chef_event or user.profile.is_chef %}
&nbsp <a class="button alt" href="{% url "pads:edit" p.id %}">{% trans "Modifier" %}</a>
&nbsp <a class="button alt" href="{% url "pads:delete" p.id %}">{% trans "Supprimer" %}</a>
{% endif %}

View file

@ -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")