diff --git a/bookwyrm/models/import_job.py b/bookwyrm/models/import_job.py index 7547cfcd2..18aad6d88 100644 --- a/bookwyrm/models/import_job.py +++ b/bookwyrm/models/import_job.py @@ -53,6 +53,7 @@ class ImportJob(models.Model): """How many books do you want to import???""" return self.items.count() + @property def pending_item_count(self): """And how many pending items??""" return self.pending_items.count() diff --git a/bookwyrm/templates/settings/imports/complete_import_modal.html b/bookwyrm/templates/settings/imports/complete_import_modal.html new file mode 100644 index 000000000..64d571764 --- /dev/null +++ b/bookwyrm/templates/settings/imports/complete_import_modal.html @@ -0,0 +1,23 @@ +{% extends 'components/modal.html' %} +{% load i18n %} + +{% block modal-title %}{% trans "Mark import as complete?" %}{% endblock %} + +{% block modal-body %} +{% trans "This action cannot be un-done" %} +{% endblock %} + +{% block modal-footer %} +
+ {% csrf_token %} + +
+ + +
+
+{% endblock %} diff --git a/bookwyrm/templates/settings/imports.html b/bookwyrm/templates/settings/imports/imports.html similarity index 75% rename from bookwyrm/templates/settings/imports.html rename to bookwyrm/templates/settings/imports/imports.html index b5936abba..f99e35209 100644 --- a/bookwyrm/templates/settings/imports.html +++ b/bookwyrm/templates/settings/imports/imports.html @@ -26,9 +26,11 @@
+ {% if status == "active" %}

{% trans "Marking an import as complete will not stop it." %}

+ {% endif %} {% url 'settings-imports' as url %} @@ -47,7 +49,9 @@ + {% if status == "active" %} + {% endif %} {% for import in imports %} @@ -58,11 +62,22 @@ + {% if status == "active" %} + {% endif %} {% endfor %} + {% if not imports %} + + + + {% endif %}
{% trans "Pending items" %} {% trans "Actions" %}
{{ import.created_date }} {{ import.item_count }} {{ import.pending_item_count }} - + {% join "complete" import.id as modal_id %} + + {% include "settings/imports/complete_import_modal.html" with id=modal_id %}
+ {% trans "No matching imports founds." %} +
diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 1f2efa5f3..397d12204 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -294,6 +294,9 @@ urlpatterns = [ re_path( r"^settings/imports/(?P(complete|active))?/?$", views.ImportList.as_view(), name="settings-imports" ), + re_path( + r"^settings/imports/(?P\d+)/complete?$", views.ImportList.as_view(), name="settings-imports-complete" + ), re_path( r"^settings/celery/?$", views.CeleryStatus.as_view(), name="settings-celery" ), diff --git a/bookwyrm/views/admin/imports.py b/bookwyrm/views/admin/imports.py index 25fc0c77f..9ebfce41f 100644 --- a/bookwyrm/views/admin/imports.py +++ b/bookwyrm/views/admin/imports.py @@ -1,6 +1,7 @@ """ manage imports """ from django.contrib.auth.decorators import login_required, permission_required from django.core.paginator import Paginator +from django.shortcuts import get_object_or_404, redirect from django.template.response import TemplateResponse from django.utils.decorators import method_decorator from django.views import View @@ -29,5 +30,14 @@ class ImportList(View): "page_range": paginated.get_elided_page_range( page.number, on_each_side=2, on_ends=1 ), + "status": status, } - return TemplateResponse(request, "settings/imports.html", data) + return TemplateResponse(request, "settings/imports/imports.html", data) + + # pylint: disable=unused-argument + def post(self, request, import_id): + """Mark an import as complete""" + import_job = get_object_or_404(models.ImportJob, id=import_id) + import_job.complete = True + import_job.save() + return redirect("settings-imports")