summaryrefslogtreecommitdiff
path: root/ishtar_common/forms_common.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/forms_common.py')
-rw-r--r--ishtar_common/forms_common.py43
1 files changed, 12 insertions, 31 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")