Skip to content

Commit

Permalink
Differentiate report output for cli and web.
Browse files Browse the repository at this point in the history
  • Loading branch information
Anaethelion committed Jul 28, 2015
1 parent 53c1109 commit 1b3d6ca
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
5 changes: 3 additions & 2 deletions geotrek/common/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def parse_row(self, row):
if self.progress_cb:
self.progress_cb(float(self.line) / self.nb, self.line, self.eid_val)

def report(self):
def report(self, output_format='txt'):
context = {
'nb_success': self.nb_success,
'nb_lines': self.line,
Expand All @@ -292,7 +292,8 @@ def report(self):
'nb_unmodified': self.nb_unmodified,
'warnings': self.warnings,
}
return render_to_string('common/parser_report.html', context)
print(output_format)
return render_to_string('common/parser_report.{output_format}'.format(output_format=output_format), context)

def get_mapping(self, src, val, mapping, partial):
if partial:
Expand Down
4 changes: 2 additions & 2 deletions geotrek/common/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def progress_cb(progress, line, eid):
'total': 100,
'filename': filename.split('/').pop(-1),
'parser': class_name,
'report': parser.report().replace('$celery_id', current_task.request.id)
'report': parser.report(output_format='html').replace('$celery_id', current_task.request.id)
}


Expand Down Expand Up @@ -76,5 +76,5 @@ def progress_cb(progress, line, eid):
'total': 100,
'filename': _("Import from web."),
'parser': class_name,
'report': parser.report().replace('$celery_id', current_task.request.id)
'report': parser.report(output_format='html').replace('$celery_id', current_task.request.id)
}
9 changes: 9 additions & 0 deletions geotrek/common/templates/common/parser_report.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% load i18n %}{% blocktrans count n=nb_success %}{{ n }}/{{ nb_lines }} line imported.{% plural %}{{ n }}/{{ nb_lines }} lines imported.{% endblocktrans %}
{% if nb_created %}{% blocktrans count n=nb_created %}{{ n }} record created.{% plural %}{{ n }} records created.{% endblocktrans %}
{% endif %}{% if nb_updated %}{% blocktrans count n=nb_updated %}{{ n }} record updated.{% plural %}{{ n }} records updated.{% endblocktrans %}
{% endif %}{% if nb_deleted %}{% blocktrans count n=nb_deleted %}{{ n }} record deleted.{% plural %}{{ n }} records deleted.{% endblocktrans %}
{% endif %}{% if nb_unmodified %}{% blocktrans count n=nb_unmodified %}{{ n }} record unmodified.{% plural %}{{ n }} records unmodified.{% endblocktrans %}
{% endif %}{% if warnings %}{% blocktrans count n=warnings|length %}{{ n }} warning:{% plural %}{{ n }} warnings:{% endblocktrans %}
{% for id, msgs in warnings.iteritems %}# {{ id }}:
{% for msg in msgs %}- {{ msg|safe }},
{% endfor %}{% endfor %}{% endif %}

0 comments on commit 1b3d6ca

Please sign in to comment.