summaryrefslogtreecommitdiff
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-04-16 16:38:32 +0200
commita9c7a217383ead98acc4fd55d635c58f1aad9c26 (patch)
tree764f7d40f7945e4d1c98c1c322cb895a12a83288
parent8cbda24660d1dbf50980e1f77c5c12a27e0279f5 (diff)
downloadIshtar-a9c7a217383ead98acc4fd55d635c58f1aad9c26.tar.bz2
Ishtar-a9c7a217383ead98acc4fd55d635c58f1aad9c26.zip
✨ Admin - Importers groups: JSON export, adapt JSON export of importer types
-rw-r--r--archaeological_operations/tests.py2
-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
5 files changed, 71 insertions, 11 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py
index afa484839..f72ef2647 100644
--- a/archaeological_operations/tests.py
+++ b/archaeological_operations/tests.py
@@ -157,7 +157,7 @@ class FileInit(object):
self.item.save()
-class ImportTest(object):
+class ImportTest:
def setUp(self):
self.username, self.password, self.user = create_superuser()
self.ishtar_user = IshtarUser.objects.get(pk=self.user.pk)
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",
+ }
}