Show failed books

This commit is contained in:
Mouse Reeve 2020-11-12 13:52:57 -08:00
parent 799496bb86
commit 032ce8efba
2 changed files with 26 additions and 4 deletions

View file

@ -26,7 +26,24 @@
{% endif %}
</div>
{% if failed_items %}
<div class="block">
<h2 class="title is-4">Failed to load</h2>
<ul>
{% for item in failed_items %}
<li>
Line {{ item.index }}:
<strong>{{ item.data|dict_key:'Title' }}</strong> by
{{ item.data|dict_key:'Author' }}
({{ item.fail_reason }})
</li>
{% endfor %}
</ul>
</div>
{% endif %}
<div class="block">
<h2 class="title is-4">Successfully imported</h2>
<table class="table">
<tr>
<th>
@ -57,9 +74,10 @@
{{ item.data|dict_key:'Author' }}
</td>
<td>
{% if item.book %}✓
{% elif item.fail_reason %}
{{ item.fail_reason }}
{% if item.book %}
<span class="icon icon-check">
<span class="is-sr-only">Imported</span>
</span>
{% endif %}
</td>
</tr>

View file

@ -209,10 +209,14 @@ def import_status(request, job_id):
if job.user != request.user:
raise PermissionDenied
task = app.AsyncResult(job.task_id)
items = job.items.order_by('index').all()
failed_items = [i for i in items if i.fail_reason]
items = [i for i in items if not i.fail_reason]
return TemplateResponse(request, 'import_status.html', {
'title': 'Import Status',
'job': job,
'items': job.items.order_by('index').all(),
'items': items,
'failed_items': failed_items,
'task': task
})