From 0285d2507455546be0beb440f996bd69806634ec Mon Sep 17 00:00:00 2001 From: Jay Varner Date: Fri, 13 Dec 2024 09:13:10 -0500 Subject: [PATCH] Actually call the canvas check. Add thumbnails to warnings email --- readux_ingest_ecds/admin.py | 2 ++ readux_ingest_ecds/mail.py | 18 +++++++++++++++--- readux_ingest_ecds/models.py | 2 +- readux_ingest_ecds/services/ocr_services.py | 2 +- readux_ingest_ecds/tasks.py | 17 ++--------------- .../templates/ingest_ecds_success_email.html | 14 +++++++++----- test_app/tests/test_ocr.py | 3 ++- 7 files changed, 32 insertions(+), 26 deletions(-) diff --git a/readux_ingest_ecds/admin.py b/readux_ingest_ecds/admin.py index 83f81eb..29e825f 100644 --- a/readux_ingest_ecds/admin.py +++ b/readux_ingest_ecds/admin.py @@ -14,7 +14,9 @@ class LocalAdmin(admin.ModelAdmin): """Django admin ingest.models.local resource.""" + list_display = ["manifest"] fields = ("bundle", "image_server", "collections") + readonly_fields = ["manifest", "warnings"] show_save_and_add_another = False def save_model(self, request, obj, form, change): diff --git a/readux_ingest_ecds/mail.py b/readux_ingest_ecds/mail.py index b939c35..ad2efd7 100644 --- a/readux_ingest_ecds/mail.py +++ b/readux_ingest_ecds/mail.py @@ -47,9 +47,21 @@ def send_email_on_success(creator=None, manifest=None, warnings=None): ingest_warnings = ( warnings if warnings is not None and len(warnings) > 10 else None ) - context["warnings"] = ( - ingest_warnings.split("$$$$") if ingest_warnings is not None else None - ) + context["warnings"] = "" + context["html_warnings"] = [] + if ingest_warnings is not None: + warnings = ingest_warnings.split(" | ") + context["warnings"] = [ + f'{w} -- https://iip.readux.io/iiif/3/{w.split(" ")[1]}/full/250,/0/default.jpg' + for w in warnings + ] + context["html_warnings"] = [ + [ + w, + f'', + ] + for w in warnings + ] html_email = get_template("ingest_ecds_success_email.html").render(context) text_email = get_template("ingest_ecds_success_email.txt").render(context) diff --git a/readux_ingest_ecds/models.py b/readux_ingest_ecds/models.py index c565778..5d13c79 100644 --- a/readux_ingest_ecds/models.py +++ b/readux_ingest_ecds/models.py @@ -242,6 +242,7 @@ def create_canvases(self): new_canvases.append(new_canvas) Canvas.objects.bulk_create(new_canvases) + self.check_canvases() upload_trigger_file(self.trigger_file) @@ -272,7 +273,6 @@ def success(self): index = ManifestDocument() index.update(self.manifest, True, "index") - self.delete() def failure(self, exc): LOGGER.info(f"FAIL!!! {self.manifest.pid}") diff --git a/readux_ingest_ecds/services/ocr_services.py b/readux_ingest_ecds/services/ocr_services.py index 0d9d908..edbe474 100644 --- a/readux_ingest_ecds/services/ocr_services.py +++ b/readux_ingest_ecds/services/ocr_services.py @@ -546,7 +546,7 @@ def add_ocr_to_canvases(manifest): elif ocr is not None: new_ocr_annotations += add_ocr_annotations(canvas, ocr) else: - warnings.append(f"No OCR for {canvas.pid}") + warnings.append(f"Canvas {canvas.pid} - No OCR") chunks = divide_chunks(new_ocr_annotations, 100) for chunk in list(chunks): diff --git a/readux_ingest_ecds/tasks.py b/readux_ingest_ecds/tasks.py index f6668bc..9298d01 100644 --- a/readux_ingest_ecds/tasks.py +++ b/readux_ingest_ecds/tasks.py @@ -130,6 +130,7 @@ def add_canvases_task(ingest_id, manifest_pid, *args, **kwargs): @app.task( name="add_ocr_task_local_ecds", + base=FinalTask, autoretry_for=(Manifest.DoesNotExist,), retry_backoff=5, ) @@ -139,24 +140,10 @@ def add_ocr_task_local(ingest_id, manifest_pid, *args, **kwargs): local_ingest = Local.objects.get(pk=ingest_id) manifest = Manifest.objects.get(pk=local_ingest.manifest.pk) warnings = add_ocr_to_canvases(manifest) - local_ingest.warnings = "$$$$".join(warnings) + local_ingest.warnings = " | ".join(warnings) local_ingest.save() -@app.task( - name="verify_canvases_task", - base=FinalTask, - autoretry_for=(Exception,), - retry_backoff=True, - max_retries=2, -) -def verify_canvases_task(ingest_id, *args, **kwargs): - """Task to call check for duplicate canvases""" - local_ingest = Local.objects.get(pk=ingest_id) - LOGGER.info(f"Checking canvases {local_ingest.manifest.pid}") - local_ingest.check_canvases() - - @app.task( name="s3_ingest_task_ecds", autoretry_for=(Exception,), diff --git a/readux_ingest_ecds/templates/ingest_ecds_success_email.html b/readux_ingest_ecds/templates/ingest_ecds_success_email.html index 4748d24..2c2cb01 100644 --- a/readux_ingest_ecds/templates/ingest_ecds_success_email.html +++ b/readux_ingest_ecds/templates/ingest_ecds_success_email.html @@ -12,11 +12,15 @@

Ingest complete: {{ manifest_pid }}

  • Link to volume
  • -{% if warnings is not None %} +{% if html_warnings is not None %}

    Warnings

    -