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

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