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:
@@ -24,14 +24,21 @@ const Brief = (() => {
|
||||
const banner = document.createElement('div');
|
||||
banner.className = 'note-banner';
|
||||
|
||||
// The square mirrors my_notes.html's .note-item__image-box (dashed
|
||||
// border + "?" placeholder) when the brief carries a square_url —
|
||||
// currently note_unlock kind, which jumps direct to /billboard/my-notes/.
|
||||
const squareEl = brief.square_url
|
||||
? '<a href="' + _esc(brief.square_url) + '" class="note-banner__image"></a>'
|
||||
? '<a href="' + _esc(brief.square_url) + '" class="note-banner__image note-item__image-box">?</a>'
|
||||
: '<div class="note-banner__image"></div>';
|
||||
|
||||
// line_text is server-rendered prose from drama.Note.grant_if_new
|
||||
// (and server-side share_post) — it may carry a `<a class="note-ref">`
|
||||
// anchor wrapping the Note name. Insert as HTML, NOT escaped text.
|
||||
// Title is plain (no HTML), so it stays escaped.
|
||||
banner.innerHTML =
|
||||
'<div class="note-banner__body">' +
|
||||
'<p class="note-banner__title">' + _esc(brief.title) + '</p>' +
|
||||
'<p class="note-banner__description">' + _esc(brief.line_text) + '</p>' +
|
||||
'<p class="note-banner__description">' + (brief.line_text || '') + '</p>' +
|
||||
'<time class="note-banner__timestamp" datetime="' + _esc(brief.created_at) + '">' +
|
||||
dateStr +
|
||||
'</time>' +
|
||||
|
||||
@@ -7,19 +7,26 @@ from apps.billboard.forms import (
|
||||
LineForm,
|
||||
)
|
||||
from apps.billboard.models import Line, Post
|
||||
from apps.lyric.models import User
|
||||
|
||||
|
||||
class LineFormTest(TestCase):
|
||||
def setUp(self):
|
||||
self.author = User.objects.create(email="author@test.io")
|
||||
|
||||
def test_form_save_handles_saving_to_a_post(self):
|
||||
mypost = Post.objects.create()
|
||||
form = LineForm(data={"text": "do re mi"})
|
||||
self.assertTrue(form.is_valid())
|
||||
new_line = form.save(for_post=mypost)
|
||||
new_line = form.save(for_post=mypost, author=self.author)
|
||||
self.assertEqual(new_line, Line.objects.get())
|
||||
self.assertEqual(new_line.text, "do re mi")
|
||||
self.assertEqual(new_line.post, mypost)
|
||||
|
||||
class ExistingPostLineFormTest(TestCase):
|
||||
def setUp(self):
|
||||
self.author = User.objects.create(email="author@test.io")
|
||||
|
||||
def test_form_validation_for_blank_lines(self):
|
||||
post = Post.objects.create()
|
||||
form = ExistingPostLineForm(for_post=post, data={"text": ""})
|
||||
@@ -28,7 +35,7 @@ class ExistingPostLineFormTest(TestCase):
|
||||
|
||||
def test_form_validation_for_duplicate_lines(self):
|
||||
post = Post.objects.create()
|
||||
Line.objects.create(post=post, text="twins, basil")
|
||||
Line.objects.create(post=post, text="twins, basil", author=self.author)
|
||||
form = ExistingPostLineForm(for_post=post, data={"text": "twins, basil"})
|
||||
self.assertFalse(form.is_valid())
|
||||
self.assertEqual(form.errors["text"], [DUPLICATE_LINE_ERROR])
|
||||
@@ -37,5 +44,5 @@ class ExistingPostLineFormTest(TestCase):
|
||||
mypost = Post.objects.create()
|
||||
form = ExistingPostLineForm(for_post=mypost, data={"text": "howdy"})
|
||||
self.assertTrue(form.is_valid())
|
||||
new_line = form.save()
|
||||
new_line = form.save(author=self.author)
|
||||
self.assertEqual(new_line, Line.objects.get())
|
||||
|
||||
@@ -7,64 +7,66 @@ from apps.lyric.models import User
|
||||
|
||||
|
||||
class LineModelTest(TestCase):
|
||||
def setUp(self):
|
||||
self.user = User.objects.create(email="a@b.cde")
|
||||
|
||||
def test_line_is_related_to_post(self):
|
||||
mypost = Post.objects.create()
|
||||
line = Line()
|
||||
line.post = mypost
|
||||
line = Line(post=mypost, author=self.user, text="x")
|
||||
line.save()
|
||||
self.assertIn(line, mypost.lines.all())
|
||||
|
||||
def test_cannot_save_null_post_lines(self):
|
||||
mypost = Post.objects.create()
|
||||
line = Line(post=mypost, text=None)
|
||||
line = Line(post=mypost, author=self.user, text=None)
|
||||
with self.assertRaises(IntegrityError):
|
||||
line.save()
|
||||
|
||||
def test_cannot_save_empty_post_lines(self):
|
||||
mypost = Post.objects.create()
|
||||
line = Line(post=mypost, text="")
|
||||
line = Line(post=mypost, author=self.user, text="")
|
||||
with self.assertRaises(ValidationError):
|
||||
line.full_clean()
|
||||
|
||||
def test_duplicate_lines_are_invalid(self):
|
||||
mypost = Post.objects.create()
|
||||
Line.objects.create(post=mypost, text="jklol")
|
||||
Line.objects.create(post=mypost, author=self.user, text="jklol")
|
||||
with self.assertRaises(ValidationError):
|
||||
line = Line(post=mypost, text="jklol")
|
||||
line = Line(post=mypost, author=self.user, text="jklol")
|
||||
line.full_clean()
|
||||
|
||||
def test_still_can_save_same_line_to_different_posts(self):
|
||||
post1 = Post.objects.create()
|
||||
post2 = Post.objects.create()
|
||||
Line.objects.create(post=post1, text="nojk")
|
||||
line = Line(post=post2, text="nojk")
|
||||
Line.objects.create(post=post1, author=self.user, text="nojk")
|
||||
line = Line(post=post2, author=self.user, text="nojk")
|
||||
line.full_clean() # should not raise
|
||||
|
||||
class PostModelTest(TestCase):
|
||||
def setUp(self):
|
||||
self.user = User.objects.create(email="a@b.cde")
|
||||
|
||||
def test_get_absolute_url(self):
|
||||
mypost = Post.objects.create()
|
||||
self.assertEqual(mypost.get_absolute_url(), f"/billboard/post/{mypost.id}/")
|
||||
|
||||
def test_post_lines_order(self):
|
||||
post1 = Post.objects.create()
|
||||
line1 = Line.objects.create(post=post1, text="i1")
|
||||
line2 = Line.objects.create(post=post1, text="line 2")
|
||||
line3 = Line.objects.create(post=post1, text="3")
|
||||
line1 = Line.objects.create(post=post1, author=self.user, text="i1")
|
||||
line2 = Line.objects.create(post=post1, author=self.user, text="line 2")
|
||||
line3 = Line.objects.create(post=post1, author=self.user, text="3")
|
||||
self.assertEqual(
|
||||
list(post1.lines.all()),
|
||||
[line1, line2, line3],
|
||||
)
|
||||
|
||||
def test_posts_can_have_owners(self):
|
||||
user = User.objects.create(email="a@b.cde")
|
||||
mypost = Post.objects.create(owner=user)
|
||||
self.assertIn(mypost, user.posts.all())
|
||||
mypost = Post.objects.create(owner=self.user)
|
||||
self.assertIn(mypost, self.user.posts.all())
|
||||
|
||||
def test_post_owner_is_optional(self):
|
||||
Post.objects.create()
|
||||
|
||||
def test_post_name_is_first_line_text(self):
|
||||
post = Post.objects.create()
|
||||
Line.objects.create(post=post, text="first line")
|
||||
Line.objects.create(post=post, text="second line")
|
||||
self.assertEqual(post.name, "first line")
|
||||
def test_post_title_is_explicit_field(self):
|
||||
post = Post.objects.create(title="first line")
|
||||
self.assertEqual(post.title, "first line")
|
||||
|
||||
@@ -66,6 +66,13 @@ class NewPostTest(TestCase):
|
||||
|
||||
@override_settings(COMPRESS_ENABLED=False)
|
||||
class PostViewTest(TestCase):
|
||||
def setUp(self):
|
||||
self.author = User.objects.create(email="author@test.io")
|
||||
# POST flows append a Line with author=request.user — non-null FK
|
||||
# since Line.author is required. force_login so the view's view_post
|
||||
# path saves cleanly; anonymous compose is no longer supported.
|
||||
self.client.force_login(self.author)
|
||||
|
||||
def test_uses_post_template(self):
|
||||
mypost = Post.objects.create()
|
||||
response = self.client.get(f"/billboard/post/{mypost.id}/")
|
||||
@@ -85,10 +92,10 @@ class PostViewTest(TestCase):
|
||||
def test_displays_only_lines_for_that_post(self):
|
||||
# Given/Arrange
|
||||
correct_post = Post.objects.create()
|
||||
Line.objects.create(text="itemey 1", post=correct_post)
|
||||
Line.objects.create(text="itemey 2", post=correct_post)
|
||||
Line.objects.create(text="itemey 1", post=correct_post, author=self.author)
|
||||
Line.objects.create(text="itemey 2", post=correct_post, author=self.author)
|
||||
other_post = Post.objects.create()
|
||||
Line.objects.create(text="other post line", post=other_post)
|
||||
Line.objects.create(text="other post line", post=other_post, author=self.author)
|
||||
# When/Act
|
||||
response = self.client.get(f"/billboard/post/{correct_post.id}/")
|
||||
# Then/Assert
|
||||
@@ -147,7 +154,7 @@ class PostViewTest(TestCase):
|
||||
|
||||
def test_duplicate_line_validation_errors_end_up_on_post_page(self):
|
||||
post1 = Post.objects.create()
|
||||
Line.objects.create(post=post1, text="lorem ipsum")
|
||||
Line.objects.create(post=post1, text="lorem ipsum", author=self.author)
|
||||
|
||||
response = self.client.post(
|
||||
f"/billboard/post/{post1.id}/",
|
||||
|
||||
@@ -18,7 +18,7 @@ from django.views.decorators.csrf import ensure_csrf_cookie
|
||||
from apps.applets.utils import applet_context, apply_applet_toggle
|
||||
from apps.drama.models import Note
|
||||
from apps.epic.utils import _compute_distinctions
|
||||
from apps.lyric.models import PaymentMethod, Token, User, Wallet
|
||||
from apps.lyric.models import PaymentMethod, Token, User, Wallet, is_reserved_username
|
||||
|
||||
|
||||
APPLET_ORDER = ["wallet", "username", "palette"]
|
||||
@@ -112,6 +112,9 @@ def set_palette(request):
|
||||
def set_profile(request):
|
||||
if request.method == "POST":
|
||||
username = request.POST.get("username", "")
|
||||
if is_reserved_username(username, current_user=request.user):
|
||||
messages.error(request, "That handle is reserved.")
|
||||
return redirect("/")
|
||||
request.user.username = username
|
||||
request.user.save(update_fields=["username"])
|
||||
return redirect("/")
|
||||
|
||||
Reference in New Issue
Block a user