aboutsummaryrefslogtreecommitdiffstats
path: root/pyblackbird_cc/resources/views.py
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-08-03 16:26:16 +0100
committerMatthew Lemon <y@yulqen.org>2024-08-03 16:26:16 +0100
commit7b757fcd38ca560139aa3c4c86ae57b4c6afe2dd (patch)
tree76f63bd0f576660154f90dd5f2119edd9b3d1006 /pyblackbird_cc/resources/views.py
parenta75aca148ba7db29e14e30f2e0707b1efac1ff94 (diff)
wip: adding the update thumbnails form
Diffstat (limited to 'pyblackbird_cc/resources/views.py')
-rw-r--r--pyblackbird_cc/resources/views.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/pyblackbird_cc/resources/views.py b/pyblackbird_cc/resources/views.py
index 07227e4..2feb655 100644
--- a/pyblackbird_cc/resources/views.py
+++ b/pyblackbird_cc/resources/views.py
@@ -17,7 +17,7 @@ from django.shortcuts import redirect
from django.shortcuts import render
from . import services
-from .forms import ResourceCreateForm
+from .forms import ResourceCreateForm, ResourceUpdateThumbnailsForm
from .forms import ResourceUpdateMetadataForm
from .models import PDFPageSnapshot, ResourceSubcategory
from .models import PDFResource
@@ -185,7 +185,7 @@ def upload_to_s3(pdf_files, thumbnail_files, snapshotted_pages) -> bool:
f"thumbnails/{f.name}",
)
if _get_pdf_collection_type(snapshotted_pages) == "SINGLE_PDF_SINGLE_PAGE" \
- or _get_pdf_collection_type(snapshotted_pages) == "SINGLE_PDF_MULTI_PAGE":
+ or _get_pdf_collection_type(snapshotted_pages) == "SINGLE_PDF_MULTI_PAGE":
for img in snapshotted_pages[0]:
logger.info("Uploading {img} to S3")
client.upload_file(
@@ -195,7 +195,7 @@ def upload_to_s3(pdf_files, thumbnail_files, snapshotted_pages) -> bool:
)
return True
if _get_pdf_collection_type(snapshotted_pages) == "MULTI_PDF_SINGLE_PAGE" \
- or _get_pdf_collection_type(snapshotted_pages) == "MULTI_PDF_MULTI_PAGE":
+ or _get_pdf_collection_type(snapshotted_pages) == "MULTI_PDF_MULTI_PAGE":
for pdf in snapshotted_pages:
for img in pdf:
logger.info("Uploading {img} to S3")
@@ -221,7 +221,7 @@ def _write_pdf_to_tempdir(f) -> str:
def create_metadata(
- pdf_files,
+ pdf_files,
) -> Generator[tuple[services.PDFMetadata, str], None, None]:
with tempfile.TemporaryDirectory() as temp_dir:
for pdf_file in pdf_files:
@@ -372,6 +372,17 @@ def resource_detail(request, resource_id):
return render(request, "resources/resource_detail.html", {"resource": resource})
+def update_resource_thumbnails(request, pk):
+ resource = get_object_or_404(Resource, pk=pk)
+ if request.method == "POST":
+ form = ResourceUpdateThumbnailsForm(request.POST, request.FILES)
+
+ else:
+ form = ResourceUpdateThumbnailsForm(resource=pk)
+
+ return render(request, "resources/update_thumbnails.html", {"form": form, "resource": resource})
+
+
@login_required
def hx_download_button(request):
"""