diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-05-05 15:21:19 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-05-05 15:21:19 +0200 |
commit | a4562858f29d2295ab6abce3ab54c509d7d44533 (patch) | |
tree | d0285b27a87e5cdf52024454a8836bc05b2410e7 /ishtar_common/forms_common.py | |
parent | 020add49f9cb09937cdab0ad77a7a7e1a567f13c (diff) | |
download | Ishtar-a4562858f29d2295ab6abce3ab54c509d7d44533.tar.bz2 Ishtar-a4562858f29d2295ab6abce3ab54c509d7d44533.zip |
Account management - profile: raise an error on profile name duplication
Diffstat (limited to 'ishtar_common/forms_common.py')
-rw-r--r-- | ishtar_common/forms_common.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index b28e40a5c..65d892fc9 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -1090,8 +1090,24 @@ class ProfileForm(ManageOldType): ] +class ProfileFormsetBase(FormSetWithDeleteSwitches): + def clean(self): + values = [] + for data in self.cleaned_data: + if not data.get("profile_type", None): + continue + value = ( + data.get("profile_type", None), + data.get("name", None) + ) + if value in values: + raise forms.ValidationError(_("Choose different name for profiles.")) + values.append(value) + return self.cleaned_data + + ProfileFormset = formset_factory( - ProfileForm, can_delete=True, formset=FormSetWithDeleteSwitches + ProfileForm, can_delete=True, formset=ProfileFormsetBase ) ProfileFormset.form_label = _("Profiles") ProfileFormset.form_admin_name = _("Profiles") |