From ab2c5864b83746df7bd2055995280208901e1f4b Mon Sep 17 00:00:00 2001 From: Jannis Date: Wed, 2 Mar 2016 14:30:38 +0100 Subject: [PATCH 1/2] Make errors more readable in template MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of printing the `repr()` of the row, leading to `OrderedDict([(u'col1', u'val1'), (u'col2', u'val2'), …])`, just print `val1, val2, …`. --- import_export/templates/admin/import_export/import.html | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/import_export/templates/admin/import_export/import.html b/import_export/templates/admin/import_export/import.html index fa0d04cf7..dea1dcf73 100644 --- a/import_export/templates/admin/import_export/import.html +++ b/import_export/templates/admin/import_export/import.html @@ -28,12 +28,7 @@

{% trans "Import" %}

{% trans "This importer will import the following fields: " %} - {% for f in fields %} - {% if forloop.counter0 %} - , - {% endif %} - {{ f }} - {% endfor %} + {{ fields|join:", " }}

@@ -73,7 +68,7 @@

{% trans "Errors" %}

{% for error in errors %}
  • {% trans "Line number" %}: {{ line }} - {{ error.error }} -
    {{ error.row }}
    +
    {{ error.row.values|join:", " }}
    {{ error.traceback|linebreaks }}
  • {% endfor %} From 979c0cbe48e23d9c859d5676c74cc6026ab6db52 Mon Sep 17 00:00:00 2001 From: Jannis Date: Wed, 2 Mar 2016 14:34:36 +0100 Subject: [PATCH 2/2] Pass message instead of object representation Exceptions implement `.__str__` which can be used to be passed to the template error output. This prevents ugly string formatting like `u''`. --- import_export/resources.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/import_export/resources.py b/import_export/resources.py index bf910e946..6ad0731f5 100644 --- a/import_export/resources.py +++ b/import_export/resources.py @@ -341,7 +341,7 @@ def import_data(self, dataset, dry_run=False, raise_errors=False, except Exception as e: logging.exception(e) tb_info = traceback.format_exc() - result.base_errors.append(Error(repr(e), tb_info)) + result.base_errors.append(Error(e, tb_info)) if raise_errors: if use_transactions: savepoint_rollback(sp1)