1
0
mirror of https://gitlab.crans.org/mediatek/med.git synced 2025-06-21 01:18:21 +02:00

Django upgrade

This commit is contained in:
Alexandre Iooss
2019-08-10 10:44:17 +02:00
parent 80055771e9
commit a6dc8653af
19 changed files with 240 additions and 137 deletions

View File

@ -0,0 +1,5 @@
# -*- mode: python; coding: utf-8 -*-
# Copyright (C) 2017-2019 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
default_app_config = 'users.apps.UsersConfig'

View File

@ -6,19 +6,20 @@ from django.contrib import admin
from django.contrib import messages
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from django.contrib.auth.forms import PasswordResetForm
from django.core.urlresolvers import reverse
from django.urls import reverse
from django.utils.html import format_html
from django.utils.translation import ugettext_lazy as _
from reversion.admin import VersionAdmin
from med.admin import admin_site
from .forms import UserCreationAdminForm
from .models import Adhesion, Clef, User
from med.admin import admin_site
class ClefAdmin(VersionAdmin):
list_display = ('nom', 'proprio', 'commentaire')
ordering = ('nom',)
search_fields = ('nom', 'proprio', 'commentaire')
class AdhesionAdmin(VersionAdmin):

19
users/apps.py Normal file
View File

@ -0,0 +1,19 @@
# -*- mode: python; coding: utf-8 -*-
# Copyright (C) 2017-2019 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from django.apps import AppConfig
from django.conf import settings
from django.db.models.signals import post_save
from django.utils.translation import ugettext_lazy as _
from .signals import add_to_default_group
class UsersConfig(AppConfig):
name = 'users'
verbose_name = _('users')
def ready(self):
post_save.connect(add_to_default_group,
sender=settings.AUTH_USER_MODEL)

View File

@ -44,6 +44,12 @@ class UserCreationAdminForm(ModelForm):
from the given information.
"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['email'].required = True
self.fields['first_name'].required = True
self.fields['last_name'].required = True
class Meta:
model = User
fields = ("username", "email", "first_name", "last_name", "address",

View File

@ -3,7 +3,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-08-09 23:09+0200\n"
"POT-Creation-Date: 2019-08-10 10:21+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -13,71 +13,71 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
#: admin.py:32
#: admin.py:29
msgid "adherent status"
msgstr "statut adhérent"
#: admin.py:37
#: admin.py:34
msgid "Yes"
msgstr ""
#: admin.py:54
#: admin.py:51
msgid "Personal info"
msgstr ""
#: admin.py:56
#: admin.py:53
msgid "Permissions"
msgstr ""
#: admin.py:59
#: admin.py:56
msgid "Important dates"
msgstr ""
#: admin.py:89
#: admin.py:86
msgid "An email to set the password was sent."
msgstr "Un mail pour initialiser le mot de passe a été envoyé."
#: admin.py:92
#: admin.py:89
msgid "The email is invalid."
msgstr "L'adresse mail est invalide."
#: admin.py:111
#: admin.py:108
msgid "Adhere"
msgstr "Adhérer"
#: admin.py:114
#: admin.py:111
msgid "is adherent"
msgstr "statut adhérent"
#: admin.py:122
#: admin.py:119
msgid "Register borrowed item"
msgstr "Enregistrer emprunt"
#: admin.py:125
#: admin.py:122
msgid "actions"
msgstr "actions"
#: models.py:18
#: models.py:14
msgid "phone number"
msgstr "numéro de téléphone"
#: models.py:24
#: models.py:20
msgid "address"
msgstr "adresse"
#: models.py:30
#: models.py:26
msgid "maximum borrowed"
msgstr "emprunts maximal"
#: models.py:31
#: models.py:27
msgid "Maximal amount of simultaneous borrowed item authorized."
msgstr "Nombre maximal d'objets empruntés en même temps."
#: models.py:36
#: models.py:32
msgid "comment"
msgstr "commentaire"
#: models.py:37
#: models.py:33
msgid "Promotion..."
msgstr ""

View File

@ -0,0 +1,18 @@
# Generated by Django 2.2.4 on 2019-08-10 08:03
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('users', '0027_auto_20190809_2317'),
]
operations = [
migrations.AlterField(
model_name='user',
name='last_name',
field=models.CharField(blank=True, max_length=150, verbose_name='last name'),
),
]

14
users/signals.py Normal file
View File

@ -0,0 +1,14 @@
# -*- mode: python; coding: utf-8 -*-
# Copyright (C) 2017-2019 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
def add_to_default_group(sender, **kwargs):
"""
When creating a new user, add it to users group
"""
user = kwargs["instance"]
if kwargs["created"]:
from django.contrib.auth.models import Group
group, group_created = Group.objects.get_or_create(name='users')
user.groups.add(group)

View File

@ -33,7 +33,7 @@ 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("/")
return redirect("index")
return form({
'form': user,
'password_change': True,
@ -48,12 +48,15 @@ def adherer(request, userid):
users = User.objects.get(pk=userid)
except User.DoesNotExist:
messages.error(request, "Utilisateur inexistant")
return redirect("/")
return redirect("admin:users_user_changelist")
adh_year = Adhesion.objects.all().order_by('annee_debut').reverse().first()
if not adh_year:
messages.error(request, "Année d'adhésion non définie")
return redirect("admin:users_user_changelist")
with transaction.atomic(), reversion.create_revision():
reversion.set_user(request.user)
adh_year.adherent.add(users)
adh_year.save()
reversion.set_comment("Adhesion de %s" % users)
messages.success(request, "Adhesion effectuee")
return redirect("/")
return redirect("admin:users_user_changelist")