summaryrefslogtreecommitdiff
path: root/ishtar_common/models_imports.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2019-04-30 13:32:17 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2019-06-17 13:21:27 +0200
commitc7e8d8c880068afdd5a035767f81138f49c18111 (patch)
tree17558137f1faafc5a098aa7e667edd9d884c1f3d /ishtar_common/models_imports.py
parentd8a0e550583db23853e4b5d6984fa6671a264acf (diff)
downloadIshtar-c7e8d8c880068afdd5a035767f81138f49c18111.tar.bz2
Ishtar-c7e8d8c880068afdd5a035767f81138f49c18111.zip
Label generation: generate labels from a template - template model, slug is mandatory
Diffstat (limited to 'ishtar_common/models_imports.py')
-rw-r--r--ishtar_common/models_imports.py30
1 files changed, 2 insertions, 28 deletions
diff --git a/ishtar_common/models_imports.py b/ishtar_common/models_imports.py
index e3f5f2492..23057e6f5 100644
--- a/ishtar_common/models_imports.py
+++ b/ishtar_common/models_imports.py
@@ -19,7 +19,6 @@
import csv
import datetime
-from importlib import import_module
import os
import logging
import shutil
@@ -29,7 +28,7 @@ import zipfile
from django.conf import settings
from django.contrib.gis.db import models
-from django.core.exceptions import SuspiciousOperation, ValidationError
+from django.core.exceptions import ValidationError
from django.core.files.base import ContentFile
from django.core.validators import validate_comma_separated_integer_list
from django.db.models.base import ModelBase
@@ -42,7 +41,7 @@ from ishtar_common.model_managers import SlugModelManager
from ishtar_common.utils import create_slug, \
get_all_related_m2m_objects_with_model, put_session_message, \
- put_session_var, get_session_var, num2col, max_size_help
+ put_session_var, get_session_var, num2col, max_size_help, import_class
from ishtar_common.data_importer import Importer, ImportFormater, \
IntegerFormater, FloatFormater, UnicodeFormater, DateFormater, \
TypeFormater, YearFormater, StrToBoolean, FileFormater, InseeFormater, \
@@ -51,12 +50,6 @@ from ishtar_common.utils import task
logger = logging.getLogger(__name__)
-IMPORTER_CLASSES = {}
-
-IMPORTER_CLASSES.update({
- 'sra-pdl-files':
- 'archaeological_files.data_importer.FileImporterSraPdL'})
-
def get_model_fields(model):
"""
@@ -70,22 +63,6 @@ def get_model_fields(model):
return fields
-def import_class(full_path_classname):
- """
- Return the model class from the full path
- TODO: add a white list for more security
- """
- mods = full_path_classname.split('.')
- if len(mods) == 1:
- mods = ['ishtar_common', 'models', mods[0]]
- elif 'models' not in mods and 'models_finds' not in mods \
- and 'models_treatments' not in mods:
- raise SuspiciousOperation(
- u"Try to import a non model from a string")
- module = import_module('.'.join(mods[:-1]))
- return getattr(module, mods[-1])
-
-
class ImportModelManager(models.Manager):
def get_by_natural_key(self, klass):
return self.get(klass=klass)
@@ -149,9 +126,6 @@ class ImporterType(models.Model):
return self.name
def get_importer_class(self, import_instance=None):
- if self.slug and self.slug in IMPORTER_CLASSES:
- cls = import_class(IMPORTER_CLASSES[self.slug])
- return cls
OBJECT_CLS = import_class(self.associated_models.klass)
DEFAULTS = dict([(default.keys, default.values)
for default in self.defaults.all()])