diff --git a/theme/templates/admin/base_site.html b/theme/templates/admin/base_site.html
index 8ec9ce8..02fe48a 100644
--- a/theme/templates/admin/base_site.html
+++ b/theme/templates/admin/base_site.html
@@ -26,13 +26,6 @@ SPDX-License-Identifier: GPL-3.0-or-later
{% endblock %}
{% block userlinks %}
{% if user.is_authenticated %}
- {% if perms.users.add_user %}
- Nouveau utilisateur /
- {% endif %}
- {% if user.is_staff %}
- Statistiques /
- {% endif %}
-
{% if available_apps %}
{# When in admin site, list all admin pages and documentation #}
@@ -45,6 +38,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
{% endif %}
{% endfor %}
{% endfor %}
+ Statistiques
{% if user.is_active and user.is_superuser %}
{% url 'django-admindocs-docroot' as docsroot %}
{% if docsroot %}
diff --git a/users/admin.py b/users/admin.py
index 8c23c4c..c043ea3 100644
--- a/users/admin.py
+++ b/users/admin.py
@@ -9,6 +9,7 @@ from django.utils.html import format_html
from django.utils.translation import ugettext_lazy as _
from reversion.admin import VersionAdmin
+from .forms import UserCreationAdminForm
from .models import Adhesion, Clef, Request, User
@@ -18,7 +19,7 @@ class RequestAdmin(admin.ModelAdmin):
class ClefAdmin(VersionAdmin):
list_display = ('nom', 'proprio', 'commentaire')
- # TODO order by nom
+ ordering = ('nom',)
class AdhesionAdmin(VersionAdmin):
@@ -60,6 +61,17 @@ class UserAdmin(VersionAdmin, BaseUserAdmin):
list_filter = (IsAdherentFilter, 'is_staff', 'is_superuser', 'is_active',
'groups')
+ # Customize required initial fields
+ add_form_template = 'admin/change_form.html'
+ add_form = UserCreationAdminForm
+ add_fieldsets = (
+ (None, {
+ 'classes': ('wide',),
+ 'fields': ("username", "email", "first_name", "last_name",
+ "address", "telephone"),
+ }),
+ )
+
def is_adherent(self, obj):
"""
Get current membership year and check if user is there
diff --git a/users/forms.py b/users/forms.py
index 6fbf008..b7518c0 100644
--- a/users/forms.py
+++ b/users/forms.py
@@ -3,6 +3,7 @@
# SPDX-License-Identifier: GPL-3.0-or-later
from django import forms
+from django.contrib.auth.forms import UsernameField
from django.core.validators import MinLengthValidator
from django.forms import ModelForm
@@ -35,3 +36,16 @@ class BaseInfoForm(ModelForm):
'address',
'telephone',
]
+
+
+class UserCreationAdminForm(ModelForm):
+ """
+ A form that creates a user, with no privileges,
+ from the given information.
+ """
+
+ class Meta:
+ model = User
+ fields = ("username", "email", "first_name", "last_name", "address",
+ "telephone")
+ field_classes = {'username': UsernameField}
diff --git a/users/templates/users/user.html b/users/templates/users/user.html
index d537797..d2d075f 100644
--- a/users/templates/users/user.html
+++ b/users/templates/users/user.html
@@ -46,7 +46,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
-
+
{% endblock %}
diff --git a/users/urls.py b/users/urls.py
index 4695864..0a44a03 100644
--- a/users/urls.py
+++ b/users/urls.py
@@ -8,7 +8,6 @@ from . import views
app_name = 'users'
urlpatterns = [
- url(r'^new_user/$', views.new_user, name='new-user'),
url(r'^edit_info/$', views.edit_info, name='edit-info'),
url(r'^adherer/(?P[0-9]+)$', views.adherer, name='adherer'),
url(r'^process/(?P[a-z0-9]{32})/$', views.process, name='process'),
diff --git a/users/views.py b/users/views.py
index 1070cd9..f095e9d 100644
--- a/users/views.py
+++ b/users/views.py
@@ -62,34 +62,6 @@ def reset_passwd_mail(req, request):
return
-@login_required
-@permission_required('users.add_user')
-def new_user(request):
- """
- Vue de création d'un nouvel utilisateur
- """
- user = BaseInfoForm(request.POST or None)
- if user.is_valid():
- user = user.save(commit=False)
- with transaction.atomic(), reversion.create_revision():
- user.save()
- reversion.set_comment("Création")
- req = Request()
- req.type = Request.PASSWD
- req.user = user
- req.save()
- reset_passwd_mail(req, request)
- messages.success(request,
- "L'utilisateur %s a été crée, un mail pour "
- "l'initialisation du mot de passe a été "
- "envoyé" % user.username)
- return redirect("/")
- return form({
- 'form': user,
- 'title': _('New user'),
- }, 'users/user.html', request)
-
-
@login_required
def edit_info(request):
"""