From e538ac34869c0f57f96269376b744923fa4aad9e Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Mon, 18 Dec 2023 16:18:06 +0100 Subject: 🐛 account form: set profile_type to readonly in order to prevent some errors on deletion (refs #5696) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ishtar_common/forms_common.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'ishtar_common') 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): -- cgit v1.2.3