Skip to content

Add image preview + square cropping to Awards admin badge (#1408)#1409

Merged
jonfroehlich merged 1 commit into
masterfrom
1408-awards-badge-crop
Jun 28, 2026
Merged

Add image preview + square cropping to Awards admin badge (#1408)#1409
jonfroehlich merged 1 commit into
masterfrom
1408-awards-badge-crop

Conversation

@jonfroehlich

Copy link
Copy Markdown
Member

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 to Award.badge.

Changes

  • website/models/award.py — new badge_cropping square (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.pyAwardAdmin subclasses ImageCroppingMixin (Cropper.js preview/crop before first save); badge_cropping added to the Display fieldset; new square "Badge" thumbnail column on the changelist (mirrors SponsorAdmin/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 raw badge.url).
  • website/static/website/css/awards.css.award-anchor-badge switched from object-fit: contain/borderless to the shared square cover+border tile for uniformity.
  • website/tests/test_image_cropping.py — regression tests pinning the Award.badge crop metadata and that AwardAdmin resolves the badge field to the Cropper.js widget.

Notes

  • Square crop is intentional — keeps the public Awards row uniform; editors re-crop on upload.
  • Existing badges keep a blank crop box until re-saved; crop_corners treats 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_award suites pass (28 tests); manage.py check clean.
  • ⚠️ TODO before merge (UI change): add before/after screenshots of an award card and run the Pa11y a11y service per CONTRIBUTING.

🤖 Generated with Claude Code

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>
@jonfroehlich jonfroehlich merged commit be9e4e3 into master Jun 28, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Awards admin: add instant image preview + square cropping for the badge field

1 participant