diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2025-03-12 12:12:00 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2025-03-13 15:48:10 +0100 |
commit | b4e0bc6502030f5ea91235ea501056b400f41e1d (patch) | |
tree | 10c1c9a5a69e04512cefd02d80f406e38d36573d | |
parent | d2c9fab7e330f3c5db660ee65af8db5c9d41370b (diff) | |
download | Ishtar-b4e0bc6502030f5ea91235ea501056b400f41e1d.tar.bz2 Ishtar-b4e0bc6502030f5ea91235ea501056b400f41e1d.zip |
🩹 simplify person wizard - put person types on main form
-rw-r--r-- | ishtar_common/forms_common.py | 43 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/wizard/wizard_person.html | 5 | ||||
-rw-r--r-- | ishtar_common/views.py | 6 |
3 files changed, 17 insertions, 37 deletions
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") diff --git a/ishtar_common/templates/ishtar/wizard/wizard_person.html b/ishtar_common/templates/ishtar/wizard/wizard_person.html index b760c027f..ed4100cb4 100644 --- a/ishtar_common/templates/ishtar/wizard/wizard_person.html +++ b/ishtar_common/templates/ishtar/wizard/wizard_person.html @@ -21,11 +21,12 @@ <div class="card-body form-row"> {% bs_field wizard.form.surname 1 %} {% bs_field wizard.form.name 1 %} + {% bs_field wizard.form.person_types %} + {% bs_field wizard.form.raw_name %} {% bs_field wizard.form.title %} {% bs_field wizard.form.salutation %} - {% bs_field wizard.form.raw_name %} - {% bs_field wizard.form.email %} {% bs_field wizard.form.attached_to %} + {% bs_field wizard.form.email %} </div> </div> diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 69e93a24f..4c83fd818 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -359,8 +359,7 @@ person_search_wizard = wizards.PersonSearch.as_view( person_creation_wizard = wizards.PersonWizard.as_view( [ - ("identity-person_creation", forms.SimplePersonForm), - ("person_type-person_creation", forms.PersonTypeForm), + ("identity-person_creation", forms.PersonForm), ("final-person_creation", FinalForm), ], label=_("New person"), @@ -370,8 +369,7 @@ person_creation_wizard = wizards.PersonWizard.as_view( person_modification_wizard = wizards.PersonModifWizard.as_view( [ ("selec-person_modification", forms.PersonFormSelection), - ("identity-person_modification", forms.SimplePersonForm), - ("person_type-person_creation", forms.PersonTypeForm), + ("identity-person_modification", forms.PersonForm), ("final-person_modification", FinalForm), ], label=_("Person modification"), |