summaryrefslogtreecommitdiff
path: root/ishtar_common/data_importer.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/data_importer.py')
-rw-r--r--ishtar_common/data_importer.py38
1 files changed, 14 insertions, 24 deletions
diff --git a/ishtar_common/data_importer.py b/ishtar_common/data_importer.py
index d5e6f966c..8e3c41e62 100644
--- a/ishtar_common/data_importer.py
+++ b/ishtar_common/data_importer.py
@@ -746,7 +746,6 @@ class Importer(object):
UNICITY_KEYS = []
# if set only models inside this list can be created
MODEL_CREATION_LIMIT = []
- EXTRA_DEFAULTS = {}
DEFAULTS = {}
PRE_IMPORT_VALUES = {} # values from a form before the import
ERRORS = {
@@ -834,12 +833,6 @@ class Importer(object):
if import_instance and import_instance.imported_images:
self.archive = import_instance.imported_images
self._defaults = self.DEFAULTS.copy()
- # EXTRA_DEFAULTS are for multiple inheritance
- if self.EXTRA_DEFAULTS:
- for k in self.EXTRA_DEFAULTS:
- if k not in self._defaults:
- self._defaults[k] = {}
- self._defaults[k].update(self.EXTRA_DEFAULTS[k])
self._pre_import_values = self.PRE_IMPORT_VALUES.copy()
self.history_modifier = history_modifier
self.output = output
@@ -1158,6 +1151,20 @@ class Importer(object):
except: # nosec
pass
+ data = update_data(self._pre_import_values, data)
+ # put default values only if relevant
+ for mandatory_keys, defaults in self._defaults:
+ test_dict = data.copy()
+ nok = False
+ for k in mandatory_keys: # test have keys
+ if k not in test_dict:
+ nok = True
+ break
+ test_dict = test_dict[k]
+ if nok or not any(1 for k in test_dict if test_dict[k]): # test empty dict
+ continue
+ data = update_data(defaults, data)
+
self.validity.append(c_row)
if not self.c_errors and (idx_col + 1) < self.min_col_number:
self.c_errors = True
@@ -1188,7 +1195,6 @@ class Importer(object):
default_srs = profile.srs if profile.srs else None
if "geodata" in data:
- geodata = copy.deepcopy(self._defaults.get(("geodata",), {}))
geodata.update(data.pop("geodata"))
if default_srs and not [
1 for k in geodata if k.startswith("spatial_reference_system") and
@@ -1197,7 +1203,6 @@ class Importer(object):
geodata["spatial_reference_system"] = default_srs
if "main_geodata" in data:
- main_geodata = copy.deepcopy(self._defaults.get(("main_geodata",), {}))
main_geodata.update(data.pop("main_geodata"))
if default_srs and not [
1 for k in main_geodata if k.startswith("spatial_reference_system")
@@ -1538,7 +1543,6 @@ class Importer(object):
concat=concats[idx],
concat_str=concat_str[idx],
)
- data = update_data(self._pre_import_values, data)
c_row.append(" ; ".join([v for v in c_values]))
return data
@@ -1582,15 +1586,6 @@ class Importer(object):
# contruct many dict for each values
default_dict = {}
- # # get default values
- p = [attribute]
- if c_path:
- p = list(c_path) + p
- p = tuple(p)
- if p in self._defaults:
- for k in self._defaults[p]:
- default_dict[k] = self._defaults[p][k]
-
# # init with simple values that will be duplicated
for key in val.keys():
if type(val[key]) not in (list, tuple):
@@ -1896,15 +1891,10 @@ class Importer(object):
elif type(create_dict[k]) == File:
create_dict[k] = copy.copy(data[k])
- # default values
path = tuple(path)
defaults = {}
if hasattr(cls, "get_import_defaults"):
defaults = cls.get_import_defaults()
- if path in self._defaults:
- for k in self._defaults[path]:
- if (k not in data or not data[k]) and self._defaults[path][k]:
- defaults[k] = self._defaults[path][k]
if "history_modifier" in create_dict:
defaults.update({"history_modifier": create_dict.pop("history_modifier")})