diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2023-12-18 16:18:06 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2023-12-18 16:23:11 +0100 |
commit | e538ac34869c0f57f96269376b744923fa4aad9e (patch) | |
tree | 21ab5bb5811ce759d2d070a9e1f7fc1a82255bd4 /ishtar_common | |
parent | 0bffd12daeb9dfee4fb8365d0dca645e7e735c8a (diff) | |
download | Ishtar-e538ac34869c0f57f96269376b744923fa4aad9e.tar.bz2 Ishtar-e538ac34869c0f57f96269376b744923fa4aad9e.zip |
🐛 account form: set profile_type to readonly in order to prevent some errors on deletion (refs #5696)
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/forms_common.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index a4a77c8f7..197b5a03c 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -1306,6 +1306,18 @@ class ProfileForm(ManageOldType): FieldType("area", models.Area, is_multiple=True), ] + def __init__(self, *args, **kwargs): + profile_type = None + initial = kwargs.get("initial", None) + if initial and "profile_type" in initial: + profile_type = initial.get("profile_type") + super().__init__(*args, **kwargs) + if profile_type: + self.fields["profile_type"].widget.choices = [ + (k, v) for k, v in self.fields["profile_type"].widget.choices if profile_type == str(k) + ] + self.fields["profile_type"].widget.attrs.update({"readonly": True}) + class ProfileFormsetBase(FormSetWithDeleteSwitches): def clean(self): |