meeting words come from the units table; the constants are now defaults
MEETING_DAY, MEETING_DAYS, MEETING_DAY_ABBR, PACK_TIME, TROOP_TIME, PACK_CLOCK and TROOP_CLOCK were the last thing a leader could not change without a commit. identity.meeting_words() derives all seven from the units rows; app.py refreshes the module globals from it on a 30-second TTL in a middleware, and the page templates - f-strings that read those globals when a route runs - are untouched. A row that cannot supply a word keeps the default, so a half-filled unit degrades to today's copy rather than a blank. The day words come from the pack row: the site's copy assumes both units meet the same night, and if that changes the copy needs rewriting, not a bigger constant. Proven on a throwaway container with a DB copy: patching pack73 to Thursday 18:15 changed the homepage, cubs, troop and meta description; patching back restored them. tests/smoke_identity.py 59 -> 66.
This commit is contained in:
@@ -338,6 +338,43 @@ def get_unit(slug_or_id):
|
||||
# code change.
|
||||
UNIT_MEETS_FIELDS = ("meets_weekday", "meets_time", "meets_at")
|
||||
|
||||
WEEKDAY_NAMES = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
|
||||
|
||||
|
||||
def clock_words(hhmm):
|
||||
""""18:00" -> ("6:00 PM", "6:00"). Returns None on anything unparseable so
|
||||
the caller keeps its fallback rather than rendering a blank."""
|
||||
try:
|
||||
t = datetime.datetime.strptime(str(hhmm), "%H:%M")
|
||||
except (TypeError, ValueError):
|
||||
return None
|
||||
h12 = t.hour % 12 or 12
|
||||
clock = "%d:%02d" % (h12, t.minute)
|
||||
return ("%s %s" % (clock, "AM" if t.hour < 12 else "PM"), clock)
|
||||
|
||||
|
||||
def meeting_words(units, defaults):
|
||||
"""The seven seasonal strings app.py renders, derived from the units rows.
|
||||
|
||||
`defaults` is the dict of the code constants; any word a row cannot supply
|
||||
keeps its default, so a half-filled unit row degrades to today's copy and
|
||||
never to a blank page. The day words come from the PACK row: the site's
|
||||
copy assumes both units meet the same night ("right after the pack"), and
|
||||
if that ever changes the copy needs rewriting, not a bigger constant.
|
||||
"""
|
||||
out = dict(defaults)
|
||||
by = {u.get("slug"): u for u in units}
|
||||
pack, troop = by.get("pack73"), by.get("troop73")
|
||||
day = (pack or troop or {}).get("meets_weekday")
|
||||
if isinstance(day, int) and 1 <= day <= 7:
|
||||
name = WEEKDAY_NAMES[day - 1]
|
||||
out["MEETING_DAY"], out["MEETING_DAYS"], out["MEETING_DAY_ABBR"] = name, name + "s", name[:3]
|
||||
for row, tkey, ckey in ((pack, "PACK_TIME", "PACK_CLOCK"), (troop, "TROOP_TIME", "TROOP_CLOCK")):
|
||||
w = clock_words((row or {}).get("meets_time"))
|
||||
if w:
|
||||
out[tkey], out[ckey] = w
|
||||
return out
|
||||
|
||||
|
||||
def update_unit_meets(slug_or_id, fields):
|
||||
"""Change when and where a unit meets.
|
||||
|
||||
Reference in New Issue
Block a user