summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.md1
-rw-r--r--ishtar_common/models_imports.py24
2 files changed, 18 insertions, 7 deletions
diff --git a/CHANGES.md b/CHANGES.md
index 20dd86081..3cd5cc0d8 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -42,6 +42,7 @@ Ishtar changelog
- Profile: do not display geo item list when mapping is deactivated
- Explicit message on associated container deletion when a warehouse is deleted
- Administrative act: add a warning when associated item is deleted
+- Imports: register automatically type models for export
- Sheet:
- fix treatment and file treatment sheet display (bad QR code link)
- Operation - statistics number of parcels fix
diff --git a/ishtar_common/models_imports.py b/ishtar_common/models_imports.py
index 6451206a2..76121d846 100644
--- a/ishtar_common/models_imports.py
+++ b/ishtar_common/models_imports.py
@@ -39,7 +39,7 @@ from django.contrib.gis.db import models
from django.contrib.gis.gdal.error import GDALException
from django.contrib.gis.geos import GEOSGeometry
from django.contrib.gis.geos.error import GEOSException
-from django.core.exceptions import ValidationError
+from django.core.exceptions import ValidationError, SuspiciousOperation
from django.core.files import File
from django.core.files.base import ContentFile
from django.core.validators import validate_comma_separated_integer_list
@@ -1073,16 +1073,26 @@ class FormaterType(models.Model):
if self.many_split:
kwargs["many_split"] = self.many_split
if self.formater_type == "TypeFormater":
- if self.options not in TARGET_MODELS_KEYS:
+ if self.options in dir():
+ model = dir()[self.options]
+ else:
+ try:
+ model = import_class(self.options)
+ except (AttributeError, SuspiciousOperation):
+ logger.warning(
+ "**WARN FormaterType.get_formater_type**: {} "
+ "is not in valid.".format(self.options)
+ )
+ return
+ # must be explicit if non general type
+ if self.options not in TARGET_MODELS_KEYS and \
+ not [True for m in model.__mro__ if m.__name__ == "GeneralType"]:
logger.warning(
"**WARN FormaterType.get_formater_type**: {} "
- "is not in TARGET_MODELS_KEYS".format(self.options)
+ "is not in valid.".format(self.options)
)
return
- if self.options in dir():
- model = dir()[self.options]
- else:
- model = import_class(self.options)
+
return TypeFormater(model, **kwargs)
elif self.formater_type == "UnicodeFormater":
if self.options: