Skip to content

Commit

Permalink
Actually call the canvas check. Add thumbnails to warnings email
Browse files Browse the repository at this point in the history
  • Loading branch information
jayvarner committed Dec 13, 2024
1 parent f21b1ce commit 0285d25
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 26 deletions.
2 changes: 2 additions & 0 deletions readux_ingest_ecds/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
18 changes: 15 additions & 3 deletions readux_ingest_ecds/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'<img src="https://iip.readux.io/iiif/3/{w.split(" ")[1]}/full/250,/0/default.jpg" />',
]
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)
Expand Down
2 changes: 1 addition & 1 deletion readux_ingest_ecds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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}")
Expand Down
2 changes: 1 addition & 1 deletion readux_ingest_ecds/services/ocr_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
17 changes: 2 additions & 15 deletions readux_ingest_ecds/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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,),
Expand Down
14 changes: 9 additions & 5 deletions readux_ingest_ecds/templates/ingest_ecds_success_email.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ <h3 style="color: green;">Ingest complete: {{ manifest_pid }}</h3>
<li><a href="{{ volume_url }}">Link to volume</a></li>
</ul>
</p>
{% if warnings is not None %}
{% if html_warnings is not None %}
<p>Warnings</p>
<ul>
{% for warning in warnings %}
<li>{{ warning }}</li>
<table>
{% for warning in html_warnings %}
<tr>
{% for part in warning %}
<td>{{ part }}</td>
{% endfor %}
</tr>
{% endfor %}
</ul>
</table>
{% endif %}
3 changes: 2 additions & 1 deletion test_app/tests/test_ocr.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def test_empty_xml(self):
local.refresh_from_db()
local.success()
assert local.warnings.startswith(
f"Canvas {canvas.pid} - XMLSyntaxError: Document is empty, line 1, column 1 (<string>, line 1)$$$$"
f"Canvas {canvas.pid} - XMLSyntaxError: Document is empty, line 1, column 1 (<string>, line 1) | "
)
assert "XMLSyntaxError" in mail.outbox[0].body
assert "iip" in mail.outbox[0].body

0 comments on commit 0285d25

Please sign in to comment.