post aperture refactor (May-8b): Post.title field; Line.author PROTECT FK + created_at; Note.grant_if_new admin-vs-Look! format dispatch w. note-ref anchor; bottom-anchored aperture w. shared-between header + per-Line user/timestamp; dotted-? Brief square; reserved adman seed — TDD

- schema: billboard/0004 adds Post.title (CharField 35) + Line.author (PROTECT FK, related_name=authored_lines) + Line.created_at (auto_now_add); RunPython backfill stamps existing rows (note_unlock → "Notes & recognitions" + author=adman; user_post → first-line glean + author=Post.owner).
  - lyric/0003 seeds adman User (system author for note unlock + share invite Lines); apps.lyric.models gains RESERVED_USERNAMES = {"adman"}, is_reserved_username() guard in dashboard.set_profile, get_or_create_adman() lazy fetch (TransactionTestCase flushes the seed).
  - drama: Note.grant_if_new dispatches via _ADMIN_NOTE_SLUGS = {"super-schizo","super-nomad"} — admin slugs use "The administration recognizes…" prose; everyone else uses "Look!—new Note unlocked." Both wrap Note name in `<a class="note-ref">`. Header Line dropped (test_two_different_grants_share_one_post asserts 2 lines, not 3). Note.display_name property added (slug.title() default — "super-schizo" → "Super-Schizo"). User.active_title_display returns donned recognition title or "Earthman" default.
  - billboard models: Post.name property removed → my_posts.html, _applet-my-posts.html, PostSerializer switched to Post.title. LineForm.save(for_post, author) + ExistingPostLineForm.save(author) signature + all callers (api.views, billboard.views.new_post + view_post + share_post). billboard.views.share_post authors via get_or_create_adman; new_post truncates first line for Post.title via _truncate_post_title.
  - post.html: <h3> post title heading; .post-shared-recipients (commas only) + .post-shared-self lines ("just me, X the Earthman" / "& me, X the Y" 0/≥1 split); #id_post_table is now a <ul> w. justify-content: flex-end + per-Line 3-col grid (author/text/time); adman Lines render |safe + .post-line--system italic; #id_text → #id_post_line_text rename (post.html only — /billboard/ new-post applet keeps #id_text); page_class page-billpost (joins billboard+billscroll body-class trio).
  - SCSS _billboard.scss: .post-page extends %billboard-page-base, adds bottom-anchored flex-column scroll + 3-col .post-line grid + .post-line-form pinned at bottom. _note.scss: a.note-banner__image picks up .note-item__image-box dashed-? styling for the Brief square.
  - _buddy_panel.html JS rewired for new layout: _appendLine builds <li class="post-line post-line--system"> w. adman+timestamp; _appendRecipientChip handles 0→1+ transition (rewrites "just me," → "& me,", inserts .post-shared-recipients line above self).
  - FT post_page.py: get_table_rows queries .post-line; wait_for_row_in_post_table matches by text containment (line_number arg ignored — kept for backwards compat); get_line_input_box probes #id_post_line_text first, falls back to #id_text; get_post_owner reads textContent (hidden span). test_applet_new_post_line_validation switched to input[name="text"]:invalid/:valid for cross-page selectors.
  - rootvars.scss: minor plutonium + fuschia tweaks (pre-existing).
  - 818 ITs + 35 FTs (buddy/new-post/sharing/validation/layout/jasmine/my-notes/my-posts) green.

Code architected by Disco DeDisco <discodedisco@outlook.com>
Git commit message Co-Authored-By:
Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Disco DeDisco
2026-05-08 21:29:21 -04:00
parent ba5f6556c0
commit 6f76f6c176
28 changed files with 619 additions and 138 deletions

View File

@@ -210,6 +210,15 @@ _NOTE_DISPLAY = {
"super-nomad": {"greeting": "Howdy,", "title": "Stranger"},
}
# Note slugs whose grant prose uses the long admin format ("The administration
# recognizes…") rather than the standard "Look!—new Note unlocked…" format.
# Any slug not in this set gets the standard format.
_ADMIN_NOTE_SLUGS = frozenset({"super-schizo", "super-nomad"})
# Hardcoded title for the per-user "Note unlocks" Post — supplants any
# first-line-glean for posts of kind=NOTE_UNLOCK.
NOTE_UNLOCK_POST_TITLE = "Notes & recognitions"
class Note(models.Model):
user = models.ForeignKey(
@@ -235,17 +244,37 @@ class Note(models.Model):
def display_greeting(self):
return _NOTE_DISPLAY.get(self.slug, {}).get("greeting", "Welcome,")
@property
def display_name(self):
"""The Note's *name* (e.g., "Stargazer", "Super-Schizo") — the heading
rendered on the my-notes card. Distinct from `display_title` which is
the *recognition title* the user dons (e.g., "Schizoid Man" for
super-schizo). For all current slugs `slug.title()` recovers the right
casing (.title() capitalizes after non-letter chars, so "super-schizo"
"Super-Schizo"); special-case in `_NOTE_DISPLAY[slug]["name"]` if a
future slug needs a different rendering."""
return _NOTE_DISPLAY.get(self.slug, {}).get("name", self.slug.title())
@classmethod
def grant_if_new(cls, user, slug):
"""Grants the Note if it doesn't already exist on the user; on a fresh
grant ALSO appends a Line to the user's per-category "Note Unlocks"
Post (creating the Post on first-ever unlock) and spawns a Brief that
FKs the appended Line. Returns ``(note, created, brief)`` — brief is
None on idempotent re-grants. Banner-side affordances (FYI navigation,
my-notes square) ride on the Brief.kind=NOTE_UNLOCK discriminator."""
grant ALSO appends a Line to the user's per-category "Notes &
recognitions" Post (creating the Post on first-ever unlock) and spawns
a Brief that FKs the appended Line. Returns ``(note, created, brief)``
— brief is None on idempotent re-grants. Banner-side affordances (FYI
navigation, my-notes square) ride on Brief.kind=NOTE_UNLOCK.
Line text dispatches by slug: admin-grant slugs (super-schizo,
super-nomad) use the long "The administration recognizes…" format;
every other slug uses the standard "Look!—new Note unlocked. {Note
name} recognizes {username} the {title}." format. Both wrap the Note
name in a `note-ref` anchor pointing at /billboard/my-notes/.
Author is hardcoded to the seeded `adman` User; the per-line username
column then attributes the Line correctly."""
from django.utils import timezone
from apps.billboard.models import Brief, Line, Post
from apps.lyric.models import get_or_create_adman
note, created = cls.objects.get_or_create(
user=user, slug=slug,
@@ -256,17 +285,37 @@ class Note(models.Model):
post, _ = Post.objects.get_or_create(
owner=user, kind=Post.KIND_NOTE_UNLOCK,
defaults={"title": NOTE_UNLOCK_POST_TITLE},
)
# Per-category header Line (becomes Post.name) — only added once on
# first-ever unlock for this user.
Line.objects.get_or_create(post=post, text="Look! — new Note unlocked")
# Per-event Line — text dedupe is enforced by the unique_together on
# (post, text), so two unlocks of the same slug at the same minute
# would clash; the timestamp suffix carries the second of resolution.
# %-I (lstrip-zero hour) is POSIX-only; %I gives "05:21:00 PM" — fine
# on Windows + Linux, and the leading zero is acceptable in a Line.
line_text = f"{note.display_title}, {note.earned_at:%I:%M:%S %p}"
line = Line.objects.create(post=post, text=line_text)
# Existing Note-unlock Posts (pre-0004 migration) might lack a title
# if they predate this code path's get_or_create defaults. Heal once.
if post.title != NOTE_UNLOCK_POST_TITLE:
post.title = NOTE_UNLOCK_POST_TITLE
post.save(update_fields=["title"])
username = user.username or user.email
note_anchor = (
f'<a class="note-ref" href="/billboard/my-notes/">'
f'{note.display_name}</a>'
)
if slug in _ADMIN_NOTE_SLUGS:
line_text = (
f"The administration recognizes {username} for {note_anchor}, "
f"which comes with the customary title of {note.display_title}. "
"This does not entail any additional benefits."
)
else:
line_text = (
f"Look!—new Note unlocked. {note_anchor} "
f"recognizes {username} the {note.display_title}."
)
# Lazy get-or-create: TransactionTestCase flushes the migration-seeded
# adman row, so tests that create superusers (which auto-grants
# super-schizo + super-nomad via the User post_save signal) need a
# safety net. Production migrations seed it once.
adman = get_or_create_adman()
line = Line.objects.create(post=post, text=line_text, author=adman)
brief = Brief.objects.create(
owner=user,
post=post,

View File

@@ -45,7 +45,7 @@ class GrantIfNewSpawnsBriefTest(TestCase):
def test_two_different_grants_share_one_post(self):
"""Per-category Post: stargazer + schizo unlocks both append Lines to
the same Note Unlocks Post (one growing thread)."""
the same "Notes & recognitions" Post (one growing thread)."""
Note.grant_if_new(self.user, "stargazer")
Note.grant_if_new(self.user, "schizo")
posts = Post.objects.filter(owner=self.user, kind=Post.KIND_NOTE_UNLOCK)
@@ -53,10 +53,11 @@ class GrantIfNewSpawnsBriefTest(TestCase):
post = posts.first()
# 2 Briefs, one per unlock
self.assertEqual(Brief.objects.filter(post=post).count(), 2)
# 3 distinct Lines on the Post: 1 header ("Look! — new Note unlocked")
# + 2 per-event Lines (one per unlock)
# 2 distinct Lines on the Post — one per grant. The standalone
# "Look! — new Note unlocked" header Line was dropped in the May-8b
# refactor; the standard format now embeds that text inline per Line.
line_texts = list(post.lines.values_list("text", flat=True))
self.assertEqual(len(set(line_texts)), 3)
self.assertEqual(len(set(line_texts)), 2)
def test_brief_line_text_includes_note_title(self):
_, _, brief = Note.grant_if_new(self.user, "stargazer")