diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2025-03-21 18:12:27 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2025-03-21 18:12:27 +0100 |
commit | 8a5a127af79fd2f6ebd1ea1f106c06e675d66f8b (patch) | |
tree | 3faed4493575229e097764fa20fb26b227f78b3e /ishtar_common/models.py | |
parent | 30e374e52f7bdf336d1f9076e4e343d596aa9ebc (diff) | |
download | Ishtar-8a5a127af79fd2f6ebd1ea1f106c06e675d66f8b.tar.bz2 Ishtar-8a5a127af79fd2f6ebd1ea1f106c06e675d66f8b.zip |
⚡️ custom form: better filter for JSON fields - 🐛 fix administrative act custom forms (refs #6238, refs #6239)
Diffstat (limited to 'ishtar_common/models.py')
-rw-r--r-- | ishtar_common/models.py | 54 |
1 files changed, 42 insertions, 12 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 50abded4c..9197d4839 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -1728,6 +1728,26 @@ class CustomForm(models.Model): unique_together = (("name", "form"),) ADMIN_SECTION = _("Custom data / custom forms") + MODELS = { + "contextrecord": ("archaeological_context_records", "contextrecord"), + "file": ("archaeological_files", "contextrecord"), + "adminact": ("archaeological_operations", "administrativeact"), + "operation": ("archaeological_operations", "operation"), + "archaeological_site": ("archaeological_operations", "archaeologicalsite"), + "find": ("archaeological_finds", "find"), + "findbasket": ("archaeological_finds", "findbasket"), + "treatment": ("archaeological_finds", "treatment"), + "treatmentfile": ("archaeological_finds", "treatmentfile"), + "exhibition": ("archaeological_finds", "exhibition"), + "warehouse": ("archaeological_warehouse", "warehouse"), + "container": ("archaeological_warehouse", "container"), + "person": ("ishtar_common", "person"), + "organization": ("ishtar_common", "organization"), + "biographicalnote": ("ishtar_common", "biographicalnote"), + "document": ("ishtar_common", "document"), + "geoitem": ("ishtar_common", "geovectordata"), + } + def natural_key(self): return (self.name, self.form) @@ -1771,6 +1791,7 @@ class CustomForm(models.Model): if "Form" not in form and "Select" not in form: # not very clean... but do not treat inappropriate items continue + form = getattr(app_form, form) if ( not inspect.isclass(form) @@ -1794,19 +1815,28 @@ class CustomForm(models.Model): return register[self.form] def get_available_json_fields(self): - register, register_fields = self.register() - if self.form not in self._register: - return [] - current_form = register[self.form] - app_name = current_form.__module__.split(".")[0] - if app_name not in register_fields: - return [] - res = [] - for model_name in register_fields[app_name]: + model_name = self.form.split("-")[0] + content_types = [] + if model_name in self.MODELS: + app_name, model_name = self.MODELS[model_name] q = ContentType.objects.filter(app_label=app_name, model=model_name) - if not q.count(): - continue - ct = q.all()[0] + if q.count(): + content_types.append(q.all()[0]) + if not content_types: + register, register_fields = self.register() + if self.form not in self._register: + return [] + current_form = register[self.form] + app_name = current_form.__module__.split(".")[0] + if app_name not in register_fields: + return [] + for model_name in register_fields[app_name]: + q = ContentType.objects.filter(app_label=app_name, model=model_name) + if not q.count(): + continue + content_types.append(q.all()[0]) + res = [] + for ct in content_types: for json_field in JsonDataField.objects.filter(content_type=ct).all(): res.append( ( |