summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2025-05-02 11:07:32 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2025-05-02 11:07:32 +0200
commite3b68d0240cc3af1d68f4807ac8eceb8e9c908cd (patch)
treece4f68ce1455d108b2336ea502bba51483388d0d
parent369f7d3c12afbdbe3f61f8fecee59d2478bb73ab (diff)
downloadIshtar-e3b68d0240cc3af1d68f4807ac8eceb8e9c908cd.tar.bz2
Ishtar-e3b68d0240cc3af1d68f4807ac8eceb8e9c908cd.zip
🚑️ person wizard: fix person creation
-rw-r--r--ishtar_common/forms_common.py13
-rw-r--r--ishtar_common/templates/ishtar/wizard/wizard_person.html2
-rw-r--r--ishtar_common/tests.py35
-rw-r--r--ishtar_common/views.py9
4 files changed, 49 insertions, 10 deletions
diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py
index 963527e6f..e1711fe29 100644
--- a/ishtar_common/forms_common.py
+++ b/ishtar_common/forms_common.py
@@ -1152,10 +1152,13 @@ class PersonMergeIntoForm(MergeIntoForm):
class SimplePersonForm(ManageOldType, NewItemForm):
extra_form_modals = ["organization"]
form_label = _("Identity")
+ base_models = [
+ "person_type"
+ ]
associated_models = {
"attached_to": models.Organization,
"title": models.TitleType,
- "person_types": models.PersonType, # already set for subclass
+ "person_type": models.PersonType, # already set for subclass
}
format_models = {
"precise_town_id": models.Town,
@@ -1355,14 +1358,14 @@ class BaseOrganizationPersonForm(forms.ModelForm):
class PersonForm(SimplePersonForm):
- person_types = forms.MultipleChoiceField(
+ person_type = forms.MultipleChoiceField(
label=_("Person types"),
choices=[],
required=False,
widget=widgets.Select2Multiple(attrs={"cols": True, "full-width": True}),
)
TYPES = SimplePersonForm.TYPES + [
- FieldType("person_types", models.PersonType, True)
+ FieldType("person_type", models.PersonType, True)
]
def __init__(self, *args, **kwargs):
@@ -1373,7 +1376,7 @@ class PersonForm(SimplePersonForm):
dct = self.cleaned_data
dct["history_modifier"] = user
for key in self.associated_models.keys():
- if key in dct and key != "person_types":
+ if key in dct and key != "person_type":
if not dct[key]:
dct.pop(key)
else:
@@ -1382,7 +1385,7 @@ class PersonForm(SimplePersonForm):
dct[key] = model.objects.get(pk=dct[key])
except model.DoesNotExist:
dct.pop(key)
- person_types = dct.pop("person_types")
+ person_types = dct.pop("person_type")
if not item:
new_item = models.Person.objects.create(**dct)
else:
diff --git a/ishtar_common/templates/ishtar/wizard/wizard_person.html b/ishtar_common/templates/ishtar/wizard/wizard_person.html
index ed4100cb4..4baa9b6cd 100644
--- a/ishtar_common/templates/ishtar/wizard/wizard_person.html
+++ b/ishtar_common/templates/ishtar/wizard/wizard_person.html
@@ -21,7 +21,7 @@
<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.person_type %}
{% bs_field wizard.form.raw_name %}
{% bs_field wizard.form.title %}
{% bs_field wizard.form.salutation %}
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py
index 5692c9863..8fd5ac9e1 100644
--- a/ishtar_common/tests.py
+++ b/ishtar_common/tests.py
@@ -4307,6 +4307,41 @@ class NewItems(TestCase):
self.assertEqual(person.author.count(), 1)
+class PersonWizardTest(WizardTest, TestCase):
+ fixtures = [
+ FIXTURE_AUTH_PATH + "fixtures/initial_data-auth-fr.json",
+ LIB_BASE_PATH + "ishtar_common/fixtures/initial_data-fr.json",
+ ]
+ url_name = "person_creation"
+ wizard_name = "person_wizard"
+ steps = views.person_creation_wizard_steps
+ model = models.Person
+ redirect_url = "/person_modification/selec-person_modification?open_item={last_id}"
+ form_datas = [
+ WizardTestFormData(
+ "Add a person",
+ form_datas={
+ "identity": {
+ "surname": "Forname",
+ "name": "name",
+ "title": None,
+ "person_types": [],
+ }
+ },
+ ),
+ ]
+
+ def pre_wizard(self):
+ self.number = models.Person.objects.count()
+ super().pre_wizard()
+
+ def post_wizard(self):
+ self.assertEqual(models.Person.objects.count(), self.number + 1)
+ person = models.Person.objects.order_by("-pk").all()[0]
+ self.assertEqual(person.surname, "Forname")
+ self.assertEqual(person.name, "name")
+
+
class AccountWizardTest(WizardTest, TestCase):
fixtures = [
FIXTURE_AUTH_PATH + "fixtures/initial_data-auth-fr.json",
diff --git a/ishtar_common/views.py b/ishtar_common/views.py
index 4a487ab90..af2cf3a98 100644
--- a/ishtar_common/views.py
+++ b/ishtar_common/views.py
@@ -357,12 +357,13 @@ person_search_wizard = wizards.PersonSearch.as_view(
label=_("Person search"),
url_name="person_search",
)
+person_creation_wizard_steps = [
+ ("identity-person_creation", forms.PersonForm),
+ ("final-person_creation", FinalForm),
+]
person_creation_wizard = wizards.PersonWizard.as_view(
- [
- ("identity-person_creation", forms.PersonForm),
- ("final-person_creation", FinalForm),
- ],
+ person_creation_wizard_steps,
label=_("New person"),
url_name="person_creation",
)