From 28567e2d8eb0ec69c100d7050e2f16e4f5ced32c Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 17 Nov 2022 15:19:42 -0800 Subject: [PATCH] Disable imports in the UI and view --- bookwyrm/templates/import/import.html | 157 ++++++++++++++------------ bookwyrm/views/imports/import_data.py | 5 + 2 files changed, 89 insertions(+), 73 deletions(-) diff --git a/bookwyrm/templates/import/import.html b/bookwyrm/templates/import/import.html index a2924703c..141e5671e 100644 --- a/bookwyrm/templates/import/import.html +++ b/bookwyrm/templates/import/import.html @@ -8,83 +8,94 @@

{% trans "Import Books" %}

- {% if recent_avg_hours or recent_avg_minutes %} -
-

- {% if recent_avg_hours %} - {% blocktrans trimmed with hours=recent_avg_hours|floatformat:0|intcomma %} - On average, recent imports have taken {{ hours }} hours. - {% endblocktrans %} - {% else %} - {% blocktrans trimmed with minutes=recent_avg_minutes|floatformat:0|intcomma %} - On average, recent imports have taken {{ minutes }} minutes. - {% endblocktrans %} + {% if site.imports_enabled %} + {% if recent_avg_hours or recent_avg_minutes %} +

+

+ {% if recent_avg_hours %} + {% blocktrans trimmed with hours=recent_avg_hours|floatformat:0|intcomma %} + On average, recent imports have taken {{ hours }} hours. + {% endblocktrans %} + {% else %} + {% blocktrans trimmed with minutes=recent_avg_minutes|floatformat:0|intcomma %} + On average, recent imports have taken {{ minutes }} minutes. + {% endblocktrans %} + {% endif %} +

+
{% endif %} + +
+ {% csrf_token %} + +
+
+
+ + +
+ +
+ +

+ {% blocktrans trimmed %} + You can download your Goodreads data from the + Import/Export page + of your Goodreads account. + {% endblocktrans %} +

+
+ +
+ + {{ import_form.csv_file }} +
+
+ +
+
+ +
+
+ + {% include 'snippets/privacy_select.html' with no_label=True privacy_uuid="import" %} +
+
+
+ +
+ {% else %} +
+

+ +

+

+ {% trans "Imports are temporarily disabled; thank you for your patience." %}

{% endif %} - -
- {% csrf_token %} - -
-
-
- - -
- -
- -

- {% blocktrans trimmed %} - You can download your Goodreads data from the - Import/Export page - of your Goodreads account. - {% endblocktrans %} -

-
- -
- - {{ import_form.csv_file }} -
-
- -
-
- -
-
- - {% include 'snippets/privacy_select.html' with no_label=True privacy_uuid="import" %} -
-
-
- -
diff --git a/bookwyrm/views/imports/import_data.py b/bookwyrm/views/imports/import_data.py index f9c62a15d..99fd7fc4c 100644 --- a/bookwyrm/views/imports/import_data.py +++ b/bookwyrm/views/imports/import_data.py @@ -4,6 +4,7 @@ import datetime from django.contrib.auth.decorators import login_required from django.db.models import Avg, ExpressionWrapper, F, fields +from django.core.exceptions import PermissionDenied from django.core.paginator import Paginator from django.http import HttpResponseBadRequest from django.shortcuts import redirect @@ -54,6 +55,10 @@ class Import(View): def post(self, request): """ingest a goodreads csv""" + site = models.Site.objects.get() + if not site.imports_enabled: + raise PermissionDenied() + form = forms.ImportForm(request.POST, request.FILES) if not form.is_valid(): return HttpResponseBadRequest()