diff options
Diffstat (limited to 'ishtar_common/data_importer.py')
-rw-r--r-- | ishtar_common/data_importer.py | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/ishtar_common/data_importer.py b/ishtar_common/data_importer.py index 6a58e0409..d5e6f966c 100644 --- a/ishtar_common/data_importer.py +++ b/ishtar_common/data_importer.py @@ -748,6 +748,7 @@ class Importer(object): MODEL_CREATION_LIMIT = [] EXTRA_DEFAULTS = {} DEFAULTS = {} + PRE_IMPORT_VALUES = {} # values from a form before the import ERRORS = { "header_check": _( "The given file is not correct. Check the file " @@ -839,6 +840,7 @@ class Importer(object): 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 if not self.history_modifier: @@ -1151,7 +1153,7 @@ class Importer(object): idx_col = 0 for idx_col, val in enumerate(line): try: - self._row_processing(c_row, idx_col, idx_line, val, data) + data = self._row_processing(c_row, idx_col, idx_line, val, data) # nosec: no catch to force continue processing of lines except: # nosec pass @@ -1367,7 +1369,7 @@ class Importer(object): def _row_processing(self, c_row, idx_col, idx_line, val, data): if idx_col >= len(self.line_format): - return + return data formater = self.line_format[idx_col] @@ -1376,7 +1378,7 @@ class Importer(object): if not formater or not formater.field_name: c_row.append(_("Not imported")) - return + return data if formater.regexp: # multiline regexp is a mess... @@ -1390,7 +1392,7 @@ class Importer(object): self.c_errors = True elif not val.strip(): c_row.append("") - return + return data val = val.replace(NEW_LINE_BREAK, "\n") self.errors.append( ( @@ -1400,7 +1402,7 @@ class Importer(object): ) ) c_row.append("") - return + return data val_group = [] for g in formater.regexp.findall(val): if isinstance(g, (tuple, list)): @@ -1470,7 +1472,7 @@ class Importer(object): self.c_errors = True self.errors.append((idx_line + 1, idx_col + 1, str(e))) c_values.append("") - return + return data if formater.value_format and value is not None and value != "": if "{item" in formater.value_format: value = formater.value_format.format(item=value) @@ -1503,7 +1505,7 @@ class Importer(object): self.errors.append( (idx_line + 1, idx_col + 1, self.ERRORS["value_required"]) ) - return + return data field_names = [field_name] force_news = [force_new] @@ -1536,7 +1538,9 @@ 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 def _get_field_m2m( self, attribute, data, c_path, new_created, field_object, idx_line=None |