summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2023-09-07 18:42:55 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2024-02-05 10:51:51 +0100
commit0ad415c7795e7ac4b2a70c03d993b027633ca0f6 (patch)
tree59005d1394d1cc04064772546d3be4f40160cd61 /ishtar_common
parentff9cb4b4d71d0df8d0b0f0a96c4a5e45a02ad904 (diff)
downloadIshtar-0ad415c7795e7ac4b2a70c03d993b027633ca0f6.tar.bz2
Ishtar-0ad415c7795e7ac4b2a70c03d993b027633ca0f6.zip
✨ Admin - Importers groups: JSON export, adapt JSON export of importer types
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/admin.py7
-rw-r--r--ishtar_common/models_imports.py14
-rw-r--r--ishtar_common/serializers.py2
-rw-r--r--ishtar_common/serializers_utils.py57
4 files changed, 70 insertions, 10 deletions
diff --git a/ishtar_common/admin.py b/ishtar_common/admin.py
index cf4366bd8..3d1909275 100644
--- a/ishtar_common/admin.py
+++ b/ishtar_common/admin.py
@@ -1654,7 +1654,7 @@ serialize_importer_action.short_description = SERIALIZE_DESC
@admin.register(models.ImporterType, site=admin_site)
class ImporterTypeAdmin(ImportJSONActionAdmin):
- list_display = ("name", "associated_models", "available")
+ list_display = ("name", "associated_models", "available", "importer_groups_label")
actions = importer_type_actions + [
serialize_importer_action,
change_value("available", True, _("Make available")),
@@ -1671,10 +1671,15 @@ class ImporterGroupImporterInline(admin.TabularInline):
extra = 3
+serialize_importer_group_action = serialize_action("common_imports", IMPORT_MODEL_LIST)
+serialize_importer_group_action.short_description = SERIALIZE_DESC
+
+
@admin.register(models.ImporterGroup, site=admin_site)
class ImporterTypeAdmin(admin.ModelAdmin):
list_display = ("name", "importer_types_label", "available")
actions = [
+ serialize_importer_group_action,
change_value("available", True, _("Make available")),
change_value("available", False, _("Make unavailable")),
]
diff --git a/ishtar_common/models_imports.py b/ishtar_common/models_imports.py
index ff920fbf2..3fbd7653d 100644
--- a/ishtar_common/models_imports.py
+++ b/ishtar_common/models_imports.py
@@ -38,6 +38,7 @@ from django.conf import settings
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.contrib.gis.db import models
+from django.contrib.gis.db.models import Manager
from django.contrib.gis.gdal.error import GDALException
from django.contrib.gis.geos import GEOSGeometry
from django.contrib.gis.geos.error import GEOSException
@@ -215,6 +216,10 @@ class ImporterType(models.Model):
return IMPORT_TYPES_DICT[str(self.type)]
return ""
+ @property
+ def importer_groups_label(self) -> str:
+ return " ; ".join([imp.group.name for imp in self.groups.all()])
+
def get_libreoffice_template(self):
if not UnoCalc:
return
@@ -412,16 +417,25 @@ class ImporterGroup(models.Model):
return " ; ".join([imp.importer_type.name for imp in self.importer_types.all()])
+class ImporterGroupImporterManager(Manager):
+ def get_by_natural_key(self, group, importer):
+ return self.get(group__slug=group, importer_type__slug=importer)
+
+
class ImporterGroupImporter(models.Model):
group = models.ForeignKey(ImporterGroup, on_delete=models.CASCADE, related_name="importer_types")
importer_type = models.ForeignKey(ImporterType, on_delete=models.CASCADE, related_name="groups")
order = models.PositiveIntegerField(_("Order"), default=10, validators=[MinValueValidator(1)])
+ objects = ImporterGroupImporterManager()
class Meta:
ordering = ("group", "order")
unique_together = ("group", "order")
verbose_name = _("Importer - Group <-> Importer")
+ def natural_key(self):
+ return self.group.slug, self.importer_type.slug
+
def get_associated_model(parent_model, keys):
model = None
diff --git a/ishtar_common/serializers.py b/ishtar_common/serializers.py
index 071007ab2..1469e13a1 100644
--- a/ishtar_common/serializers.py
+++ b/ishtar_common/serializers.py
@@ -120,6 +120,8 @@ IMPORT_MODEL_LIST = [
models.ImportTarget,
models.ImporterDefaultValues,
models.ImporterDuplicateField,
+ models.ImporterGroup,
+ models.ImporterGroupImporter,
]
diff --git a/ishtar_common/serializers_utils.py b/ishtar_common/serializers_utils.py
index eefbfd681..ada0a62cf 100644
--- a/ishtar_common/serializers_utils.py
+++ b/ishtar_common/serializers_utils.py
@@ -115,20 +115,59 @@ def archive_serialization(
GENERIC_QUERYSET_FILTER = {
"JsonDataSection": {"JsonDataField": "json_data_field__pk__in"},
- "Regexp": {"ImporterType": "columns__importer_type__pk__in"},
+ "Regexp": {
+ "ImporterType": "columns__importer_type__pk__in",
+ "ImporterGroup": "columns__importer_type__groups__group__pk__in",
+ },
"ImporterModel": {
"ImporterType": [
"importer_type_associated__pk__in",
"importer_type_created__pk__in",
- ]
+ ],
+ "ImporterGroup": [
+ "importer_type_associated__groups__group__pk__in",
+ "importer_type_created__groups__group__pk__in",
+ ],
+ },
+ "ValueFormater": {
+ "ImporterType": "columns__importer_type__pk__in",
+ "ImporterGroup": "columns__importer_type__groups__group__pk__in",
+ },
+ "ImporterColumn": {
+ "ImporterType": "importer_type__pk__in",
+ "ImporterGroup": "importer_type__groups__group__pk__in",
+ },
+ "ImporterDefault": {
+ "ImporterType": "importer_type__pk__in",
+ "ImporterGroup": "importer_type__groups__group__pk__in",
+ },
+ "ImportTarget": {
+ "ImporterType": "column__importer_type__pk__in",
+ "ImporterGroup": "column__importer_type__groups__group__pk__in",
},
- "ValueFormater": {"ImporterType": "columns__importer_type__pk__in"},
- "ImporterColumn": {"ImporterType": "importer_type__pk__in"},
- "ImporterDefault": {"ImporterType": "importer_type__pk__in"},
- "ImportTarget": {"ImporterType": "column__importer_type__pk__in"},
- "FormaterType": {"ImporterType": "targets__column__importer_type__pk__in"},
- "ImporterDefaultValues": {"ImporterType": "default_target__importer_type__pk__in"},
- "ImporterDuplicateField": {"ImporterType": "column__importer_type__pk__in"},
+ "FormaterType": {
+ "ImporterType": "targets__column__importer_type__pk__in",
+ "ImporterGroup": "targets__column__importer_type__groups__group__pk__in",
+ },
+ "ImporterDefaultValues": {
+ "ImporterType": "default_target__importer_type__pk__in",
+ "ImporterGroup": "default_target__importer_type__groups__group__pk__in",
+ },
+ "ImporterDuplicateField": {
+ "ImporterType": "column__importer_type__pk__in",
+ "ImporterGroup": "column__importer_type__groups__group__pk__in",
+ },
+ "ImporterGroup": {
+ "ImporterType": "importer_types__importer_type__pk__in",
+ "ImporterGroup": "importer_types__importer_type__groups__group__pk__in",
+ },
+ "ImporterGroupImporter": {
+ "ImporterType": "importer_type__pk__in",
+ "ImporterGroup": "group__pk__in",
+ },
+ "ImporterType": {
+ "ImporterGroup": "groups__group__pk__in",
+ }
}