diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2023-03-08 10:48:50 +0100 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2023-03-08 10:48:50 +0100 | 
| commit | f447bbebea851eb7014815351dc69e03d0aff47f (patch) | |
| tree | f383ed479798eedb387d5b8f192e2e2461956d98 /ishtar_common/models_imports.py | |
| parent | b8517e71ef80647740ddecd93fc5baeb9c775257 (diff) | |
| download | Ishtar-f447bbebea851eb7014815351dc69e03d0aff47f.tar.bz2 Ishtar-f447bbebea851eb7014815351dc69e03d0aff47f.zip | |
Imports: register automatically type models for export (refs #3653)
Diffstat (limited to 'ishtar_common/models_imports.py')
| -rw-r--r-- | ishtar_common/models_imports.py | 24 | 
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: | 
