summaryrefslogtreecommitdiff
path: root/ishtar_common/models_imports.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/models_imports.py')
-rw-r--r--ishtar_common/models_imports.py24
1 files changed, 17 insertions, 7 deletions
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: