mirror of
				https://gitlab.crans.org/mediatek/med.git
				synced 2025-11-04 06:22:15 +01:00 
			
		
		
		
	Simplify user profile
This commit is contained in:
		@@ -23,39 +23,31 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 | 
			
		||||
{% endcomment %}
 | 
			
		||||
 | 
			
		||||
{% if revisions_list.paginator %}
 | 
			
		||||
{% include "pagination.html" with list=revisions_list %}
 | 
			
		||||
    {% include "pagination.html" with list=revisions_list %}
 | 
			
		||||
{% endif %}
 | 
			
		||||
 | 
			
		||||
{% load logs_extra %}
 | 
			
		||||
 | 
			
		||||
    <table class="table table-striped">
 | 
			
		||||
        <thead>
 | 
			
		||||
<table class="table table-striped">
 | 
			
		||||
    <thead>
 | 
			
		||||
    <tr>
 | 
			
		||||
        <th>Objet modifié</th>
 | 
			
		||||
        <th>Type de l'objet</th>
 | 
			
		||||
        <th>Modification par</th>
 | 
			
		||||
        <th>Date de modification</th>
 | 
			
		||||
        <th>Commentaire</th>
 | 
			
		||||
        <th></th>
 | 
			
		||||
    </tr>
 | 
			
		||||
    </thead>
 | 
			
		||||
    {% for revision in revisions_list %}
 | 
			
		||||
        {% for reversion in revision.version_set.all %}
 | 
			
		||||
            <tr>
 | 
			
		||||
                <th>Objet modifié</th>
 | 
			
		||||
                <th>Type de l'objet</th>
 | 
			
		||||
                <th>Modification par</th>
 | 
			
		||||
                <th>Date de modification</th>
 | 
			
		||||
                <th>Commentaire</th>
 | 
			
		||||
                <th></th>
 | 
			
		||||
                <td>{{ reversion.object|truncatechars:20 }}</td>
 | 
			
		||||
                <td>{{ reversion.object|classname }}</td>
 | 
			
		||||
                <td>{{ revision.user }}</td>
 | 
			
		||||
                <td>{{ revision.date_created }}</td>
 | 
			
		||||
                <td>{{ revision.comment }}</td>
 | 
			
		||||
            </tr>
 | 
			
		||||
        </thead>
 | 
			
		||||
        {% for revision in revisions_list %}
 | 
			
		||||
        	{% for reversion in revision.version_set.all %}
 | 
			
		||||
		<tr>
 | 
			
		||||
            	    <td>{{ reversion.object|truncatechars:20 }}</td>
 | 
			
		||||
                    <td>{{ reversion.object|classname }}</td>
 | 
			
		||||
                    <td>{{ revision.user }}</td>
 | 
			
		||||
                    <td>{{ revision.date_created }}</td>
 | 
			
		||||
                    <td>{{ revision.comment }}</td>
 | 
			
		||||
                    {% if is_bureau %}
 | 
			
		||||
                    <td>
 | 
			
		||||
                	<a class="btn btn-danger btn-sm" role="button" href="{% url 'logs:revert-action' revision.id %}">
 | 
			
		||||
                    	<i class="glyphicon glyphicon-remove"></i>
 | 
			
		||||
                    	Annuler
 | 
			
		||||
                	</a>
 | 
			
		||||
            	    </td>
 | 
			
		||||
            	    {% endif %}
 | 
			
		||||
        	</tr>
 | 
			
		||||
		{% endfor %}
 | 
			
		||||
        {% endfor %}
 | 
			
		||||
    </table>
 | 
			
		||||
    {% endfor %}
 | 
			
		||||
</table>
 | 
			
		||||
 
 | 
			
		||||
@@ -8,6 +8,5 @@ from . import views
 | 
			
		||||
 | 
			
		||||
urlpatterns = [
 | 
			
		||||
    url(r'^$', views.index, name='index'),
 | 
			
		||||
    url(r'^revert_action/(?P<revision_id>[0-9]+)$', views.revert_action, name='revert-action'),
 | 
			
		||||
    url(r'^stats_actions/$', views.stats_actions, name='stats-actions'),
 | 
			
		||||
]
 | 
			
		||||
 
 | 
			
		||||
@@ -2,11 +2,10 @@
 | 
			
		||||
# Copyright (C) 2017-2019 by BDE ENS Paris-Saclay
 | 
			
		||||
# SPDX-License-Identifier: GPL-3.0-or-later
 | 
			
		||||
 | 
			
		||||
from django.contrib import messages
 | 
			
		||||
from django.contrib.auth.decorators import login_required, permission_required
 | 
			
		||||
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
 | 
			
		||||
from django.db.models import Count
 | 
			
		||||
from django.shortcuts import redirect, render
 | 
			
		||||
from django.shortcuts import render
 | 
			
		||||
from django.template.context_processors import csrf
 | 
			
		||||
from reversion.models import Revision
 | 
			
		||||
 | 
			
		||||
@@ -23,7 +22,8 @@ def form(ctx, template, request):
 | 
			
		||||
@login_required
 | 
			
		||||
@permission_required('perm')
 | 
			
		||||
def index(request):
 | 
			
		||||
    revisions = Revision.objects.all().order_by('date_created').reverse().select_related('user').prefetch_related(
 | 
			
		||||
    revisions = Revision.objects.all().order_by(
 | 
			
		||||
        'date_created').reverse().select_related('user').prefetch_related(
 | 
			
		||||
        'version_set__object')
 | 
			
		||||
    paginator = Paginator(revisions, pagination_number)
 | 
			
		||||
    page = request.GET.get('page')
 | 
			
		||||
@@ -38,27 +38,13 @@ def index(request):
 | 
			
		||||
    return render(request, 'logs/index.html', {'revisions_list': revisions})
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@login_required
 | 
			
		||||
@permission_required('bureau')
 | 
			
		||||
def revert_action(request, revision_id):
 | 
			
		||||
    """ Annule l'action en question """
 | 
			
		||||
    try:
 | 
			
		||||
        revision = Revision.objects.get(id=revision_id)
 | 
			
		||||
    except Revision.DoesNotExist:
 | 
			
		||||
        messages.error(request, u"Revision inexistante")
 | 
			
		||||
    if request.method == "POST":
 | 
			
		||||
        revision.revert()
 | 
			
		||||
        messages.success(request, "L'action a été supprimée")
 | 
			
		||||
        return redirect("/logs/")
 | 
			
		||||
    return form({'objet': revision, 'objet_name': revision.__class__.__name__}, 'logs/delete.html', request)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@login_required
 | 
			
		||||
@permission_required('perm')
 | 
			
		||||
def stats_actions(request):
 | 
			
		||||
    stats = {
 | 
			
		||||
        'Utilisateur': {
 | 
			
		||||
            'Action': User.objects.annotate(num=Count('revision')).order_by('-num')[:40],
 | 
			
		||||
            'Action': User.objects.annotate(num=Count('revision')).order_by(
 | 
			
		||||
                '-num')[:40],
 | 
			
		||||
        },
 | 
			
		||||
    }
 | 
			
		||||
    return render(request, 'logs/stats_users.html', {'stats_list': stats})
 | 
			
		||||
 
 | 
			
		||||
@@ -53,9 +53,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 | 
			
		||||
                    </div>
 | 
			
		||||
                    <div class="collapse navbar-collapse" id="myNavbar">
 | 
			
		||||
                        <ul class="nav navbar-nav">
 | 
			
		||||
                            <li><a href="{% url "users:mon-profil" %}">Mon profil</a></li>
 | 
			
		||||
                            <li><a href="{% url "users:profil" %}">Mon profil</a></li>
 | 
			
		||||
                            {% if is_perm %}
 | 
			
		||||
                            <li><a href="{% url "users:index" %}">Utilisateurs</a></li>
 | 
			
		||||
                            <li><a href="{% url "users:new-user" %}">Utilisateurs</a></li>
 | 
			
		||||
                            {% endif %}
 | 
			
		||||
                            <li><a href="{% url "media:index" %}">Media</a></li>
 | 
			
		||||
                            {% if is_perm %}
 | 
			
		||||
 
 | 
			
		||||
@@ -26,12 +26,12 @@ SPDX-License-Identifier: GPL-3.0-or-later
 | 
			
		||||
        {% endblock %}
 | 
			
		||||
        {% block userlinks %}
 | 
			
		||||
            {# Link to our apps outside of admin #}
 | 
			
		||||
            <a href="{% url "users:mon-profil" %}">{% trans 'My profile' %}</a> /
 | 
			
		||||
            <a href="{% url "users:profil" %}">{% trans 'My profile' %}</a> /
 | 
			
		||||
            <a href="{% url "media:index" %}">Media</a> /
 | 
			
		||||
 | 
			
		||||
            {% if user.is_authenticated %}
 | 
			
		||||
                {% if is_perm %}
 | 
			
		||||
                    <a href="{% url "users:index" %}">Utilisateurs</a> /
 | 
			
		||||
                    <a href="{% url "users:new-user" %}">Nouveau utilisateur</a> /
 | 
			
		||||
                    <a href="{% url "logs:index" %}">Statistiques</a> /
 | 
			
		||||
                {% endif %}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -35,16 +35,3 @@ class BaseInfoForm(ModelForm):
 | 
			
		||||
            'telephone',
 | 
			
		||||
            'address',
 | 
			
		||||
        ]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class InfoForm(BaseInfoForm):
 | 
			
		||||
    class Meta(BaseInfoForm.Meta):
 | 
			
		||||
        fields = [
 | 
			
		||||
            'first_name',
 | 
			
		||||
            'username',
 | 
			
		||||
            'last_name',
 | 
			
		||||
            'email',
 | 
			
		||||
            'telephone',
 | 
			
		||||
            'address',
 | 
			
		||||
            'maxemprunt',
 | 
			
		||||
        ]
 | 
			
		||||
 
 | 
			
		||||
@@ -1,20 +0,0 @@
 | 
			
		||||
{% comment %}
 | 
			
		||||
SPDX-License-Identifier: GPL-3.0-or-later
 | 
			
		||||
{% endcomment %}
 | 
			
		||||
 | 
			
		||||
<table class="table table-striped">
 | 
			
		||||
    <thead>
 | 
			
		||||
    <tr>
 | 
			
		||||
        <th>Clef</th>
 | 
			
		||||
        <th>Propriétaire</th>
 | 
			
		||||
        <th>Commentaire</th>
 | 
			
		||||
    </tr>
 | 
			
		||||
    </thead>
 | 
			
		||||
    {% for clef in clef_list %}
 | 
			
		||||
        <tr>
 | 
			
		||||
            <td>{{ clef.nom }}</td>
 | 
			
		||||
            <td>{{ clef.proprio }}</td>
 | 
			
		||||
            <td>{{ clef.commentaire }}</td>
 | 
			
		||||
        </tr>
 | 
			
		||||
    {% endfor %}
 | 
			
		||||
</table>
 | 
			
		||||
@@ -1,44 +1,23 @@
 | 
			
		||||
{% comment %}
 | 
			
		||||
Re2o est un logiciel d'administration développé initiallement au rezometz. Il
 | 
			
		||||
se veut agnostique au réseau considéré, de manière à être installable en
 | 
			
		||||
quelques clics.
 | 
			
		||||
 | 
			
		||||
Copyright © 2017  Gabriel Détraz
 | 
			
		||||
Copyright © 2017  Goulven Kermarec
 | 
			
		||||
Copyright © 2017  Augustin Lemesle
 | 
			
		||||
 | 
			
		||||
This program is free software; you can redistribute it and/or modify
 | 
			
		||||
it under the terms of the GNU General Public License as published by
 | 
			
		||||
the Free Software Foundation; either version 2 of the License, or
 | 
			
		||||
(at your option) any later version.
 | 
			
		||||
 | 
			
		||||
This program is distributed in the hope that it will be useful,
 | 
			
		||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
GNU General Public License for more details.
 | 
			
		||||
 | 
			
		||||
You should have received a copy of the GNU General Public License along
 | 
			
		||||
with this program; if not, write to the Free Software Foundation, Inc.,
 | 
			
		||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 | 
			
		||||
SPDX-License-Identifier: GPL-3.0-or-later
 | 
			
		||||
{% endcomment %}
 | 
			
		||||
 | 
			
		||||
{% if users_list.paginator %}
 | 
			
		||||
{% include "pagination.html" with list=users_list %} 
 | 
			
		||||
    {% include "pagination.html" with list=users_list %}
 | 
			
		||||
{% endif %}
 | 
			
		||||
 | 
			
		||||
    <table class="table table-striped">
 | 
			
		||||
        <thead>
 | 
			
		||||
            <tr>
 | 
			
		||||
                <th>Prénom</th>
 | 
			
		||||
                <th>Nom</th>
 | 
			
		||||
                <th>Pseudo</th>
 | 
			
		||||
                <th>Mail</th>
 | 
			
		||||
                <th>Max emprunts</th>
 | 
			
		||||
                <th>Adhérent</th>
 | 
			
		||||
                <th>Profil</th>
 | 
			
		||||
            </tr>
 | 
			
		||||
        </thead>
 | 
			
		||||
        {% for user in users_list %}    
 | 
			
		||||
<table class="table table-striped">
 | 
			
		||||
    <thead>
 | 
			
		||||
    <tr>
 | 
			
		||||
        <th>Prénom</th>
 | 
			
		||||
        <th>Nom</th>
 | 
			
		||||
        <th>Pseudo</th>
 | 
			
		||||
        <th>Mail</th>
 | 
			
		||||
        <th>Max emprunts</th>
 | 
			
		||||
        <th>Adhérent</th>
 | 
			
		||||
    </tr>
 | 
			
		||||
    </thead>
 | 
			
		||||
    {% for user in users_list %}
 | 
			
		||||
        <tr>
 | 
			
		||||
            <td>{{ user.first_name }}</td>
 | 
			
		||||
            <td>{{ user.last_name }}</td>
 | 
			
		||||
@@ -46,13 +25,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 | 
			
		||||
            <td>{{ user.email }}</td>
 | 
			
		||||
            <td>{{ user.maxemprunt }}</td>
 | 
			
		||||
            {% if user.is_adherent %}
 | 
			
		||||
            <td><font color="green">Oui</font></td>
 | 
			
		||||
                <td><span style="color:green">Oui</span></td>
 | 
			
		||||
            {% else %}
 | 
			
		||||
            <td><font color="red">Non</font></td>
 | 
			
		||||
                <td><span style="color:red">Non</span></td>
 | 
			
		||||
            {% endif %}
 | 
			
		||||
            <td><a href="{% url "users:profil" user.id%}" class="btn btn-primary btn-sm" role="button"><i class="glyphicon glyphicon-user"></i></a>
 | 
			
		||||
            </td>
 | 
			
		||||
        </tr>
 | 
			
		||||
        {% endfor %}
 | 
			
		||||
    </table>
 | 
			
		||||
    {% endfor %}
 | 
			
		||||
</table>
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,37 +0,0 @@
 | 
			
		||||
{% extends "users/sidebar.html" %}
 | 
			
		||||
{% comment %}
 | 
			
		||||
Re2o est un logiciel d'administration développé initiallement au rezometz. Il
 | 
			
		||||
se veut agnostique au réseau considéré, de manière à être installable en
 | 
			
		||||
quelques clics.
 | 
			
		||||
 | 
			
		||||
Copyright © 2017  Gabriel Détraz
 | 
			
		||||
Copyright © 2017  Goulven Kermarec
 | 
			
		||||
Copyright © 2017  Augustin Lemesle
 | 
			
		||||
 | 
			
		||||
This program is free software; you can redistribute it and/or modify
 | 
			
		||||
it under the terms of the GNU General Public License as published by
 | 
			
		||||
the Free Software Foundation; either version 2 of the License, or
 | 
			
		||||
(at your option) any later version.
 | 
			
		||||
 | 
			
		||||
This program is distributed in the hope that it will be useful,
 | 
			
		||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
GNU General Public License for more details.
 | 
			
		||||
 | 
			
		||||
You should have received a copy of the GNU General Public License along
 | 
			
		||||
with this program; if not, write to the Free Software Foundation, Inc.,
 | 
			
		||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 | 
			
		||||
{% endcomment %}
 | 
			
		||||
 | 
			
		||||
{% load bootstrap3 %}
 | 
			
		||||
 | 
			
		||||
{% block title %}Utilisateurs{% endblock %}
 | 
			
		||||
 | 
			
		||||
{% block content %}
 | 
			
		||||
  <h2>Users</h2>
 | 
			
		||||
  {%  include "users/aff_users.html" with  users_list=users_list %}
 | 
			
		||||
  <br />
 | 
			
		||||
  <br />
 | 
			
		||||
  <br />
 | 
			
		||||
{% endblock %}
 | 
			
		||||
 | 
			
		||||
@@ -1,11 +0,0 @@
 | 
			
		||||
{% extends "users/sidebar.html" %}
 | 
			
		||||
{% comment %}
 | 
			
		||||
SPDX-License-Identifier: GPL-3.0-or-later
 | 
			
		||||
{% endcomment %}
 | 
			
		||||
 | 
			
		||||
{% block title %}Clef{% endblock %}
 | 
			
		||||
 | 
			
		||||
{% block content %}
 | 
			
		||||
  <h2>Liste des clef</h2>
 | 
			
		||||
  {%  include "users/aff_clef.html" with  clef_list=clef_list %}
 | 
			
		||||
{% endblock %}
 | 
			
		||||
@@ -1,26 +1,6 @@
 | 
			
		||||
{% extends "users/sidebar.html" %}
 | 
			
		||||
{% extends "base.html" %}
 | 
			
		||||
{% comment %}
 | 
			
		||||
Re2o est un logiciel d'administration développé initiallement au rezometz. Il
 | 
			
		||||
se veut agnostique au réseau considéré, de manière à être installable en
 | 
			
		||||
quelques clics.
 | 
			
		||||
 | 
			
		||||
Copyright © 2017  Gabriel Détraz
 | 
			
		||||
Copyright © 2017  Goulven Kermarec
 | 
			
		||||
Copyright © 2017  Augustin Lemesle
 | 
			
		||||
 | 
			
		||||
This program is free software; you can redistribute it and/or modify
 | 
			
		||||
it under the terms of the GNU General Public License as published by
 | 
			
		||||
the Free Software Foundation; either version 2 of the License, or
 | 
			
		||||
(at your option) any later version.
 | 
			
		||||
 | 
			
		||||
This program is distributed in the hope that it will be useful,
 | 
			
		||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
GNU General Public License for more details.
 | 
			
		||||
 | 
			
		||||
You should have received a copy of the GNU General Public License along
 | 
			
		||||
with this program; if not, write to the Free Software Foundation, Inc.,
 | 
			
		||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 | 
			
		||||
SPDX-License-Identifier: GPL-3.0-or-later
 | 
			
		||||
{% endcomment %}
 | 
			
		||||
 | 
			
		||||
{% load bootstrap3 %}
 | 
			
		||||
@@ -30,21 +10,17 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 | 
			
		||||
{% block content %}
 | 
			
		||||
    <h2>Compte</h2>
 | 
			
		||||
    <div>
 | 
			
		||||
        <a class="btn btn-primary btn-sm" role="button" href="{% url 'users:edit-info' user.id %}">
 | 
			
		||||
        <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' user.id %}">
 | 
			
		||||
        <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>
 | 
			
		||||
        <a class="btn btn-info btn-sm" role="button" href="{% url 'users:history' 'user' user.id %}">
 | 
			
		||||
            <i class="glyphicon glyphicon-time"></i>
 | 
			
		||||
            Historique
 | 
			
		||||
        </a>
 | 
			
		||||
    </div>
 | 
			
		||||
    <p>
 | 
			
		||||
        <br />
 | 
			
		||||
        <br/>
 | 
			
		||||
    </p>
 | 
			
		||||
    <table class="table table-striped">
 | 
			
		||||
        <tr>
 | 
			
		||||
@@ -76,17 +52,18 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 | 
			
		||||
            <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>
 | 
			
		||||
                <td>{% for droit in list_droits %}{{ droit.right }}{% if list_droits|length != forloop.counter %}  -
 | 
			
		||||
                {% endif %} {% endfor %}</td>
 | 
			
		||||
            {% else %}
 | 
			
		||||
            <td>Aucun</td>
 | 
			
		||||
                <td>Aucun</td>
 | 
			
		||||
            {% endif %}
 | 
			
		||||
        </tr>
 | 
			
		||||
        <tr> 
 | 
			
		||||
           <th>Statut</th>
 | 
			
		||||
        <tr>
 | 
			
		||||
            <th>Statut</th>
 | 
			
		||||
            {% if user.is_active %}
 | 
			
		||||
            <td><font color="green">Actif</font></td>
 | 
			
		||||
                <td><font color="green">Actif</font></td>
 | 
			
		||||
            {% else %}
 | 
			
		||||
            <td><font color="red">Désactivé</font></td>
 | 
			
		||||
                <td><font color="red">Désactivé</font></td>
 | 
			
		||||
            {% endif %}
 | 
			
		||||
            <th>Dernière connexion</th>
 | 
			
		||||
            <td>{{ user.last_login }}</td>
 | 
			
		||||
@@ -94,27 +71,26 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 | 
			
		||||
        <tr>
 | 
			
		||||
            <th>Adherent pour l'année en cours</th>
 | 
			
		||||
            {% if user.is_adherent %}
 | 
			
		||||
            <td><font color="green">Oui</font></td>
 | 
			
		||||
                <td><font color="green">Oui</font></td>
 | 
			
		||||
            {% else %}
 | 
			
		||||
            <td><font color="red">Non</font></td>
 | 
			
		||||
                <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>
 | 
			
		||||
                <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> 
 | 
			
		||||
        </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>
 | 
			
		||||
        <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 %}
 | 
			
		||||
        {% include "media/aff_emprunts.html" with emprunts_list=emprunts_list %}
 | 
			
		||||
    {% else %}
 | 
			
		||||
    <p>Aucun emprunt</p>
 | 
			
		||||
        <p>Aucun emprunt</p>
 | 
			
		||||
    {% endif %}
 | 
			
		||||
    <br />
 | 
			
		||||
    <br />
 | 
			
		||||
    <br />
 | 
			
		||||
{% endblock %}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,48 +0,0 @@
 | 
			
		||||
{% extends "base.html" %}
 | 
			
		||||
{% comment %}
 | 
			
		||||
Re2o est un logiciel d'administration développé initiallement au rezometz. Il
 | 
			
		||||
se veut agnostique au réseau considéré, de manière à être installable en
 | 
			
		||||
quelques clics.
 | 
			
		||||
 | 
			
		||||
Copyright © 2017  Gabriel Détraz
 | 
			
		||||
Copyright © 2017  Goulven Kermarec
 | 
			
		||||
Copyright © 2017  Augustin Lemesle
 | 
			
		||||
 | 
			
		||||
This program is free software; you can redistribute it and/or modify
 | 
			
		||||
it under the terms of the GNU General Public License as published by
 | 
			
		||||
the Free Software Foundation; either version 2 of the License, or
 | 
			
		||||
(at your option) any later version.
 | 
			
		||||
 | 
			
		||||
This program is distributed in the hope that it will be useful,
 | 
			
		||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
GNU General Public License for more details.
 | 
			
		||||
 | 
			
		||||
You should have received a copy of the GNU General Public License along
 | 
			
		||||
with this program; if not, write to the Free Software Foundation, Inc.,
 | 
			
		||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 | 
			
		||||
{% endcomment %}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
{% block sidebar %}
 | 
			
		||||
        {% if is_bureau %}
 | 
			
		||||
        <a class="list-group-item list-group-item-success" href="{% url "users:new-user" %}">
 | 
			
		||||
            <i class="glyphicon glyphicon-plus"></i>
 | 
			
		||||
            Créer un adhérent
 | 
			
		||||
        </a>
 | 
			
		||||
        {% endif %}
 | 
			
		||||
        {% if is_perm %}
 | 
			
		||||
        <a class="list-group-item list-group-item-info" href="{% url "users:index" %}">
 | 
			
		||||
            <i class="glyphicon glyphicon-list"></i>
 | 
			
		||||
            Utilisateurs dans la base
 | 
			
		||||
        </a>
 | 
			
		||||
        <a class="list-group-item list-group-item-info" href="{% url "users:index-ajour" %}">
 | 
			
		||||
            <i class="glyphicon glyphicon-list"></i>
 | 
			
		||||
            Adhérents
 | 
			
		||||
        </a>
 | 
			
		||||
        <a class="list-group-item list-group-item-info" href="{% url "users:index-clef" %}">
 | 
			
		||||
            <i class="glyphicon glyphicon-list"></i>
 | 
			
		||||
            Clef
 | 
			
		||||
        </a>
 | 
			
		||||
    {% endif %}
 | 
			
		||||
{% endblock %}
 | 
			
		||||
@@ -1,26 +1,6 @@
 | 
			
		||||
{% extends "users/sidebar.html" %}
 | 
			
		||||
{% extends "base.html" %}
 | 
			
		||||
{% comment %}
 | 
			
		||||
Re2o est un logiciel d'administration développé initiallement au rezometz. Il
 | 
			
		||||
se veut agnostique au réseau considéré, de manière à être installable en
 | 
			
		||||
quelques clics.
 | 
			
		||||
 | 
			
		||||
Copyright © 2017  Gabriel Détraz
 | 
			
		||||
Copyright © 2017  Goulven Kermarec
 | 
			
		||||
Copyright © 2017  Augustin Lemesle
 | 
			
		||||
 | 
			
		||||
This program is free software; you can redistribute it and/or modify
 | 
			
		||||
it under the terms of the GNU General Public License as published by
 | 
			
		||||
the Free Software Foundation; either version 2 of the License, or
 | 
			
		||||
(at your option) any later version.
 | 
			
		||||
 | 
			
		||||
This program is distributed in the hope that it will be useful,
 | 
			
		||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
GNU General Public License for more details.
 | 
			
		||||
 | 
			
		||||
You should have received a copy of the GNU General Public License along
 | 
			
		||||
with this program; if not, write to the Free Software Foundation, Inc.,
 | 
			
		||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 | 
			
		||||
SPDX-License-Identifier: GPL-3.0-or-later
 | 
			
		||||
{% endcomment %}
 | 
			
		||||
 | 
			
		||||
{% load bootstrap3 %}
 | 
			
		||||
@@ -28,14 +8,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 | 
			
		||||
{% block title %}Création et modification d'utilisateur{% endblock %}
 | 
			
		||||
 | 
			
		||||
{% block content %}
 | 
			
		||||
{% bootstrap_form_errors userform %}
 | 
			
		||||
    {% bootstrap_form_errors userform %}
 | 
			
		||||
 | 
			
		||||
<form class="form" method="post">
 | 
			
		||||
    {% csrf_token %}
 | 
			
		||||
    {% bootstrap_form userform %}
 | 
			
		||||
    {% bootstrap_button "Créer ou modifier" button_type="submit" icon="star" %}
 | 
			
		||||
</form>
 | 
			
		||||
  <br />
 | 
			
		||||
  <br />
 | 
			
		||||
  <br />
 | 
			
		||||
    <form class="form" method="post">
 | 
			
		||||
        {% csrf_token %}
 | 
			
		||||
        {% bootstrap_form userform %}
 | 
			
		||||
        {% bootstrap_button "Créer ou modifier" button_type="submit" icon="star" %}
 | 
			
		||||
    </form>
 | 
			
		||||
{% endblock %}
 | 
			
		||||
 
 | 
			
		||||
@@ -9,15 +9,9 @@ from . import views
 | 
			
		||||
app_name = 'users'
 | 
			
		||||
urlpatterns = [
 | 
			
		||||
    url(r'^new_user/$', views.new_user, name='new-user'),
 | 
			
		||||
    url(r'^edit_info/(?P<userid>[0-9]+)$', views.edit_info,
 | 
			
		||||
        name='edit-info'),
 | 
			
		||||
    url(r'^password/(?P<userid>[0-9]+)$', views.password,
 | 
			
		||||
        name='password'),
 | 
			
		||||
    url(r'^profil/(?P<userid>[0-9]+)$', views.profil, name='profil'),
 | 
			
		||||
    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'^mon_profil/$', views.mon_profil, name='mon-profil'),
 | 
			
		||||
    url(r'^index_clef/$', views.index_clef, name='index-clef'),
 | 
			
		||||
    url(r'^process/(?P<token>[a-z0-9]{32})/$', views.process, name='process'),
 | 
			
		||||
    url(r'^$', views.index, name='index'),
 | 
			
		||||
    url(r'^index_ajour/$', views.index_ajour, name='index-ajour'),
 | 
			
		||||
]
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										124
									
								
								users/views.py
									
									
									
									
									
								
							
							
						
						
									
										124
									
								
								users/views.py
									
									
									
									
									
								
							@@ -5,7 +5,6 @@
 | 
			
		||||
from django.contrib import messages
 | 
			
		||||
from django.contrib.auth.decorators import login_required, permission_required
 | 
			
		||||
from django.core.mail import send_mail
 | 
			
		||||
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
 | 
			
		||||
from django.core.urlresolvers import reverse
 | 
			
		||||
from django.db import transaction
 | 
			
		||||
from django.shortcuts import get_object_or_404, redirect, render
 | 
			
		||||
@@ -15,11 +14,11 @@ from django.utils import timezone
 | 
			
		||||
from reversion import revisions as reversion
 | 
			
		||||
 | 
			
		||||
from med.settings import ASSO_EMAIL, ASSO_NAME, EMAIL_FROM, \
 | 
			
		||||
    PAGINATION_NUMBER, REQ_EXPIRE_STR, SITE_NAME
 | 
			
		||||
    REQ_EXPIRE_STR, SITE_NAME
 | 
			
		||||
from media.models import Emprunt
 | 
			
		||||
from users.forms import BaseInfoForm, InfoForm
 | 
			
		||||
from users.forms import BaseInfoForm
 | 
			
		||||
from users.forms import PassForm
 | 
			
		||||
from users.models import Adhesion, Clef, Request, Right, User
 | 
			
		||||
from users.models import Adhesion, Request, Right, User
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def form(ctx, template, request):
 | 
			
		||||
@@ -64,7 +63,7 @@ def reset_passwd_mail(req, request):
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@login_required
 | 
			
		||||
@permission_required('bureau')
 | 
			
		||||
@permission_required('users.add_user')
 | 
			
		||||
def new_user(request):
 | 
			
		||||
    """
 | 
			
		||||
    Vue de création d'un nouvel utilisateur
 | 
			
		||||
@@ -89,26 +88,11 @@ def new_user(request):
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@login_required
 | 
			
		||||
def edit_info(request, userid):
 | 
			
		||||
def edit_info(request):
 | 
			
		||||
    """
 | 
			
		||||
    Edite un utilisateur à partir de son id,
 | 
			
		||||
    si l'id est différent de request.user,
 | 
			
		||||
    vérifie la possession du droit admin
 | 
			
		||||
    Edite son utilisateur
 | 
			
		||||
    """
 | 
			
		||||
    try:
 | 
			
		||||
        user = User.objects.get(pk=userid)
 | 
			
		||||
    except User.DoesNotExist:
 | 
			
		||||
        messages.error(request, "Utilisateur inexistant")
 | 
			
		||||
        return redirect("/users/")
 | 
			
		||||
    if not request.user.has_perms(('bureau',)) and user != request.user:
 | 
			
		||||
        messages.error(request,
 | 
			
		||||
                       "Vous ne pouvez pas modifier un autre user que vous "
 | 
			
		||||
                       "sans droit admin")
 | 
			
		||||
        return redirect("/users/profil/" + str(request.user.id))
 | 
			
		||||
    if not request.user.has_perms(('bureau',)):
 | 
			
		||||
        user = BaseInfoForm(request.POST or None, instance=user)
 | 
			
		||||
    else:
 | 
			
		||||
        user = InfoForm(request.POST or None, instance=user)
 | 
			
		||||
    user = BaseInfoForm(request.POST or None, instance=request.user)
 | 
			
		||||
    if user.is_valid():
 | 
			
		||||
        with transaction.atomic(), reversion.create_revision():
 | 
			
		||||
            user.save()
 | 
			
		||||
@@ -116,99 +100,33 @@ def edit_info(request, userid):
 | 
			
		||||
            reversion.set_comment("Champs modifié(s) : %s" % ', '.join(
 | 
			
		||||
                field for field in user.changed_data))
 | 
			
		||||
        messages.success(request, "L'user a bien été modifié")
 | 
			
		||||
        return redirect("/users/profil/" + userid)
 | 
			
		||||
        return redirect("/users/profil/")
 | 
			
		||||
    return form({'userform': user}, 'users/user.html', request)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@login_required
 | 
			
		||||
def password(request, userid):
 | 
			
		||||
    """ Reinitialisation d'un mot de passe à partir de l'userid,
 | 
			
		||||
    pour self par défaut, pour tous sans droit si droit admin,
 | 
			
		||||
    pour tous si droit bureau """
 | 
			
		||||
    try:
 | 
			
		||||
        user = User.objects.get(pk=userid)
 | 
			
		||||
    except User.DoesNotExist:
 | 
			
		||||
        messages.error(request, "Utilisateur inexistant")
 | 
			
		||||
        return redirect("/users/")
 | 
			
		||||
    if not request.user.has_perms(('bureau',)) and user != request.user:
 | 
			
		||||
        messages.error(request,
 | 
			
		||||
                       "Vous ne pouvez pas modifier un autre user que vous "
 | 
			
		||||
                       "sans droit admin")
 | 
			
		||||
        return redirect("/users/profil/" + str(request.user.id))
 | 
			
		||||
def password(request):
 | 
			
		||||
    """
 | 
			
		||||
    Reinitialisation d'un mot de passe
 | 
			
		||||
    """
 | 
			
		||||
    u_form = PassForm(request.POST or None)
 | 
			
		||||
    if u_form.is_valid():
 | 
			
		||||
        return password_change_action(u_form, user, request)
 | 
			
		||||
        return password_change_action(u_form, request.user, request)
 | 
			
		||||
    return form({'userform': u_form}, 'users/user.html', request)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@login_required
 | 
			
		||||
@permission_required('perm')
 | 
			
		||||
def index_clef(request):
 | 
			
		||||
    clef_list = Clef.objects.all().order_by('nom')
 | 
			
		||||
    return render(request, 'users/index_clef.html', {'clef_list': clef_list})
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@login_required
 | 
			
		||||
@permission_required('perm')
 | 
			
		||||
def index(request):
 | 
			
		||||
    """ Affiche l'ensemble des users, need droit admin """
 | 
			
		||||
    users_list = User.objects.order_by('first_name')
 | 
			
		||||
    paginator = Paginator(users_list, PAGINATION_NUMBER)
 | 
			
		||||
    page = request.GET.get('page')
 | 
			
		||||
    try:
 | 
			
		||||
        users_list = paginator.page(page)
 | 
			
		||||
    except PageNotAnInteger:
 | 
			
		||||
        # If page is not an integer, deliver first page.
 | 
			
		||||
        users_list = paginator.page(1)
 | 
			
		||||
    except EmptyPage:
 | 
			
		||||
        # If page is out of range (e.g. 9999), deliver last page of results.
 | 
			
		||||
        users_list = paginator.page(paginator.num_pages)
 | 
			
		||||
    return render(request, 'users/index.html', {'users_list': users_list})
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@login_required
 | 
			
		||||
@permission_required('perm')
 | 
			
		||||
def index_ajour(request):
 | 
			
		||||
    """ Affiche l'ensemble des users, need droit admin """
 | 
			
		||||
    users_list = Adhesion.objects.all().order_by(
 | 
			
		||||
        'annee_debut').reverse().first().adherent.all().order_by('first_name')
 | 
			
		||||
    paginator = Paginator(users_list, PAGINATION_NUMBER)
 | 
			
		||||
    page = request.GET.get('page')
 | 
			
		||||
    try:
 | 
			
		||||
        users_list = paginator.page(page)
 | 
			
		||||
    except PageNotAnInteger:
 | 
			
		||||
        # If page is not an integer, deliver first page.
 | 
			
		||||
        users_list = paginator.page(1)
 | 
			
		||||
    except EmptyPage:
 | 
			
		||||
        # If page is out of range (e.g. 9999), deliver last page of results.
 | 
			
		||||
        users_list = paginator.page(paginator.num_pages)
 | 
			
		||||
    return render(request, 'users/index.html', {'users_list': users_list})
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@login_required
 | 
			
		||||
def mon_profil(request):
 | 
			
		||||
    return redirect("/users/profil/" + str(request.user.id))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@login_required
 | 
			
		||||
def profil(request, userid):
 | 
			
		||||
    try:
 | 
			
		||||
        users = User.objects.get(pk=userid)
 | 
			
		||||
    except User.DoesNotExist:
 | 
			
		||||
        messages.error(request, "Utilisateur inexistant")
 | 
			
		||||
        return redirect("/users/")
 | 
			
		||||
    if not request.user.has_perms(('perm',)) and users != request.user:
 | 
			
		||||
        messages.error(request,
 | 
			
		||||
                       "Vous ne pouvez pas afficher un autre user "
 | 
			
		||||
                       "que vous sans droit perm")
 | 
			
		||||
        return redirect("/users/profil/" + str(request.user.id))
 | 
			
		||||
    emprunts_list = Emprunt.objects.filter(user=users)
 | 
			
		||||
    list_droits = Right.objects.filter(user=users)
 | 
			
		||||
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': users,
 | 
			
		||||
            'user': request.user,
 | 
			
		||||
            'emprunts_list': emprunts_list,
 | 
			
		||||
            'list_droits': list_droits,
 | 
			
		||||
        }
 | 
			
		||||
@@ -216,7 +134,7 @@ def profil(request, userid):
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@login_required
 | 
			
		||||
@permission_required('bureau')
 | 
			
		||||
@permission_required('users.add_adhesion')
 | 
			
		||||
def adherer(request, userid):
 | 
			
		||||
    try:
 | 
			
		||||
        users = User.objects.get(pk=userid)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user