diff --git a/users/templates/users/aff_users.html b/search/templates/search/aff_users.html similarity index 100% rename from users/templates/users/aff_users.html rename to search/templates/search/aff_users.html diff --git a/search/templates/search/index.html b/search/templates/search/index.html index 74c4479..9e516c8 100644 --- a/search/templates/search/index.html +++ b/search/templates/search/index.html @@ -30,7 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc., {% block content %} {% if users_list %}

Résultats dans les utilisateurs

- {% include "users/aff_users.html" with users_list=users_list %} + {% include "search/aff_users.html" with users_list=users_list %} {% endif%} {% if emprunts_list %}

Résultats dans les emprunt :

diff --git a/users/admin.py b/users/admin.py index 0fc53ff..8c23c4c 100644 --- a/users/admin.py +++ b/users/admin.py @@ -4,6 +4,8 @@ from django.contrib import admin from django.contrib.auth.admin import UserAdmin as BaseUserAdmin +from django.core.urlresolvers import reverse +from django.utils.html import format_html from django.utils.translation import ugettext_lazy as _ from reversion.admin import VersionAdmin @@ -54,7 +56,7 @@ class UserAdmin(VersionAdmin, BaseUserAdmin): (_('Important dates'), {'fields': ('last_login', 'date_joined')}), ) list_display = ('username', 'email', 'first_name', 'last_name', - 'maxemprunt', 'is_adherent', 'is_staff') + 'maxemprunt', 'is_adherent', 'is_staff', 'actions_btn') list_filter = (IsAdherentFilter, 'is_staff', 'is_superuser', 'is_active', 'groups') @@ -64,15 +66,33 @@ class UserAdmin(VersionAdmin, BaseUserAdmin): """ 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_member = last_adh_year and obj in last_adh_year.adherent.all() + if is_member: + return format_html( + 'True' + ) + else: + # TODO permit adhere only if perms.users.add_user + return format_html( + 'False ' + '{}', + reverse('users:adherer', args=[obj.pk]), + _('Adhere') + ) - is_adherent.boolean = True is_adherent.short_description = _('is adherent') + is_adherent.allow_tags = True - # 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 %}"> + def actions_btn(self, obj): + # TODO permit adhere only if perms.media.add_emprunt + return format_html( + '{}', + reverse('media:add-emprunt', args=[obj.pk]), + _('Register borrowed item') + ) + + actions_btn.short_description = _('actions') + actions_btn.allow_tags = True admin.site.register(User, UserAdmin) diff --git a/users/forms.py b/users/forms.py index ed6d5b8..6fbf008 100644 --- a/users/forms.py +++ b/users/forms.py @@ -28,10 +28,10 @@ class BaseInfoForm(ModelForm): class Meta: model = User fields = [ - 'first_name', 'username', - 'last_name', 'email', - 'telephone', + 'first_name', + 'last_name', 'address', + 'telephone', ] diff --git a/users/templates/users/user.html b/users/templates/users/user.html index 195f057..b2b3849 100644 --- a/users/templates/users/user.html +++ b/users/templates/users/user.html @@ -1,21 +1,72 @@ -{% extends "base.html" %} +{% extends "admin/base_site.html" %} {% comment %} SPDX-License-Identifier: GPL-3.0-or-later {% endcomment %} -{% load bootstrap3 %} +{% load i18n static %} -{% block title %}Création et modification d'utilisateur{% endblock %} +{% block breadcrumbs %} + +{% endblock %} + +{% block extrahead %}{{ block.super }} + {# Load Django Admin widgets #} + + + {{ form.media }} +{% endblock %} + +{% block extrastyle %}{{ block.super }} + +{% endblock %} {% block content %} - {% bootstrap_form_errors userform %} +
{% csrf_token %} + {% if form.non_field_errors %} +

+ {% for error in form.non_field_errors %} + {{ error }} + {% endfor %} +

+ {% endif %} +
+ {% for field in form %} +
+ {{ field.errors }} +
+ {{ field.label_tag }} + {% if field.is_readonly %} +
{{ field.contents }}
+ {% else %} + {{ field }} + {% endif %} + {% if field.field.help_text %} +
{{ field.field.help_text|safe }}
+ {% endif %} +
+
+ {% endfor %} + {% if password_change %} +
+
+ + +
+
+ {% endif %} +
- - Changer le mot de passe - - - {% csrf_token %} - {% bootstrap_form userform %} - {% bootstrap_button "Créer ou modifier" button_type="submit" icon="star" %} +
+ +
+ + {% endblock %} diff --git a/users/views.py b/users/views.py index 42a27a8..fdedaeb 100644 --- a/users/views.py +++ b/users/views.py @@ -11,14 +11,14 @@ from django.shortcuts import get_object_or_404, redirect, render from django.template import loader from django.template.context_processors import csrf from django.utils import timezone +from django.utils.translation import ugettext_lazy as _ from reversion import revisions as reversion from med.settings import ASSO_EMAIL, ASSO_NAME, EMAIL_FROM, \ REQ_EXPIRE_STR, SITE_NAME -from media.models import Emprunt from users.forms import BaseInfoForm from users.forms import PassForm -from users.models import Adhesion, Request, Right, User +from users.models import Adhesion, Request, User def form(ctx, template, request): @@ -40,7 +40,7 @@ def password_change_action(u_form, user, request, req=False): if req: req.delete() return redirect("/") - return redirect("/users/profil/" + str(user.id)) + return redirect("/") def reset_passwd_mail(req, request): @@ -83,8 +83,11 @@ def new_user(request): "L'utilisateur %s a été crée, un mail pour " "l'initialisation du mot de passe a été " "envoyé" % user.username) - return redirect("/users/profil/" + str(user.id)) - return form({'userform': user}, 'users/user.html', request) + return redirect("/") + return form({ + 'form': user, + 'title': _('New user'), + }, 'users/user.html', request) @login_required @@ -100,8 +103,12 @@ def edit_info(request): 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/") - return form({'userform': user}, 'users/user.html', request) + return redirect("/") + return form({ + 'form': user, + 'password_change': True, + 'title': _('Edit user profile'), + }, 'users/user.html', request) @login_required @@ -112,7 +119,10 @@ def password(request): u_form = PassForm(request.POST or None) if u_form.is_valid(): return password_change_action(u_form, request.user, request) - return form({'userform': u_form}, 'users/user.html', request) + return form({ + 'form': u_form, + 'title': _('Change password'), + }, 'users/user.html', request) @login_required @@ -122,7 +132,7 @@ def adherer(request, userid): users = User.objects.get(pk=userid) except User.DoesNotExist: messages.error(request, "Utilisateur inexistant") - return redirect("/users/") + return redirect("/") adh_year = Adhesion.objects.all().order_by('annee_debut').reverse().first() with transaction.atomic(), reversion.create_revision(): reversion.set_user(request.user) @@ -130,7 +140,7 @@ def adherer(request, userid): adh_year.save() reversion.set_comment("Adhesion de %s" % users) messages.success(request, "Adhesion effectuee") - return redirect("/users/profil/" + userid) + return redirect("/") def process(request, token):