1
0
mirror of https://gitlab.crans.org/mediatek/med.git synced 2024-11-26 20:47:10 +00:00

Remove custom add user view

This commit is contained in:
Alexandre Iooss 2019-08-09 22:52:47 +02:00
parent de9650d33a
commit d1806fd727
No known key found for this signature in database
GPG Key ID: 6C79278F3FCDCC02
6 changed files with 29 additions and 38 deletions

View File

@ -26,13 +26,6 @@ SPDX-License-Identifier: GPL-3.0-or-later
{% endblock %}
{% block userlinks %}
{% if user.is_authenticated %}
{% if perms.users.add_user %}
<a href="{% url "users:new-user" %}">Nouveau utilisateur</a> /
{% endif %}
{% if user.is_staff %}
<a href="{% url "logs:index" %}">Statistiques</a> /
{% endif %}
{% if available_apps %}
{# When in admin site, list all admin pages and documentation #}
<span class="dropdown">
@ -45,6 +38,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
{% endif %}
{% endfor %}
{% endfor %}
<a href="{% url "logs:index" %}">Statistiques</a>
{% if user.is_active and user.is_superuser %}
{% url 'django-admindocs-docroot' as docsroot %}
{% if docsroot %}

View File

@ -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

View File

@ -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}

View File

@ -46,7 +46,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
</fieldset>
<div class="submit-row">
<input class="default" type="submit" value="{% trans 'Create or edit' %}">
<input class="default" type="submit" value="{% trans 'Save' %}">
</div>
</form>
{% endblock %}

View File

@ -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<userid>[0-9]+)$', views.adherer, name='adherer'),
url(r'^process/(?P<token>[a-z0-9]{32})/$', views.process, name='process'),

View File

@ -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):
"""