From b4e0bc6502030f5ea91235ea501056b400f41e1d Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 12 Mar 2025 12:12:00 +0100 Subject: 🩹 simplify person wizard - put person types on main form MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ishtar_common/forms_common.py | 43 ++++++++++++------------------------------- 1 file changed, 12 insertions(+), 31 deletions(-) (limited to 'ishtar_common/forms_common.py') diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index 8529e0c24..6a8db2693 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -1155,6 +1155,7 @@ class SimplePersonForm(ManageOldType, NewItemForm): associated_models = { "attached_to": models.Organization, "title": models.TitleType, + "person_types": models.PersonType, # already set for subclass } format_models = { "precise_town_id": models.Town, @@ -1217,13 +1218,13 @@ class SimplePersonForm(ManageOldType, NewItemForm): alt_country = forms.CharField( label=_("Other address: country"), max_length=30, required=False ) + TYPES = [ + FieldType("title", models.TitleType), + ] def __init__(self, *args, **kwargs): - super(SimplePersonForm, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) self.fields["raw_name"].widget.attrs["readonly"] = True - self.fields["title"].choices = models.TitleType.get_types( - initial=self.init_data.get("title") - ) class PersonUserSelect(PersonSelect): @@ -1355,25 +1356,24 @@ class BaseOrganizationPersonForm(forms.ModelForm): class PersonForm(SimplePersonForm): person_types = forms.MultipleChoiceField( - label=_("Person type"), + label=_("Person types"), choices=[], required=False, - widget=forms.CheckboxSelectMultiple, + widget=widgets.Select2Multiple, ) + TYPES = SimplePersonForm.TYPES + [ + FieldType("person_types", models.PersonType, True) + ] def __init__(self, *args, **kwargs): - super(PersonForm, self).__init__(*args, **kwargs) - self.fields["person_types"].choices = models.PersonType.get_types( - initial=self.init_data.get("person_types"), empty_first=False - ) - self.fields["person_types"].help_text = models.PersonType.get_help() + super().__init__(*args, **kwargs) self.limit_fields() def save(self, user, item=None): dct = self.cleaned_data dct["history_modifier"] = user for key in self.associated_models.keys(): - if key in dct: + if key in dct and key != "person_types": if not dct[key]: dct.pop(key) else: @@ -1402,25 +1402,6 @@ class NoOrgaPersonForm(PersonForm): self.fields.pop("attached_to") -class PersonTypeForm(ManageOldType, forms.Form): - form_label = _("Person type") - base_model = "person_type" - associated_models = {"person_type": models.PersonType} - person_type = forms.MultipleChoiceField( - label=_("Person type"), - choices=[], - required=False, - widget=widgets.Select2Multiple, - ) - - def __init__(self, *args, **kwargs): - super(PersonTypeForm, self).__init__(*args, **kwargs) - self.fields["person_type"].choices = models.PersonType.get_types( - initial=self.init_data.get("person_type"), empty_first=False - ) - self.fields["person_type"].help_text = models.PersonType.get_help() - - class BiographicalNoteForm(CustomForm, ManageOldType, NewItemForm): form_label = _("Biographical note") form_admin_name = _("Biographical note - 010 - General") -- cgit v1.2.3