summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ishtar_common/admin.py22
-rw-r--r--ishtar_common/models.py11
-rw-r--r--ishtar_common/models_imports.py3
-rw-r--r--ishtar_common/serializers_utils.py1
-rw-r--r--ishtar_common/tests.py11
5 files changed, 39 insertions, 9 deletions
diff --git a/ishtar_common/admin.py b/ishtar_common/admin.py
index 86a9af8e8..3e388d615 100644
--- a/ishtar_common/admin.py
+++ b/ishtar_common/admin.py
@@ -193,6 +193,8 @@ def export_as_csv_action(
value = ""
elif isinstance(value, ContentType):
value = f"{value.app_label}|{value.model}"
+ elif hasattr(value, "natural_key"):
+ value = "||".join(value.natural_key())
else:
value = str(value)
row.append(value)
@@ -203,6 +205,7 @@ def export_as_csv_action(
export_as_csv.short_description = description
return export_as_csv
+
def export_as_geojson_action(
geometry_field,
description=_("Export selected as GeoJSON file"),
@@ -664,6 +667,14 @@ class ImportActionAdmin(admin.ModelAdmin):
value = value.split("|")
value = ContentType.objects.get(app_label=value[0],
model=value[1])
+ elif "||" in value:
+ try:
+ value = model.objects.get_by_natural_key(
+ *value.split("||")
+ )
+ except model.DoesNotExist:
+ missing_parent.append(row.pop(k))
+ break
else:
for slug_col2 in self.import_keys:
try:
@@ -1790,7 +1801,13 @@ class JsonDataFieldForm(JsonContentTypeFormMixin, forms.ModelForm):
exclude = []
-class JsonDataFieldAdmin(ImportActionAdmin):
+serialize_json_action = serialize_action(
+ "types", [models.JsonDataSection, models.JsonDataField]
+)
+serialize_json_action.short_description = SERIALIZE_DESC
+
+
+class JsonDataFieldAdmin(ImportActionAdmin, ImportJSONActionAdmin):
import_keys = ["key"]
list_display = [
"name",
@@ -1803,9 +1820,10 @@ class JsonDataFieldAdmin(ImportActionAdmin):
"section",
]
actions = [
+ export_as_csv_action(),
+ serialize_json_action,
change_value("display", True, _("Display selected")),
change_value("display", False, _("Hide selected")),
- export_as_csv_action(),
]
list_filter = ["value_type", "search_index"]
form = JsonDataFieldForm
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index 81fc4c069..9c139086b 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -689,8 +689,8 @@ class JsonDataSection(models.Model):
objects = JsonDataSectionManager()
class Meta:
- verbose_name = _("Json data - Menu")
- verbose_name_plural = _("Json data - Menus")
+ verbose_name = _("Custom data - Menu")
+ verbose_name_plural = _("Custom data - Menus")
ordering = ["order", "name"]
unique_together = ("name", "content_type")
@@ -743,7 +743,8 @@ class JsonDataField(models.Model):
order = models.IntegerField(_("Order"), default=10)
search_index = models.BooleanField(_("Use in search indexes"), default=False)
section = models.ForeignKey(
- JsonDataSection, blank=True, null=True, on_delete=models.SET_NULL
+ JsonDataSection, blank=True, null=True, on_delete=models.SET_NULL,
+ related_name="json_data_field",
)
custom_forms = models.ManyToManyField(
"CustomForm", blank=True, through="CustomFormJsonField"
@@ -751,8 +752,8 @@ class JsonDataField(models.Model):
objects = JsonDataFieldManager()
class Meta:
- verbose_name = _("Json data - Field")
- verbose_name_plural = _("Json data - Fields")
+ verbose_name = _("Custom data - Field")
+ verbose_name_plural = _("Custom data - Fields")
ordering = ["order", "name"]
unique_together = ("content_type", "key")
diff --git a/ishtar_common/models_imports.py b/ishtar_common/models_imports.py
index c85533268..5cf672877 100644
--- a/ishtar_common/models_imports.py
+++ b/ishtar_common/models_imports.py
@@ -1124,7 +1124,8 @@ class Import(models.Model):
"IshtarUser", blank=True, null=True, on_delete=models.SET_NULL
)
name = models.CharField(_("Name"), max_length=500, null=True)
- importer_type = models.ForeignKey(ImporterType, on_delete=models.CASCADE)
+ importer_type = models.ForeignKey(ImporterType, on_delete=models.CASCADE,
+ verbose_name=_("Importer type"))
imported_file = models.FileField(
_("Imported file"),
upload_to="upload/imports/%Y/%m/",
diff --git a/ishtar_common/serializers_utils.py b/ishtar_common/serializers_utils.py
index 1a526cfff..eefbfd681 100644
--- a/ishtar_common/serializers_utils.py
+++ b/ishtar_common/serializers_utils.py
@@ -114,6 +114,7 @@ def archive_serialization(
GENERIC_QUERYSET_FILTER = {
+ "JsonDataSection": {"JsonDataField": "json_data_field__pk__in"},
"Regexp": {"ImporterType": "columns__importer_type__pk__in"},
"ImporterModel": {
"ImporterType": [
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py
index e3af9024f..1ddc94cb2 100644
--- a/ishtar_common/tests.py
+++ b/ishtar_common/tests.py
@@ -1552,7 +1552,7 @@ class AdminGenTypeTest(TestCase):
models.Format,
models.SupportType,
]
- models_with_data = gen_models + [models.ImporterModel]
+ models_with_data = gen_models + [models.ImporterModel, models.JsonDataField]
models = models_with_data
module_name = "ishtar_common"
ishtar_apps = [
@@ -1569,6 +1569,14 @@ class AdminGenTypeTest(TestCase):
"ishtar_common.ProfileTypeSummary",
]
+ def extra_setup_data(self):
+ models.JsonDataField.objects.create(
+ name="Extra data",
+ content_type=ContentType.objects.get(model="operation"),
+ key="extra_data",
+ value_type="T"
+ )
+
def setUp(self):
self.password = "mypassword"
self.username = "myuser"
@@ -1579,6 +1587,7 @@ class AdminGenTypeTest(TestCase):
user.save()
self.client = Client()
self.client.login(username=self.username, password=self.password)
+ self.extra_setup_data()
def test_listing_and_detail(self):
models = []