From 34a462b58fa629af474bada00a5eba366a07ca59 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 23 Mar 2018 13:57:12 +0100 Subject: Step by step: large improvments on step display (refs #3975) Show modified, sheet access for existing items, link between created, updated fields and associated column. --- ishtar_common/data_importer.py | 25 +++- ishtar_common/models.py | 4 + ishtar_common/static/media/styles.css | 8 ++ .../templates/ishtar/import_step_by_step.html | 116 ++++++++++------- ishtar_common/templatetags/link_to_window.py | 2 +- ishtar_common/utils.py | 16 +++ ishtar_common/views.py | 145 +++++++++++++++++++-- 7 files changed, 248 insertions(+), 68 deletions(-) diff --git a/ishtar_common/data_importer.py b/ishtar_common/data_importer.py index 4519241af..3bcd62415 100644 --- a/ishtar_common/data_importer.py +++ b/ishtar_common/data_importer.py @@ -1632,7 +1632,10 @@ class Importer(object): for k in create_dict.keys(): # filter unnecessary default values but not the json field if type(create_dict[k]) == dict and k != 'data': - create_dict.pop(k) + if self.simulate: + create_dict[k] = _(u"* created *") + else: + create_dict.pop(k) # File doesn't like deepcopy elif type(create_dict[k]) == File: create_dict[k] = copy.copy(data[k]) @@ -1776,16 +1779,26 @@ class Importer(object): # force post save script v.save() if self.simulate: + # put m2m result in data dict + current_data = data + if m2ms: + for item in path: + if item not in current_data: + current_data[item] = {} + current_data = current_data[item] + for key, value in m2ms: + if not isinstance(value, list) and \ + not isinstance(value, tuple): + value = [value] + current_data[key] = value + if created: - for k in dct.keys(): - # do not present empty value - if dct[k] in (None, ''): - dct.pop(k) - return _(u"* created item *"), True + return dct, True else: # defaults are not presented as matching data dct.pop('defaults') return self.updated_objects[-1][1], False + if m2ms: # force post save script obj.save() diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 883c12ab9..6518ea763 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -459,6 +459,10 @@ class GeneralType(Cached, models.Model): def natural_key(self): return (self.txt_idx, ) + @property + def explicit_label(self): + return u"{} ({})".format(self.label, self._meta.verbose_name) + @classmethod def create_default_for_test(cls): return [cls.objects.create(label='Test %d' % i) for i in range(5)] diff --git a/ishtar_common/static/media/styles.css b/ishtar_common/static/media/styles.css index 4ab36afe2..9507674b7 100644 --- a/ishtar_common/static/media/styles.css +++ b/ishtar_common/static/media/styles.css @@ -14,6 +14,10 @@ html{ background-position: right 30px top 150px; } +.text-large{ + font-size: 1.8em; +} + .form-thumbnail{ max-width: 120px; max-height: 120px; @@ -89,6 +93,10 @@ button:hover{ cursor: pointer; } +.fa-question-circle{ + cursor: help; +} + div#foot{ font-size: 0.75em; text-align: center; diff --git a/ishtar_common/templates/ishtar/import_step_by_step.html b/ishtar_common/templates/ishtar/import_step_by_step.html index 233889df4..c827156c5 100644 --- a/ishtar_common/templates/ishtar/import_step_by_step.html +++ b/ishtar_common/templates/ishtar/import_step_by_step.html @@ -1,9 +1,8 @@ {% extends "base.html" %} -{% load i18n inline_formset %} +{% load i18n inline_formset link_to_window %} {% block content %} -

{% trans "Import step by step" %}

-

{{import.name}} – {% trans "line " %} {{line_number_displayed}}

+

{% trans "Import step by step" %} – {{import.name}} – {% trans "line " %} {{line_number_displayed}}

{% if errors %} +
+{% endfor %} {% endif %} {% if updated_objects %} -

{% trans "Objects to be updated" %}

-
- - - - - - - - {% for path, obj, values, updated_values in updated_objects %} - - - - - - {% endfor %} -
{% trans "Path" %}{% trans "Object" %}{% trans "Matching values" %}{% trans "Updated values" %}
{{path}}{{obj}} ({{obj.get_verbose_name}}){% for k, value in values.items %}
-
{{k}}{% trans ":"%}
-
{{value}}
-
{% endfor %} -
{% for k, value in updated_values.items %}
-
{{k}}{% trans ":"%}
-
{{value}}
-
{% endfor %} -
+

{% trans "Objects to be updated" %}

+{% for path, obj, values, old_and_updated in updated_objects %} + +
+
+
{{path}} – {{obj}} {{obj|link_to_window}} ({{obj.get_verbose_name}})
+
+
+ +
{% trans "Matching values" %}
+ + + + + + {% for k, value in values.items %} + + + {% endfor %} +
{% trans "Key" %}{% trans "Value" %}
{{k|safe}}{{value}}
+ + +
{% trans "Updated values" %}
+ + + + + + + + {% for k, value in old_and_updated.items %} + + + + + {% endfor %} +
{% trans "Key" %}{% trans "Old value" %}{% trans "New value" %}{% trans "Changed" %}
{{k|safe}}{{value.0|safe}}{{value.1|safe}}{% if value.2%} + {% else %}–{% endif %}
+
+ +
+{% endfor %} + {% endif %} +

{% trans "CSV values" %}

+
- - + {% comment %}{% endcomment %} - {% for idx, name, raw, interpreted in values %} + {% for idx, name, raw, interpreted in values %} - - + {% endfor %}
{% trans "Column number" %} {% trans "Name" %} {% trans "Raw CSV value" %}{% trans "Current value" %}{% trans "New value" %}{% trans "Interpreted value" %}{% trans "Merged value" %}
{{idx}} {{name|safe}} {{raw}}{{interpreted}}{{interpreted|safe}}
diff --git a/ishtar_common/templatetags/link_to_window.py b/ishtar_common/templatetags/link_to_window.py index f157b6255..fca5a9f91 100644 --- a/ishtar_common/templatetags/link_to_window.py +++ b/ishtar_common/templatetags/link_to_window.py @@ -10,7 +10,7 @@ register = Library() @register.filter def link_to_window(item): - if not item: + if not hasattr(item, 'SHOW_URL'): return "" return mark_safe( u' ".join( + unicode(l) + for l in get_field_labels_from_path(cls, path) + ) + if not label: + label = unicode(cls._meta.verbose_name) + return label + + def transform_keys_to_label(self, path, cls, dct): + value_dct = {} + for k in dct: + label = unicode( + get_field_labels_from_path(cls, [k])[0] + ) + + concat_path = u"__".join(list(path) + [k]) + if concat_path in self.path_to_column: + for col in self.path_to_column[concat_path]: + col += 1 + label += u" "\ + u" {} {} "\ + u"".format(col, _(u"Col. "), col) + value_dct[label] = dct[k] + return value_dct + + def list_to_html(self, lst): + if not lst: + return _(u"* empty *") + return u"
  • " + \ + u"
  • ".join([ + self.get_value(item) for item in lst + ]) + u"
" + + def get_value(self, item): + if hasattr(item, 'SHOW_URL'): + return u"{}{}".format(unicode(item), link_to_window(item)) + if hasattr(item, 'explicit_label'): + return item.explicit_label + if item in (None, [], [None]): + return _(u"* empty *") + if isinstance(item, list): + return self.list_to_html(item) + return unicode(item) + class ImportListTableView(ImportListView): template_name = 'ishtar/import_table.html' -- cgit v1.2.3