From df2d0d4d4c82f5d0f73f46e76e4c0dc5a8136bfe Mon Sep 17 00:00:00 2001 From: Kenneth SOARES Date: Fri, 28 Mar 2025 12:27:21 +0100 Subject: [PATCH] methode clean dans MergeForm fixed formatting Update rootplace/forms.py Co-authored-by: thomas girod <56346771+imperosol@users.noreply.github.com> Check that a user cannot be merged into itself ajout des traductions changed test language to french Check that a user cannot be merged into itself --- locale/fr/LC_MESSAGES/django.po | 32 ++++++++++++++++------------- locale/fr/LC_MESSAGES/djangojs.po | 3 ++- rootplace/forms.py | 11 ++++++++++ rootplace/tests/test_merge_users.py | 10 +++++++++ 4 files changed, 41 insertions(+), 15 deletions(-) diff --git a/locale/fr/LC_MESSAGES/django.po b/locale/fr/LC_MESSAGES/django.po index 19b164df..a7d0c1ab 100644 --- a/locale/fr/LC_MESSAGES/django.po +++ b/locale/fr/LC_MESSAGES/django.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-02-25 16:38+0100\n" +"POT-Creation-Date: 2025-03-28 13:51+0100\n" "PO-Revision-Date: 2016-07-18\n" "Last-Translator: Maréchal \n" @@ -935,10 +935,6 @@ msgstr "rôle" msgid "description" msgstr "description" -#: club/models.py -msgid "past member" -msgstr "ancien membre" - #: club/models.py msgid "Email address" msgstr "Adresse email" @@ -2837,6 +2833,7 @@ msgid "Users" msgstr "Utilisateurs" #: core/templates/core/search.jinja core/views/user.py +#: counter/templates/counter/product_list.jinja msgid "Clubs" msgstr "Clubs" @@ -3182,7 +3179,7 @@ msgid "Bans" msgstr "Bans" #: core/templates/core/user_tools.jinja counter/forms.py -#: counter/views/mixins.py +#: counter/templates/counter/product_list.jinja counter/views/mixins.py msgid "Counters" msgstr "Comptoirs" @@ -3338,8 +3335,8 @@ msgstr "Nom d'utilisateur, email, ou numéro de compte AE" #: core/views/forms.py msgid "" -"Profile: you need to be visible on the picture, in order to be recognized " -"(e.g. by the barmen)" +"Profile: you need to be visible on the picture, in order to be recognized (e." +"g. by the barmen)" msgstr "" "Photo de profil: vous devez être visible sur la photo afin d'être reconnu " "(par exemple par les barmen)" @@ -3949,8 +3946,8 @@ msgstr "" #: counter/templates/counter/mails/account_dump.jinja msgid "If you think this was a mistake, please mail us at ae@utbm.fr." msgstr "" -"Si vous pensez qu'il s'agit d'une erreur, veuillez envoyer un mail à " -"ae@utbm.fr." +"Si vous pensez qu'il s'agit d'une erreur, veuillez envoyer un mail à ae@utbm." +"fr." #: counter/templates/counter/mails/account_dump.jinja msgid "" @@ -5120,6 +5117,10 @@ msgstr "Utilisateur qui sera conservé" msgid "User that will be deleted" msgstr "Utilisateur qui sera supprimé" +#: rootplace/forms.py +msgid "You cannot merge two identical users." +msgstr "Vous ne pouvez pas fusionner deux utilisateurs identiques." + #: rootplace/forms.py msgid "User to be selected" msgstr "Utilisateur à sélectionner" @@ -5219,15 +5220,15 @@ msgstr "SAS" msgid "Albums" msgstr "Albums" -#: sas/templates/sas/album.jinja -msgid "Download album" -msgstr "Télécharger l'album" - #: sas/templates/sas/album.jinja sas/templates/sas/macros.jinja #: sas/templates/sas/user_pictures.jinja msgid "To be moderated" msgstr "A modérer" +#: sas/templates/sas/album.jinja +msgid "Download album" +msgstr "Télécharger l'album" + #: sas/templates/sas/album.jinja msgid "Upload" msgstr "Envoyer" @@ -6042,3 +6043,6 @@ msgstr "Vous ne pouvez plus écrire de commentaires, la date est passée." #, python-format msgid "Maximum characters: %(max_length)s" msgstr "Nombre de caractères max: %(max_length)s" + +#~ msgid "past member" +#~ msgstr "ancien membre" diff --git a/locale/fr/LC_MESSAGES/djangojs.po b/locale/fr/LC_MESSAGES/djangojs.po index c222636a..9b967354 100644 --- a/locale/fr/LC_MESSAGES/djangojs.po +++ b/locale/fr/LC_MESSAGES/djangojs.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-02-25 16:10+0100\n" +"POT-Creation-Date: 2025-03-28 13:52+0100\n" "PO-Revision-Date: 2024-09-17 11:54+0200\n" "Last-Translator: Sli \n" "Language-Team: AE info \n" @@ -34,6 +34,7 @@ msgid "Delete" msgstr "Supprimer" #: com/static/bundled/com/components/moderation-alert-index.ts +#, javascript-format msgid "" "This event will take place every week for %s weeks. If you publish or delete " "this event, it will also be published (or deleted) for the following weeks." diff --git a/rootplace/forms.py b/rootplace/forms.py index e5796023..850238ac 100644 --- a/rootplace/forms.py +++ b/rootplace/forms.py @@ -1,4 +1,5 @@ from django import forms +from django.core.exceptions import ValidationError from django.utils.translation import gettext_lazy as _ from core.models import User, UserBan @@ -22,6 +23,16 @@ class MergeForm(forms.Form): queryset=User.objects.all(), ) + def clean(self): + cleaned_data = super().clean() + user1 = cleaned_data.get("user1") + user2 = cleaned_data.get("user2") + + if user1.id == user2.id: + raise ValidationError(_("You cannot merge two identical users.")) + + return cleaned_data + class SelectUserForm(forms.Form): user = forms.ModelChoiceField( diff --git a/rootplace/tests/test_merge_users.py b/rootplace/tests/test_merge_users.py index ad66fdd8..2c4c0e03 100644 --- a/rootplace/tests/test_merge_users.py +++ b/rootplace/tests/test_merge_users.py @@ -22,6 +22,7 @@ from django.utils.timezone import localtime, now from club.models import Club from core.models import Group, User from counter.models import Counter, Customer, Product, Refilling, Selling +from rootplace.forms import MergeForm from subscription.models import Subscription @@ -79,6 +80,15 @@ class TestMergeUser(TestCase): sas_admin.id, } + def test_identical_accounts(self): + form = MergeForm(data={"user1": self.to_keep.id, "user2": self.to_keep.id}) + assert not form.is_valid() + assert "__all__" in form.errors + assert ( + "Vous ne pouvez pas fusionner deux utilisateurs identiques." + in form.errors["__all__"] + ) + def test_both_subscribers_and_with_account(self): Customer(user=self.to_keep, account_id="11000l", amount=0).save() Customer(user=self.to_delete, account_id="12000m", amount=0).save()