From b7b609dcf3dad3bab338297d6a32a44f229f3e53 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 29 Mar 2018 14:12:29 +0200 Subject: Fixes for not imported columns on step by step import. Tests for this feature. --- .../templates/ishtar/import_step_by_step.html | 9 +++++++-- ishtar_common/views.py | 18 ++++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) (limited to 'ishtar_common') diff --git a/ishtar_common/templates/ishtar/import_step_by_step.html b/ishtar_common/templates/ishtar/import_step_by_step.html index 44c5389d3..9aca80837 100644 --- a/ishtar_common/templates/ishtar/import_step_by_step.html +++ b/ishtar_common/templates/ishtar/import_step_by_step.html @@ -85,7 +85,7 @@ {{idx}} {{name|safe}} {{raw}} - + {% endfor %} @@ -121,13 +121,18 @@ {% else %} -{% if not have_change %} +{% if not have_change and not new_objects %} {% else %} {% endif %} diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 1536868d4..d4fb68004 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -1948,7 +1948,10 @@ class ImportStepByStepView(IshtarMixin, LoginRequiredMixin, TemplateView): line_nb = self.imprt_obj.get_number_of_lines() total_line_nb = self.imprt_obj.skip_lines + line_nb delta = int((self.current_line_number + 1) / pagination_step) - already_imported = self.imprt_obj.imported_line_numbers.split(',') + + already_imported = [] + if self.imprt_obj.imported_line_numbers: + already_imported = self.imprt_obj.imported_line_numbers.split(',') dct['page_is_last'] = self.current_line_number == line_nb dct['page_numbers'] = [] # label, number, enabled, is_imported @@ -1981,7 +1984,8 @@ class ImportStepByStepView(IshtarMixin, LoginRequiredMixin, TemplateView): dct['errors'] = self.errors if self.errors: if self.imprt.current_csv_line: - headers = [f.label for f in self.imprt.get_formaters()] + headers = [f.label if f else _(u"Not imported") + for f in self.imprt.get_formaters()] dct['values'] = zip( range(1, len(headers) + 1), headers, self.imprt.current_csv_line @@ -1989,6 +1993,10 @@ class ImportStepByStepView(IshtarMixin, LoginRequiredMixin, TemplateView): return dct headers, self.path_to_column, interpreted_values = [], {}, [] for idx, formater in enumerate(self.imprt.get_formaters()): + if not formater: + headers.append(_(u"Not imported")) + interpreted_values.append(u"–") + continue lbl = formater.label if formater.comment: lbl += u' ' headers.append(lbl) + field_name = formater.field_name[0] if formater.export_field_name: field_name = formater.export_field_name[0] @@ -2011,16 +2020,17 @@ class ImportStepByStepView(IshtarMixin, LoginRequiredMixin, TemplateView): self.path_to_column[current_field_name].append(idx) field_name_tuple.pop() - for idx, key in enumerate(field_name.split('__')): + for idx_split, key in enumerate(field_name.split('__')): if isinstance(value, dict) and key in value: value = value[key] - elif not idx: + elif not idx_split: # no key reach value = None else: break value = self.get_value(value) interpreted_values.append(value) + dct['values'] = zip( range(1, len(headers) + 1), headers, self.imprt.current_csv_line, interpreted_values -- cgit v1.2.3