forked from mirrors/bookwyrm
Adds retry page
This commit is contained in:
parent
2a84c0a370
commit
a65f07e0bf
5 changed files with 76 additions and 4 deletions
|
@ -32,12 +32,28 @@
|
|||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if complete and fail_count %}
|
||||
<div class="notification is-warning">
|
||||
{% blocktrans trimmed count counter=fail_count with display_counter=fail_count|intcomma %}
|
||||
{{ display_counter }} item failed to import.
|
||||
{% plural %}
|
||||
{{ display_counter }} items failed to import.
|
||||
{% endblocktrans %}
|
||||
<a href="{% url 'import-troubleshoot' job.id %}">
|
||||
{% trans "View and troubleshoot failed items." %}
|
||||
</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
</header>
|
||||
|
||||
<div class="block">
|
||||
<h2 class="title is-4">
|
||||
{% block page_title %}
|
||||
{% trans "Your Import" %}
|
||||
{% endblock %}
|
||||
</h2>
|
||||
{% block actions %}{% endblock %}
|
||||
<table class="table">
|
||||
<tr>
|
||||
<th>
|
||||
|
|
30
bookwyrm/templates/import/troubleshoot.html
Normal file
30
bookwyrm/templates/import/troubleshoot.html
Normal file
|
@ -0,0 +1,30 @@
|
|||
{% extends 'import/import_status.html' %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block title %}{% trans "Import Troubleshooting" %}{% endblock %}
|
||||
|
||||
{% block page_title %}
|
||||
{% trans "Failed items" %}
|
||||
{% endblock %}
|
||||
|
||||
{% block actions %}
|
||||
<div class="block">
|
||||
<div class="notification content">
|
||||
<p>
|
||||
{% trans "Re-trying an import can fix missing items in cases such as:" %}
|
||||
<ul>
|
||||
<li>{% trans "The book has been added to the instance since this import" %}</li>
|
||||
<li>{% trans "A transient error or timeout caused the external data source to be unavailable." %}</li>
|
||||
<li>{% trans "BookWyrm has been updated since this import with a bug fix" %}</li>
|
||||
</ul>
|
||||
</p>
|
||||
<p>
|
||||
{% trans "Contact your admin or <a href='https://github.com/bookwyrm-social/bookwyrm/issues'>open an issue</a> if you are seeing unexpected failed items." %}
|
||||
</p>
|
||||
</div>
|
||||
<form name="retry" method="post" action="{% url 'import-troubleshoot' job.id %}">
|
||||
{% csrf_token %}
|
||||
<button type="submit" class="button">Retry all</button>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -238,6 +238,7 @@ urlpatterns = [
|
|||
# imports
|
||||
re_path(r"^import/?$", views.Import.as_view(), name="import"),
|
||||
re_path(r"^import/(\d+)/?$", views.ImportStatus.as_view(), name="import-status"),
|
||||
re_path(r"^import/(\d+)/failed/?$", views.ImportTroubleshoot.as_view(), name="import-troubleshoot"),
|
||||
# users
|
||||
re_path(rf"{USER_PATH}\.json$", views.User.as_view()),
|
||||
re_path(rf"{USER_PATH}/?$", views.User.as_view(), name="user-feed"),
|
||||
|
|
|
@ -62,7 +62,7 @@ from .group import (
|
|||
accept_membership,
|
||||
reject_membership,
|
||||
)
|
||||
from .import_data import Import, ImportStatus
|
||||
from .import_data import Import, ImportStatus, ImportTroubleshoot
|
||||
from .inbox import Inbox
|
||||
from .interaction import Favorite, Unfavorite, Boost, Unboost
|
||||
from .isbn import Isbn
|
||||
|
|
|
@ -93,6 +93,7 @@ class ImportStatus(View):
|
|||
data = {
|
||||
"job": job,
|
||||
"items": page,
|
||||
"fail_count": items.filter(fail_reason__isnull=False).count(),
|
||||
"page_range": paginated.get_elided_page_range(
|
||||
page.number, on_each_side=2, on_ends=1
|
||||
),
|
||||
|
@ -104,12 +105,36 @@ class ImportStatus(View):
|
|||
|
||||
return TemplateResponse(request, "import/import_status.html", data)
|
||||
|
||||
|
||||
@method_decorator(login_required, name="dispatch")
|
||||
class ImportTroubleshoot(View):
|
||||
"""problems items in an existing import"""
|
||||
|
||||
def get(self, request, job_id):
|
||||
"""status of an import job"""
|
||||
job = get_object_or_404(models.ImportJob, id=job_id)
|
||||
if job.user != request.user:
|
||||
raise PermissionDenied()
|
||||
|
||||
items = job.items.order_by("index").filter(fail_reason__isnull=False)
|
||||
|
||||
paginated = Paginator(items, PAGE_LENGTH)
|
||||
page = paginated.get_page(request.GET.get("page"))
|
||||
data = {
|
||||
"job": job,
|
||||
"items": page,
|
||||
"page_range": paginated.get_elided_page_range(
|
||||
page.number, on_each_side=2, on_ends=1
|
||||
),
|
||||
"complete": True,
|
||||
}
|
||||
|
||||
return TemplateResponse(request, "import/troubleshoot.html", data)
|
||||
|
||||
def post(self, request, job_id):
|
||||
"""retry lines from an import"""
|
||||
job = get_object_or_404(models.ImportJob, id=job_id)
|
||||
items = []
|
||||
for item in request.POST.getlist("import_item"):
|
||||
items.append(get_object_or_404(models.ImportItem, id=item))
|
||||
items = job.items.filter(fail_reason__isnull=False)
|
||||
|
||||
importer = Importer()
|
||||
job = importer.create_retry_job(
|
||||
|
|
Loading…
Reference in a new issue