1
0
mirror of https://gitlab.crans.org/mediatek/med.git synced 2025-06-29 19:51:08 +02:00

Continue to remove old perm system

This commit is contained in:
Alexandre Iooss
2019-08-08 19:16:54 +02:00
parent deb28aa93b
commit d0086c84e8
28 changed files with 423 additions and 695 deletions

View File

@ -7,17 +7,13 @@ from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from django.utils.translation import ugettext_lazy as _
from reversion.admin import VersionAdmin
from .models import Adhesion, Clef, ListRight, Request, Right, User
from .models import Adhesion, Clef, Request, User
class RequestAdmin(admin.ModelAdmin):
list_display = ('user', 'type', 'created_at', 'expires_at')
class RightAdmin(VersionAdmin):
list_display = ('user', 'right')
class ClefAdmin(VersionAdmin):
list_display = ('nom', 'proprio', 'commentaire')
# TODO order by nom
@ -27,10 +23,6 @@ class AdhesionAdmin(VersionAdmin):
list_display = ('annee_debut', 'annee_fin')
class ListRightAdmin(VersionAdmin):
list_display = ('listright',)
class IsAdherentFilter(admin.SimpleListFilter):
title = _('adherent status')
parameter_name = 'is_adherent'
@ -44,7 +36,7 @@ class IsAdherentFilter(admin.SimpleListFilter):
value = self.value()
if value == 'Yes':
# Get current membership year and list all members
last_adh_year = Adhesion.objects.all().order_by('annee_debut')\
last_adh_year = Adhesion.objects.all().order_by('annee_debut') \
.reverse().first()
return last_adh_year.adherent
return queryset
@ -70,17 +62,20 @@ class UserAdmin(VersionAdmin, BaseUserAdmin):
"""
Get current membership year and check if user is there
"""
last_adh_year = Adhesion.objects.all().order_by('annee_debut')\
last_adh_year = Adhesion.objects.all().order_by('annee_debut') \
.reverse().first()
return last_adh_year and obj in last_adh_year.adherent.all()
is_adherent.boolean = True
is_adherent.short_description = _('is adherent')
# TODO {% if not user.is_adherent and perms.users.add_user %}
# {% url 'users:adherer' user.id %}
# TODO {% if perms.media.add_emprunt %}
# {% url 'media:add-emprunt' user.id %}">
admin.site.register(User, UserAdmin)
admin.site.register(Request, RequestAdmin)
admin.site.register(ListRight, ListRightAdmin)
admin.site.register(Right, RightAdmin)
admin.site.register(Adhesion, AdhesionAdmin)
admin.site.register(Clef, ClefAdmin)

View File

@ -41,14 +41,6 @@ class User(AbstractUser):
REQUIRED_FIELDS = ['first_name', 'last_name', 'email']
def has_perms(self, perms, obj=None):
for perm in perms:
try:
Right.objects.get(user=self, right__listright=perm)
return True
except Right.DoesNotExist:
return False
@property
def is_adherent(self):
last_adh_year = Adhesion.objects.all().order_by(

View File

@ -1,96 +0,0 @@
{% extends "base.html" %}
{% comment %}
SPDX-License-Identifier: GPL-3.0-or-later
{% endcomment %}
{% load bootstrap3 %}
{% block title %}Profil{% endblock %}
{% block content %}
<h2>Compte</h2>
<div>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'users:edit-info' %}">
<i class="glyphicon glyphicon-edit"></i>
Editer
</a>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'users:password' %}">
<i class="glyphicon glyphicon-lock"></i>
Changer le mot de passe
</a>
</div>
<p>
<br/>
</p>
<table class="table table-striped">
<tr>
<th>Prénom</th>
<td>{{ user.first_name }}</td>
<th>Nom</th>
<td>{{ user.last_name }}</td>
</tr>
<tr>
<th>Pseudo</th>
<td>{{ user.username }}</td>
<th>E-mail</th>
<td>{{ user.email }}</td>
</tr>
<tr>
<th>Commentaire</th>
<td>{{ user.comment }}</td>
<th>Date d'inscription</th>
<td>{{ user.date_joined }}</td>
</tr>
<tr>
<th>Adresse</th>
<td>{{ user.address }}</td>
<th>Telephone</th>
<td>{{ user.telephone }}</td>
</tr>
<tr>
<th>Emprunts maximums autorisés</th>
<td>{{ user.maxemprunt }}</td>
<th>Droits</th>
{% if list_droits %}
<td>{% for droit in list_droits %}{{ droit.right }}{% if list_droits|length != forloop.counter %} -
{% endif %} {% endfor %}</td>
{% else %}
<td>Aucun</td>
{% endif %}
</tr>
<tr>
<th>Statut</th>
{% if user.is_active %}
<td><font color="green">Actif</font></td>
{% else %}
<td><font color="red">Désactivé</font></td>
{% endif %}
<th>Dernière connexion</th>
<td>{{ user.last_login }}</td>
</tr>
<tr>
<th>Adherent pour l'année en cours</th>
{% if user.is_adherent %}
<td><font color="green">Oui</font></td>
{% else %}
<td><font color="red">Non</font></td>
{% endif %}
{% if not user.is_adherent and is_bureau %}
<th></th>
<td><a class="btn btn-primary btn-sm" role="button" href="{% url 'users:adherer' user.id %}"><i
class="glyphicon glyphicon-flag"></i> Adhérer</a></td>
{% endif %}
</tr>
</table>
<h2>Emprunts</h2>
{% if is_perm or is_bureau %}
<h4><a class="btn btn-primary btn-sm" role="button" href="{% url 'media:add-emprunt' user.id %}"><i
class="glyphicon glyphicon-flag"></i> Ajouter</a></h4>
{% endif %}
{% if emprunts_list %}
{% include "media/aff_emprunts.html" with emprunts_list=emprunts_list %}
{% else %}
<p>Aucun emprunt</p>
{% endif %}
{% endblock %}

View File

@ -10,6 +10,9 @@ SPDX-License-Identifier: GPL-3.0-or-later
{% block content %}
{% bootstrap_form_errors userform %}
<a href="{% url 'users:password' %}">
Changer le mot de passe
</a>
<form class="form" method="post">
{% csrf_token %}
{% bootstrap_form userform %}

View File

@ -11,7 +11,6 @@ urlpatterns = [
url(r'^new_user/$', views.new_user, name='new-user'),
url(r'^edit_info/$', views.edit_info, name='edit-info'),
url(r'^password/$', views.password, name='password'),
url(r'^profil/$', views.profil, name='profil'),
url(r'^adherer/(?P<userid>[0-9]+)$', views.adherer, name='adherer'),
url(r'^process/(?P<token>[a-z0-9]{32})/$', views.process, name='process'),
]

View File

@ -115,24 +115,6 @@ def password(request):
return form({'userform': u_form}, 'users/user.html', request)
@login_required
def profil(request):
"""
Voir son profil
"""
emprunts_list = Emprunt.objects.filter(user=request.user)
list_droits = Right.objects.filter(user=request.user)
return render(
request,
'users/profil.html',
{
'user': request.user,
'emprunts_list': emprunts_list,
'list_droits': list_droits,
}
)
@login_required
@permission_required('users.add_adhesion')
def adherer(request, userid):