Show PDF thumbnail on artifact admin change form (#1380)#1381
Merged
Conversation
Editors only saw a "Currently: <filename>" link on the Publication / Talk / Poster change forms, with no way to visually confirm the right PDF was attached. Add a read-only `thumbnail_preview` field on ArtifactAdmin that renders the auto-generated `thumbnail` as a ~220px-tall <img> via easy_thumbnails (same pipeline as the changelist `get_display_thumbnail`). - Injected into the 'Files' fieldset via `get_fieldsets()` on ArtifactAdmin, so all three child admins get it without editing each `fieldsets`. Change view only (the Add form has no saved thumbnail yet). - Degrades to a text placeholder when there's no thumbnail or the source file is missing on disk (happens on the servers) rather than 500ing the page. - Regression tests: img/placeholder/missing-file paths, fieldset injection across all three admins (change only, not add), no class-level mutation, and a full change-form GET asserting the <img> renders unescaped. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
# Conflicts: # website/admin/artifact_admin.py
#1380) Per review feedback, "Thumbnail preview" → "PDF thumbnail" on the change form (clearer that it's the PDF-derived thumbnail). Also updates the <img> alt text and the regression test to match. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1380.
What & why
Editors previously only saw a "Currently:
<filename>" link on the Publication / Talk / Poster admin change forms — no way to visually confirm the right PDF was attached. This adds a read-only PDF thumbnail preview to the Files fieldset.How
thumbnail_preview(self, obj)onArtifactAdminrenders the auto-generatedthumbnailas a ~220px-tall<img>via easy_thumbnails (same pipeline as the changelistget_display_thumbnail).ArtifactAdmin.get_fieldsets()so all three child admins get it without editing eachfieldsets. Change view only (the Add form has no saved thumbnail yet).This composes cleanly with the #248 upload-guard work already on master (both touch
ArtifactAdmin; merged in this branch).Tests
website/tests/test_admin_thumbnail_preview.py(8 tests): img / placeholder / missing-file paths,None-obj guard, fieldset injection across all three admins (change-only, not add), no class-levelfieldsetsmutation, and a full change-form GET asserting the<img>renders unescaped.Run:
python manage.py test website.tests.test_admin_thumbnail_preview --settings=makeabilitylab.settings_test→ 8/8 pass. Also re-ran #248 + changelist suites — no regressions.Screenshots
🤖 Generated with Claude Code