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
This commit is contained in:
Kenneth SOARES
2025-03-28 12:27:21 +01:00
parent ac1e40038e
commit df2d0d4d4c
4 changed files with 41 additions and 15 deletions

View File

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