diff options
Diffstat (limited to 'ishtar_common')
| -rw-r--r-- | ishtar_common/admin.py | 10 | ||||
| -rw-r--r-- | ishtar_common/migrations/0262_migrate_custom_form_slug.py | 33 | ||||
| -rw-r--r-- | ishtar_common/models.py | 54 | 
3 files changed, 80 insertions, 17 deletions
| diff --git a/ishtar_common/admin.py b/ishtar_common/admin.py index 0d2cf3a0d..50dbbe25a 100644 --- a/ishtar_common/admin.py +++ b/ishtar_common/admin.py @@ -262,13 +262,13 @@ def export_as_geojson_action(              fields=field_names,          ).encode("utf-8")          in_memory = BytesIO() -        zip = zipfile.ZipFile(in_memory, "a") -        zip.writestr(basename + ".geojson", geojson) +        czip = zipfile.ZipFile(in_memory, "a") +        czip.writestr(basename + ".geojson", geojson)          # fix for Linux zip files read in Windows -        for file in zip.filelist: -            file.create_system = 0 -        zip.close() +        for cfile in czip.filelist: +            cfile.create_system = 0 +        czip.close()          response = HttpResponse(content_type="application/zip")          response["Content-Disposition"] = "attachment; filename={}.zip".format(basename)          in_memory.seek(0) diff --git a/ishtar_common/migrations/0262_migrate_custom_form_slug.py b/ishtar_common/migrations/0262_migrate_custom_form_slug.py new file mode 100644 index 000000000..f35d78e1a --- /dev/null +++ b/ishtar_common/migrations/0262_migrate_custom_form_slug.py @@ -0,0 +1,33 @@ +# Generated by Django 2.2.28 on 2025-03-21 17:52 + +from django.db import migrations + +FORM_SLUG = [ +    ("preventive-020-edition-form", "file-020-preventiveedition-form"), +    ("file-adminact-general", "adminact-file-general"), +    ("simplefind-020-general", "find-020-simplegeneral"), +    ("treatmentn1-030-resulting-find", "treatment-030-n1-resulting-find"), +    ("treatment1n-030-resulting-finds", "treatment-030-1n-resulting-finds"), +    ("treatmentn1-020-general", "treatment-020-n1-general"), +    ("treatment1n-020-general", "treatment-020-1n-general"), +    ("treatment-adminact-general", "adminact-treatment-general"), +    ("treatmentfile-adminact-general", "adminact-treatmentfile-general"), +    ("operation-adminact-general", "adminact-operation-general"), +] + + +def migrate_slug(apps, __): +    CustomForm = apps.get_model("ishtar_common", "customform") +    for old, new in FORM_SLUG: +        CustomForm.objects.filter(form=old).update(form=new) + + +class Migration(migrations.Migration): + +    dependencies = [ +        ('ishtar_common', '0261_geo_reference_acquisition_date'), +    ] + +    operations = [ +        migrations.RunPython(migrate_slug) +    ] 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(                      ( | 
