Skip to content

Commit

Permalink
Add reports to batch imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Anaethelion committed Jul 23, 2015
1 parent eada912 commit 8209e60
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 52 deletions.
12 changes: 12 additions & 0 deletions geotrek/common/static/common/css/import.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,16 @@

#progress-bars span.parser{
font-weight: bold;
}

#progress-bars button {
margin-top: 1em;
}

#progress-bars .collapse {
margin-top: 1em;
}

#import-forms .file-attachment-form {
width: auto;
}
22 changes: 15 additions & 7 deletions geotrek/common/static/common/js/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,21 @@ function updateImportProgressBars() {
status_class = "progress-danger";
}

// Update element if exists
if (element = document.getElementById(row.id)) {
element.querySelector('.bar').style.width = local_percent;
element.querySelector('.pull-left').innerHTML = local_percent;
} else {

if(!element.querySelector('.alert').classList.contains('alert-success')) {
// Add report if success.
if (row.result.report) {
element.querySelector('.alert').classList.add('alert-success');
element.querySelector('.alert').innerHTML = row.result.report;
element.querySelector('.alert').style.display = 'block';
}
}

} else { //Create element in dom.
element = document.createElement('div');
element.innerHTML = document.querySelector('#import-template').innerHTML
element.id = row.id;
Expand All @@ -30,18 +41,15 @@ function updateImportProgressBars() {

parent.appendChild(element);
}

// Handle errors if any.
if (row.result.exc_message) {
element.querySelector('.alert').classList.add('alert-error');
element.querySelector('.alert span').innerHTML = "Error message : " + row.result.exc_message;
element.querySelector('.alert').style.display = 'block';
}

if (row.result.report) {
element.querySelector('.alert').classList.add('alert-success');
element.querySelector('.alert span').innerHTML = row.result.report;
element.querySelector('.alert').style.display = 'block';
}

// Add class on status change.
if (!element.querySelector('.progress').classList.contains(status_class)) {
element.querySelector('.progress').classList.add(status_class);
}
Expand Down
6 changes: 4 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):
'total': 100,
'filename': filename.split('/').pop(-1),
'parser': class_name,
'report': parser.report()
'report': parser.report().replace('$celery_id', current_task.request.id)
}


Expand Down Expand Up @@ -71,10 +71,12 @@ def progress_cb(progress):
except Exception as e:
raise e

print(parser.report())

return {
'current': 100,
'total': 100,
'filename': _("Import from web."),
'parser': class_name,
'report': parser.report()
'report': parser.report().replace('$celery_id', current_task.request.id)
}
2 changes: 1 addition & 1 deletion geotrek/common/templates/common/import_dataset.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{% endblock toolbar %}

{% block mainpanel %}
<div class="span3 offset2">
<div id="import-forms" class="span3 offset2">
{% block mainform %}
{% crispy form form.helper %}
{% if form_without_file %}
Expand Down
94 changes: 52 additions & 42 deletions geotrek/common/templates/common/parser_report.html
Original file line number Diff line number Diff line change
@@ -1,52 +1,62 @@
{% load i18n %}

{% blocktrans count n=nb_success %}
<div>
{{ n }}/{{ nb_lines }} line imported.{% plural %}{{ n }}/{{ nb_lines }} lines imported.
</div>
{% endblocktrans %}
<button type="button" class="btn btn-primary" data-toggle="collapse" data-target="#collapse-$celery_id">
{%trans "Display report" %}
</button>

{% if nb_created %}
{% blocktrans count n=nb_created %}
<div>
{{ n }} record created.{% plural %}{{ n }} records created.
</div>
<div id="collapse-$celery_id" class="collapse">
<div class="nb-success">
{% blocktrans count n=nb_success %}
{{ n }}/{{ nb_lines }} line imported.{% plural %}{{ n }}/{{ nb_lines }} lines imported.
{% endblocktrans %}
{% endif %}

{% if nb_updated %}
{% blocktrans count n=nb_updated %}
<div>
{{ n }} record updated.{% plural %}{{ n }} records updated.
</div>
{% endblocktrans %}
{% endif %}

{% if nb_deleted %}
{% blocktrans count n=nb_deleted %}
<div>
{{ n }} record deleted.{% plural %}{{ n }} records deleted.
</div>
{% endblocktrans %}
{% endif %}
{% if nb_created %}
<div class="nb-created">
{% blocktrans count n=nb_created %}
{{ n }} record created.{% plural %}{{ n }} records created.
{% endblocktrans %}
</div>
{% endif %}

{% if nb_unmodified %}
{% blocktrans count n=nb_unmodified %}
<div>
{{ n }} record unmodified.{% plural %}{{ n }} records unmodified.
</div>
{% endblocktrans %}
{% endif %}
{% if nb_updated %}
<div class="nb-updated">
{% blocktrans count n=nb_updated %}
{{ n }} record updated.{% plural %}{{ n }} records updated.
{% endblocktrans %}
</div>
{% endif %}

{% if warnings %}
{% blocktrans count n=warnings|length %}
<div>
{{ n }} warning:{% plural %}{{ n }} warnings:
</div>
{% endblocktrans %}
{% if nb_deleted %}
<div class="nb-deleted">
{% blocktrans count n=nb_deleted %}
{{ n }} record deleted.{% plural %}{{ n }} records deleted.
{% endblocktrans %}
</div>
{% endif %}

{% if nb_unmodified %}
<div class="nb-unmodified">
{% blocktrans count n=nb_unmodified %}
{{ n }} record unmodified.{% plural %}{{ n }} records unmodified.
{% endblocktrans %}
</div>
{% endif %}

{% for id, msgs in warnings.iteritems %}# {{ id }}:
{% for msg in msgs %}- {{ msg|safe }},
{% if warnings %}
<div class="warnings">
{% blocktrans count n=warnings|length %}
{{ n }} warning:{% plural %}{{ n }} warnings:
{% endblocktrans %}

<ul>
{% for id, msgs in warnings.iteritems %}
<li><div># {{ id }}:</div>
{% for msg in msgs %}
<div>- {{ msg|safe }},</div></li>
{% endfor %}
{% endfor %}
{% endfor %}
{% endif %}
</ul>
</div>
{% endif %}
</div>

0 comments on commit 8209e60

Please sign in to comment.