Add image preview + square cropping to Awards admin badge (#1408)#1409
Merged
Conversation
The Awards admin badge upload didn't follow the standard image pattern
(People/News/Sponsor): no instant client-side preview, no cropping. Apply
the ImageCroppingMixin + ImageRatioField (Cropper.js) pattern.
- Award.badge_cropping: square 245x245 ImageRatioField, matching the
portrait/sponsor anchors so award-row anchors read as uniform squares.
- AwardAdmin subclasses ImageCroppingMixin; badge_cropping in the Display
fieldset; new square "Badge" thumbnail column on the changelist.
- display_award_snippet renders the badge via {% thumbnail box=badge_cropping
crop %} so the crop is applied (was raw badge.url).
- .award-anchor-badge: contain/borderless -> shared square cover+border tile.
- Tests pin badge crop metadata + AwardAdmin badge -> Cropper.js widget.
Existing badges keep a blank crop box until re-saved; crop_corners treats
blank as no-box and center-crops, so nothing breaks in the meantime.
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 #1408.
What & why
The new Awards admin badge upload didn't follow our standard image-upload pattern (People headshots, News thumbnails, Sponsor logos): no instant client-side preview, no cropping. This applies the established
ImageCroppingMixin+ImageRatioField(Cropper.js) pattern toAward.badge.Changes
website/models/award.py— newbadge_croppingsquare (245x245)ImageRatioField. Square matches the Person portrait / Sponsor icon anchors, so every award-row anchor (badge, portrait, project thumbnail, medal) reads as a uniform square tile. Stores an"x1,y1,x2,y2"box string; no committed migration (migrations are gitignored, auto-generated on container start).website/admin/award_admin.py—AwardAdminsubclassesImageCroppingMixin(Cropper.js preview/crop before first save);badge_croppingadded to the Display fieldset; new square "Badge" thumbnail column on the changelist (mirrorsSponsorAdmin/NewsAdmin).website/templates/snippets/display_award_snippet.html— badge anchor now renders through{% thumbnail award.badge 245x245 box=award.badge_cropping crop upscale %}so the stored crop is applied (was rawbadge.url).website/static/website/css/awards.css—.award-anchor-badgeswitched fromobject-fit: contain/borderless to the shared squarecover+border tile for uniformity.website/tests/test_image_cropping.py— regression tests pinning theAward.badgecrop metadata and thatAwardAdminresolves the badge field to the Cropper.js widget.Notes
crop_cornerstreats blank as "no box" and center-crops, so nothing breaks meanwhile (they'll look best after a quick re-crop).Testing
test_image_cropping+test_awardsuites pass (28 tests);manage.py checkclean.🤖 Generated with Claude Code