mirror of
https://gitlab.crans.org/mediatek/med.git
synced 2024-11-27 00:07:12 +00:00
Remove custom add user view
This commit is contained in:
parent
de9650d33a
commit
d1806fd727
@ -26,13 +26,6 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block userlinks %}
|
{% block userlinks %}
|
||||||
{% if user.is_authenticated %}
|
{% 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 %}
|
{% if available_apps %}
|
||||||
{# When in admin site, list all admin pages and documentation #}
|
{# When in admin site, list all admin pages and documentation #}
|
||||||
<span class="dropdown">
|
<span class="dropdown">
|
||||||
@ -45,6 +38,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
<a href="{% url "logs:index" %}">Statistiques</a>
|
||||||
{% if user.is_active and user.is_superuser %}
|
{% if user.is_active and user.is_superuser %}
|
||||||
{% url 'django-admindocs-docroot' as docsroot %}
|
{% url 'django-admindocs-docroot' as docsroot %}
|
||||||
{% if docsroot %}
|
{% if docsroot %}
|
||||||
|
@ -9,6 +9,7 @@ from django.utils.html import format_html
|
|||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from reversion.admin import VersionAdmin
|
from reversion.admin import VersionAdmin
|
||||||
|
|
||||||
|
from .forms import UserCreationAdminForm
|
||||||
from .models import Adhesion, Clef, Request, User
|
from .models import Adhesion, Clef, Request, User
|
||||||
|
|
||||||
|
|
||||||
@ -18,7 +19,7 @@ class RequestAdmin(admin.ModelAdmin):
|
|||||||
|
|
||||||
class ClefAdmin(VersionAdmin):
|
class ClefAdmin(VersionAdmin):
|
||||||
list_display = ('nom', 'proprio', 'commentaire')
|
list_display = ('nom', 'proprio', 'commentaire')
|
||||||
# TODO order by nom
|
ordering = ('nom',)
|
||||||
|
|
||||||
|
|
||||||
class AdhesionAdmin(VersionAdmin):
|
class AdhesionAdmin(VersionAdmin):
|
||||||
@ -60,6 +61,17 @@ class UserAdmin(VersionAdmin, BaseUserAdmin):
|
|||||||
list_filter = (IsAdherentFilter, 'is_staff', 'is_superuser', 'is_active',
|
list_filter = (IsAdherentFilter, 'is_staff', 'is_superuser', 'is_active',
|
||||||
'groups')
|
'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):
|
def is_adherent(self, obj):
|
||||||
"""
|
"""
|
||||||
Get current membership year and check if user is there
|
Get current membership year and check if user is there
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
|
from django.contrib.auth.forms import UsernameField
|
||||||
from django.core.validators import MinLengthValidator
|
from django.core.validators import MinLengthValidator
|
||||||
from django.forms import ModelForm
|
from django.forms import ModelForm
|
||||||
|
|
||||||
@ -35,3 +36,16 @@ class BaseInfoForm(ModelForm):
|
|||||||
'address',
|
'address',
|
||||||
'telephone',
|
'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}
|
||||||
|
@ -46,7 +46,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<div class="submit-row">
|
<div class="submit-row">
|
||||||
<input class="default" type="submit" value="{% trans 'Create or edit' %}">
|
<input class="default" type="submit" value="{% trans 'Save' %}">
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -8,7 +8,6 @@ from . import views
|
|||||||
|
|
||||||
app_name = 'users'
|
app_name = 'users'
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^new_user/$', views.new_user, name='new-user'),
|
|
||||||
url(r'^edit_info/$', views.edit_info, name='edit-info'),
|
url(r'^edit_info/$', views.edit_info, name='edit-info'),
|
||||||
url(r'^adherer/(?P<userid>[0-9]+)$', views.adherer, name='adherer'),
|
url(r'^adherer/(?P<userid>[0-9]+)$', views.adherer, name='adherer'),
|
||||||
url(r'^process/(?P<token>[a-z0-9]{32})/$', views.process, name='process'),
|
url(r'^process/(?P<token>[a-z0-9]{32})/$', views.process, name='process'),
|
||||||
|
@ -62,34 +62,6 @@ def reset_passwd_mail(req, request):
|
|||||||
return
|
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
|
@login_required
|
||||||
def edit_info(request):
|
def edit_info(request):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user