diff --git a/users/forms.py b/users/forms.py index 8aa2ffe7..a47c1436 100644 --- a/users/forms.py +++ b/users/forms.py @@ -379,6 +379,18 @@ class FullClubForm(ClubForm): ] +class ClubAdminandMembersForm(ModelForm): + """Permet d'éditer la liste des membres et des administrateurs + d'un club""" + class Meta: + model = Club + fields = ['administrators', 'members'] + + def __init__(self, *args, **kwargs): + prefix = kwargs.pop('prefix', self.Meta.model.__name__) + super(ClubAdminandMembersForm, self).__init__(*args, prefix=prefix, **kwargs) + + class PasswordForm(ModelForm): """ Formulaire de changement brut de mot de passe. Ne pas utiliser sans traitement""" diff --git a/users/migrations/0060_auto_20171120_0317.py b/users/migrations/0060_auto_20171120_0317.py new file mode 100644 index 00000000..a77b24db --- /dev/null +++ b/users/migrations/0060_auto_20171120_0317.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2017-11-20 02:17 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0059_auto_20171025_1854'), + ] + + operations = [ + migrations.AddField( + model_name='club', + name='administrators', + field=models.ManyToManyField(blank=True, related_name='club_administrator', to='users.Adherent'), + ), + migrations.AddField( + model_name='club', + name='members', + field=models.ManyToManyField(blank=True, related_name='club_members', to='users.Adherent'), + ), + ] diff --git a/users/models.py b/users/models.py index 54500f4e..fae011d6 100644 --- a/users/models.py +++ b/users/models.py @@ -60,7 +60,10 @@ from django.core.mail import send_mail from django.core.urlresolvers import reverse from django.db import transaction from django.utils import timezone -from django.contrib.auth.models import AbstractBaseUser, BaseUserManager +from django.contrib.auth.models import ( + AbstractBaseUser, + BaseUserManager +) from django.core.validators import RegexValidator from reversion import revisions as reversion @@ -771,6 +774,7 @@ class Adherent(User): pass + class Club(User): PRETTY_NAME = "Clubs" room = models.ForeignKey( @@ -779,6 +783,17 @@ class Club(User): blank=True, null=True ) + administrators = models.ManyToManyField( + blank=True, + to='users.Adherent', + related_name='club_administrator' + ) + members = models.ManyToManyField( + blank=True, + to='users.Adherent', + related_name='club_members' + ) + pass diff --git a/users/templates/users/profil.html b/users/templates/users/profil.html index 253ab86d..fb9e37d9 100644 --- a/users/templates/users/profil.html +++ b/users/templates/users/profil.html @@ -141,21 +141,61 @@ with this program; if not, write to the Free Software Foundation, Inc., {{ user.shell }} {% endif %} -

Machines :

+ {% if user.is_class_club %} + + + Gérer admin et membres + +

Administrateurs du club

+ + + + + + + + + {% for admin in user.club.administrators.all %} + + + + + + {% endfor %} +
NomPrenomPseudo
{{ admin.surname }}{{ admin.name }}{{ admin.pseudo }}
+

Membres

+ + + + + + + + + {% for admin in user.club.members.all %} + + + + + + {% endfor %} +
NomPrenomPseudo
{{ admin.surname }}{{ admin.name }}{{ admin.pseudo }}
+ {% endif %} +

Machines

Ajouter une machine

{% if machines_list %} {% include "machines/aff_machines.html" with machines_list=machines_list %} {% else %}

Aucune machine

{% endif %} -

Cotisations :

+

Cotisations

{% if is_cableur %}

Ajouter une cotisation {% if user_solde %} Modifier le solde{% endif%}

{% endif%} {% if facture_list %} {% include "cotisations/aff_cotisations.html" with facture_list=facture_list %} {% else %}

Aucune facture

{% endif %} -

Bannissements :

+

Bannissements

{% if is_bofh %}

Ajouter un bannissement

{% endif %} {% if ban_list %} {% include "users/aff_bans.html" with ban_list=ban_list %} diff --git a/users/templates/users/user.html b/users/templates/users/user.html index ad6ddb64..bf1bef0f 100644 --- a/users/templates/users/user.html +++ b/users/templates/users/user.html @@ -33,7 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% csrf_token %} - {% massive_bootstrap_form userform 'room,school' %} + {% massive_bootstrap_form userform 'room,school,administrators,members' %} {% bootstrap_button "Créer ou modifier" button_type="submit" icon="star" %}

diff --git a/users/urls.py b/users/urls.py index e351dcca..e669a0d9 100644 --- a/users/urls.py +++ b/users/urls.py @@ -33,6 +33,11 @@ urlpatterns = [ url(r'^new_user/$', views.new_user, name='new-user'), url(r'^new_club/$', views.new_club, name='new-club'), url(r'^edit_info/(?P[0-9]+)$', views.edit_info, name='edit-info'), + url( + r'^edit_club_admin_members/(?P[0-9]+)$', + views.edit_club_admin_members, + name='edit-club-admin-members' + ), url(r'^state/(?P[0-9]+)$', views.state, name='state'), url(r'^password/(?P[0-9]+)$', views.password, name='password'), url(r'^new_serviceuser/$', views.new_serviceuser, name='new-serviceuser'), diff --git a/users/views.py b/users/views.py index 5cbe462e..9aa51b5e 100644 --- a/users/views.py +++ b/users/views.py @@ -53,14 +53,40 @@ from rest_framework.renderers import JSONRenderer from reversion.models import Version from reversion import revisions as reversion from users.serializers import MailSerializer -from users.models import User, Right, Ban, Whitelist, School, ListRight -from users.models import Request, ServiceUser, Adherent, Club -from users.forms import DelRightForm, BanForm, WhitelistForm, DelSchoolForm -from users.forms import DelListRightForm, NewListRightForm, FullAdherentForm -from users.forms import StateForm, FullClubForm -from users.forms import RightForm, SchoolForm, EditServiceUserForm -from users.forms import ServiceUserForm, ListRightForm, AdherentForm, ClubForm -from users.forms import MassArchiveForm, PassForm, ResetPasswordForm +from users.models import ( + User, + Right, + Ban, + Whitelist, + School, + ListRight, + Request, + ServiceUser, + Adherent, + Club +) +from users.forms import ( + DelRightForm, + BanForm, + WhitelistForm, + DelSchoolForm, + DelListRightForm, + NewListRightForm, + FullAdherentForm, + StateForm, + FullClubForm, + RightForm, + SchoolForm, + EditServiceUserForm, + ServiceUserForm, + ListRightForm, + AdherentForm, + ClubForm, + MassArchiveForm, + PassForm, + ResetPasswordForm, + ClubAdminandMembersForm +) from cotisations.models import Facture from machines.models import Machine from preferences.models import OptionalUser, GeneralOption @@ -128,6 +154,38 @@ def new_club(request): return form({'userform': club}, 'users/user.html', request) +@login_required +def edit_club_admin_members(request, clubid): + """Vue d'edition de la liste des users administrateurs et + membres d'un club""" + try: + club_instance = Club.objects.get(pk=clubid) + except Club.DoesNotExist: + messages.error(request, "Club inexistant") + return redirect(reverse('users:index')) + if not request.user.has_perms(('cableur',))\ + and not request.user in club_instance.administrators.all(): + messages.error(request, "Vous ne pouvez pas accéder à ce menu") + return redirect(reverse( + 'users:profil', + kwargs={'userid':str(request.user.id)} + )) + club = ClubAdminandMembersForm(request.POST or None, instance=club_instance) + if club.is_valid(): + with transaction.atomic(), reversion.create_revision(): + club.save() + reversion.set_user(request.user) + reversion.set_comment("Champs modifié(s) : %s" % ', '.join( + field for field in club.changed_data + )) + messages.success(request, "Le club a bien été modifié") + return redirect(reverse( + 'users:profil', + kwargs={'userid':str(club_instance.id)} + )) + return form({'userform': club}, 'users/user.html', request) + + def select_user_edit_form(request, user): """Fonction de choix du bon formulaire, en fonction de: - droit