Validate constraints.meals_mode + meals_note (times-only meal schedules) - #267
Merged
Conversation
The frontend adds a times-only meals mode: meals_mode "schedule" shows
hackers just the meal times (no item selection) with an optional meals_note
intro line. Both hackathon validators now enforce meals_mode in
ALLOWED_MEALS_MODES {menu, schedule} and meals_note as a string capped at
MAX_MEALS_NOTE_LENGTH (500), with partial-save skip semantics. Kept in sync
with MEALS_MODE_* / MEALS_NOTE_MAX_LENGTH in the frontend MealSchedule.js.
Co-Authored-By: Claude Fable 5 <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.
What
Companion to frontend PR opportunity-hack/frontend-ohack.dev#350 (times-only meals mode). The frontend adds two hackathon constraint keys:
constraints.meals_mode:"menu"(default; hackers pick one item per slot) |"schedule"(times-only — the hacker application shows just the meal schedule, nothing to select)constraints.meals_note: optional intro line shown above the times-only scheduleBoth keys already flow through the permissive constraints passthrough; this PR makes them validated:
ALLOWED_MEALS_MODES = {"menu", "schedule"}andMAX_MEALS_NOTE_LENGTH = 500incommon/utils/validators.py, kept in sync withMEALS_MODE_*/MEALS_NOTE_MAX_LENGTHin the frontendsrc/components/ApplicationForm/MealSchedule.js.validate_hackathon_data: rejects unknown/non-stringmeals_modeand non-string/over-lengthmeals_note(None/"" are fine — they resolve to the default menu mode).validate_hackathon_data_partial: same checks with the established skip-and-strip semantics, so one bad key never blocks the rest of an admin save.No change to
validate_mealsitself — a meal with noitemswas already valid, which is what times-only slots produce.Tests
test/common/utils/test_validators.py: meals with no items passvalidate_meals; both modes + unset/empty accepted; bad mode (string and unhashable) rejected; note length/type bounds; partial validator keeps valid values and strips invalid ones while saving the rest.python -m pytest test/common/utils/test_validators.py→ 10 passed.🤖 Generated with Claude Code