2026-04-22 04:02:14 -04:00
|
|
|
import json
|
|
|
|
|
|
2026-03-19 15:48:59 -04:00
|
|
|
from django.contrib.auth.decorators import login_required
|
2026-03-24 16:46:46 -04:00
|
|
|
from django.db.models import Max, Q
|
2026-04-22 04:02:14 -04:00
|
|
|
from django.http import JsonResponse
|
2026-03-24 16:46:46 -04:00
|
|
|
from django.shortcuts import redirect, render
|
2026-03-19 15:48:59 -04:00
|
|
|
|
2026-04-21 15:46:30 -04:00
|
|
|
from apps.applets.utils import applet_context, apply_applet_toggle
|
rename: Note→Post/Line (dashboard); Recognition→Note (drama); new-post/my-posts to billboard
- dashboard: Note→Post, Item→Line across models, forms, views, API, urls & tests
- new-post (9×3) & my-posts (3×3) applets migrate from dashboard→billboard context; billboard view passes form & recent_posts
- drama: Recognition→Note, related_name notes; billboard URL /recognition/→/my-notes/, set-palette at /note/<slug>/set-palette
- recognition.js→note.js (module Note, data.note key); recognition-page.js→note-page.js; .recog-*→.note-*
- _recognition.scss→_note.scss; BillNotes page header; applet slug billboard-recognition→billboard-notes (My Notes)
- NoteSpec.js replaces RecognitionSpec.js; test_recognition.py→test_applet_my_notes.py
- 4 migrations applied: dashboard 0004, applets 0011+0012, drama 0005; 683 ITs green
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-22 22:32:34 -04:00
|
|
|
from apps.dashboard.forms import LineForm
|
|
|
|
|
from apps.dashboard.models import Post
|
|
|
|
|
from apps.drama.models import GameEvent, Note, ScrollPosition
|
2026-04-21 15:46:30 -04:00
|
|
|
from apps.epic.models import Room
|
|
|
|
|
from apps.epic.utils import rooms_for_user
|
2026-03-19 15:48:59 -04:00
|
|
|
|
|
|
|
|
|
rename: Note→Post/Line (dashboard); Recognition→Note (drama); new-post/my-posts to billboard
- dashboard: Note→Post, Item→Line across models, forms, views, API, urls & tests
- new-post (9×3) & my-posts (3×3) applets migrate from dashboard→billboard context; billboard view passes form & recent_posts
- drama: Recognition→Note, related_name notes; billboard URL /recognition/→/my-notes/, set-palette at /note/<slug>/set-palette
- recognition.js→note.js (module Note, data.note key); recognition-page.js→note-page.js; .recog-*→.note-*
- _recognition.scss→_note.scss; BillNotes page header; applet slug billboard-recognition→billboard-notes (My Notes)
- NoteSpec.js replaces RecognitionSpec.js; test_recognition.py→test_applet_my_notes.py
- 4 migrations applied: dashboard 0004, applets 0011+0012, drama 0005; 683 ITs green
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-22 22:32:34 -04:00
|
|
|
def _recent_posts(user, limit=3):
|
|
|
|
|
return (
|
|
|
|
|
Post
|
|
|
|
|
.objects
|
|
|
|
|
.filter(Q(owner=user) | Q(shared_with=user))
|
|
|
|
|
.annotate(last_line=Max('lines__id'))
|
|
|
|
|
.order_by('-last_line')
|
|
|
|
|
.distinct()[:limit]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2026-03-19 15:48:59 -04:00
|
|
|
@login_required(login_url="/")
|
|
|
|
|
def billboard(request):
|
2026-04-21 15:46:30 -04:00
|
|
|
my_rooms = rooms_for_user(request.user).order_by("-created_at")
|
2026-03-24 16:46:46 -04:00
|
|
|
|
|
|
|
|
recent_room = (
|
|
|
|
|
Room.objects.filter(
|
|
|
|
|
Q(owner=request.user) | Q(gate_slots__gamer=request.user)
|
|
|
|
|
)
|
|
|
|
|
.annotate(last_event=Max("events__timestamp"))
|
|
|
|
|
.filter(last_event__isnull=False)
|
|
|
|
|
.order_by("-last_event")
|
|
|
|
|
.distinct()
|
|
|
|
|
.first()
|
|
|
|
|
)
|
|
|
|
|
recent_events = (
|
2026-04-13 00:34:05 -04:00
|
|
|
list(
|
|
|
|
|
recent_room.events
|
|
|
|
|
.select_related("actor")
|
|
|
|
|
.exclude(verb=GameEvent.SIG_UNREADY)
|
|
|
|
|
.exclude(verb=GameEvent.SIG_READY, data__retracted=True)
|
|
|
|
|
.order_by("-timestamp")[:36]
|
|
|
|
|
)[::-1]
|
2026-03-24 16:46:46 -04:00
|
|
|
if recent_room else []
|
|
|
|
|
)
|
|
|
|
|
|
2026-03-19 15:48:59 -04:00
|
|
|
return render(request, "apps/billboard/billboard.html", {
|
|
|
|
|
"my_rooms": my_rooms,
|
2026-03-24 16:46:46 -04:00
|
|
|
"recent_room": recent_room,
|
|
|
|
|
"recent_events": recent_events,
|
|
|
|
|
"viewer": request.user,
|
|
|
|
|
"applets": applet_context(request.user, "billboard"),
|
rename: Note→Post/Line (dashboard); Recognition→Note (drama); new-post/my-posts to billboard
- dashboard: Note→Post, Item→Line across models, forms, views, API, urls & tests
- new-post (9×3) & my-posts (3×3) applets migrate from dashboard→billboard context; billboard view passes form & recent_posts
- drama: Recognition→Note, related_name notes; billboard URL /recognition/→/my-notes/, set-palette at /note/<slug>/set-palette
- recognition.js→note.js (module Note, data.note key); recognition-page.js→note-page.js; .recog-*→.note-*
- _recognition.scss→_note.scss; BillNotes page header; applet slug billboard-recognition→billboard-notes (My Notes)
- NoteSpec.js replaces RecognitionSpec.js; test_recognition.py→test_applet_my_notes.py
- 4 migrations applied: dashboard 0004, applets 0011+0012, drama 0005; 683 ITs green
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-22 22:32:34 -04:00
|
|
|
"form": LineForm(),
|
|
|
|
|
"recent_posts": _recent_posts(request.user),
|
2026-03-19 15:48:59 -04:00
|
|
|
"page_class": "page-billboard",
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
2026-03-24 16:46:46 -04:00
|
|
|
@login_required(login_url="/")
|
|
|
|
|
def toggle_billboard_applets(request):
|
|
|
|
|
checked = request.POST.getlist("applets")
|
2026-04-21 15:46:30 -04:00
|
|
|
apply_applet_toggle(request.user, "billboard", checked)
|
2026-03-24 16:46:46 -04:00
|
|
|
if request.headers.get("HX-Request"):
|
|
|
|
|
return render(request, "apps/billboard/_partials/_applets.html", {
|
|
|
|
|
"applets": applet_context(request.user, "billboard"),
|
rename: Note→Post/Line (dashboard); Recognition→Note (drama); new-post/my-posts to billboard
- dashboard: Note→Post, Item→Line across models, forms, views, API, urls & tests
- new-post (9×3) & my-posts (3×3) applets migrate from dashboard→billboard context; billboard view passes form & recent_posts
- drama: Recognition→Note, related_name notes; billboard URL /recognition/→/my-notes/, set-palette at /note/<slug>/set-palette
- recognition.js→note.js (module Note, data.note key); recognition-page.js→note-page.js; .recog-*→.note-*
- _recognition.scss→_note.scss; BillNotes page header; applet slug billboard-recognition→billboard-notes (My Notes)
- NoteSpec.js replaces RecognitionSpec.js; test_recognition.py→test_applet_my_notes.py
- 4 migrations applied: dashboard 0004, applets 0011+0012, drama 0005; 683 ITs green
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-22 22:32:34 -04:00
|
|
|
"form": LineForm(),
|
|
|
|
|
"recent_posts": _recent_posts(request.user),
|
2026-03-24 16:46:46 -04:00
|
|
|
})
|
|
|
|
|
return redirect("billboard:billboard")
|
|
|
|
|
|
|
|
|
|
|
2026-03-19 15:48:59 -04:00
|
|
|
@login_required(login_url="/")
|
|
|
|
|
def room_scroll(request, room_id):
|
|
|
|
|
room = Room.objects.get(id=room_id)
|
|
|
|
|
events = room.events.select_related("actor").all()
|
2026-03-24 17:44:34 -04:00
|
|
|
sp = ScrollPosition.objects.filter(user=request.user, room=room).first()
|
2026-03-19 15:48:59 -04:00
|
|
|
return render(request, "apps/billboard/room_scroll.html", {
|
|
|
|
|
"room": room,
|
|
|
|
|
"events": events,
|
|
|
|
|
"viewer": request.user,
|
2026-03-24 17:44:34 -04:00
|
|
|
"scroll_position": sp.position if sp else 0,
|
2026-03-24 16:46:46 -04:00
|
|
|
"page_class": "page-billscroll",
|
2026-03-19 15:48:59 -04:00
|
|
|
})
|
2026-03-24 17:44:34 -04:00
|
|
|
|
|
|
|
|
|
rename: Note→Post/Line (dashboard); Recognition→Note (drama); new-post/my-posts to billboard
- dashboard: Note→Post, Item→Line across models, forms, views, API, urls & tests
- new-post (9×3) & my-posts (3×3) applets migrate from dashboard→billboard context; billboard view passes form & recent_posts
- drama: Recognition→Note, related_name notes; billboard URL /recognition/→/my-notes/, set-palette at /note/<slug>/set-palette
- recognition.js→note.js (module Note, data.note key); recognition-page.js→note-page.js; .recog-*→.note-*
- _recognition.scss→_note.scss; BillNotes page header; applet slug billboard-recognition→billboard-notes (My Notes)
- NoteSpec.js replaces RecognitionSpec.js; test_recognition.py→test_applet_my_notes.py
- 4 migrations applied: dashboard 0004, applets 0011+0012, drama 0005; 683 ITs green
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-22 22:32:34 -04:00
|
|
|
_NOTE_META = {
|
2026-04-22 04:02:14 -04:00
|
|
|
"stargazer": {
|
|
|
|
|
"title": "Stargazer",
|
|
|
|
|
"description": "You saved your first personal sky chart.",
|
|
|
|
|
"palette_options": ["palette-bardo", "palette-sheol"],
|
|
|
|
|
},
|
|
|
|
|
"schizo": {
|
|
|
|
|
"title": "Schizo",
|
|
|
|
|
"description": "The socius recognizes the line of flight.",
|
|
|
|
|
"palette_options": [],
|
|
|
|
|
},
|
|
|
|
|
"nomad": {
|
|
|
|
|
"title": "Nomad",
|
|
|
|
|
"description": "The socius recognizes the smooth space.",
|
|
|
|
|
"palette_options": [],
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_required(login_url="/")
|
rename: Note→Post/Line (dashboard); Recognition→Note (drama); new-post/my-posts to billboard
- dashboard: Note→Post, Item→Line across models, forms, views, API, urls & tests
- new-post (9×3) & my-posts (3×3) applets migrate from dashboard→billboard context; billboard view passes form & recent_posts
- drama: Recognition→Note, related_name notes; billboard URL /recognition/→/my-notes/, set-palette at /note/<slug>/set-palette
- recognition.js→note.js (module Note, data.note key); recognition-page.js→note-page.js; .recog-*→.note-*
- _recognition.scss→_note.scss; BillNotes page header; applet slug billboard-recognition→billboard-notes (My Notes)
- NoteSpec.js replaces RecognitionSpec.js; test_recognition.py→test_applet_my_notes.py
- 4 migrations applied: dashboard 0004, applets 0011+0012, drama 0005; 683 ITs green
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-22 22:32:34 -04:00
|
|
|
def note_set_palette(request, slug):
|
2026-04-22 04:02:14 -04:00
|
|
|
from django.http import Http404
|
2026-04-22 23:54:05 -04:00
|
|
|
from apps.dashboard.views import _unlocked_palettes_for_user
|
2026-04-22 04:02:14 -04:00
|
|
|
try:
|
rename: Note→Post/Line (dashboard); Recognition→Note (drama); new-post/my-posts to billboard
- dashboard: Note→Post, Item→Line across models, forms, views, API, urls & tests
- new-post (9×3) & my-posts (3×3) applets migrate from dashboard→billboard context; billboard view passes form & recent_posts
- drama: Recognition→Note, related_name notes; billboard URL /recognition/→/my-notes/, set-palette at /note/<slug>/set-palette
- recognition.js→note.js (module Note, data.note key); recognition-page.js→note-page.js; .recog-*→.note-*
- _recognition.scss→_note.scss; BillNotes page header; applet slug billboard-recognition→billboard-notes (My Notes)
- NoteSpec.js replaces RecognitionSpec.js; test_recognition.py→test_applet_my_notes.py
- 4 migrations applied: dashboard 0004, applets 0011+0012, drama 0005; 683 ITs green
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-22 22:32:34 -04:00
|
|
|
note = Note.objects.get(user=request.user, slug=slug)
|
|
|
|
|
except Note.DoesNotExist:
|
2026-04-22 04:02:14 -04:00
|
|
|
raise Http404
|
|
|
|
|
if request.method == "POST":
|
|
|
|
|
body = json.loads(request.body)
|
2026-04-22 23:54:05 -04:00
|
|
|
palette = body.get("palette", "")
|
|
|
|
|
note.palette = palette
|
rename: Note→Post/Line (dashboard); Recognition→Note (drama); new-post/my-posts to billboard
- dashboard: Note→Post, Item→Line across models, forms, views, API, urls & tests
- new-post (9×3) & my-posts (3×3) applets migrate from dashboard→billboard context; billboard view passes form & recent_posts
- drama: Recognition→Note, related_name notes; billboard URL /recognition/→/my-notes/, set-palette at /note/<slug>/set-palette
- recognition.js→note.js (module Note, data.note key); recognition-page.js→note-page.js; .recog-*→.note-*
- _recognition.scss→_note.scss; BillNotes page header; applet slug billboard-recognition→billboard-notes (My Notes)
- NoteSpec.js replaces RecognitionSpec.js; test_recognition.py→test_applet_my_notes.py
- 4 migrations applied: dashboard 0004, applets 0011+0012, drama 0005; 683 ITs green
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-22 22:32:34 -04:00
|
|
|
note.save(update_fields=["palette"])
|
2026-04-22 23:54:05 -04:00
|
|
|
# Commit as the user's active sitewide palette now that the Note unlocks it.
|
|
|
|
|
if palette in _unlocked_palettes_for_user(request.user):
|
|
|
|
|
request.user.palette = palette
|
|
|
|
|
request.user.save(update_fields=["palette"])
|
2026-04-22 04:02:14 -04:00
|
|
|
return JsonResponse({"ok": True})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_required(login_url="/")
|
rename: Note→Post/Line (dashboard); Recognition→Note (drama); new-post/my-posts to billboard
- dashboard: Note→Post, Item→Line across models, forms, views, API, urls & tests
- new-post (9×3) & my-posts (3×3) applets migrate from dashboard→billboard context; billboard view passes form & recent_posts
- drama: Recognition→Note, related_name notes; billboard URL /recognition/→/my-notes/, set-palette at /note/<slug>/set-palette
- recognition.js→note.js (module Note, data.note key); recognition-page.js→note-page.js; .recog-*→.note-*
- _recognition.scss→_note.scss; BillNotes page header; applet slug billboard-recognition→billboard-notes (My Notes)
- NoteSpec.js replaces RecognitionSpec.js; test_recognition.py→test_applet_my_notes.py
- 4 migrations applied: dashboard 0004, applets 0011+0012, drama 0005; 683 ITs green
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-22 22:32:34 -04:00
|
|
|
def my_notes(request):
|
|
|
|
|
qs = Note.objects.filter(user=request.user)
|
|
|
|
|
note_items = [
|
2026-04-22 04:02:14 -04:00
|
|
|
{
|
rename: Note→Post/Line (dashboard); Recognition→Note (drama); new-post/my-posts to billboard
- dashboard: Note→Post, Item→Line across models, forms, views, API, urls & tests
- new-post (9×3) & my-posts (3×3) applets migrate from dashboard→billboard context; billboard view passes form & recent_posts
- drama: Recognition→Note, related_name notes; billboard URL /recognition/→/my-notes/, set-palette at /note/<slug>/set-palette
- recognition.js→note.js (module Note, data.note key); recognition-page.js→note-page.js; .recog-*→.note-*
- _recognition.scss→_note.scss; BillNotes page header; applet slug billboard-recognition→billboard-notes (My Notes)
- NoteSpec.js replaces RecognitionSpec.js; test_recognition.py→test_applet_my_notes.py
- 4 migrations applied: dashboard 0004, applets 0011+0012, drama 0005; 683 ITs green
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-22 22:32:34 -04:00
|
|
|
"obj": n,
|
|
|
|
|
"title": _NOTE_META.get(n.slug, {}).get("title", n.slug),
|
|
|
|
|
"description": _NOTE_META.get(n.slug, {}).get("description", ""),
|
|
|
|
|
"palette_options": _NOTE_META.get(n.slug, {}).get("palette_options", []),
|
2026-04-22 04:02:14 -04:00
|
|
|
}
|
rename: Note→Post/Line (dashboard); Recognition→Note (drama); new-post/my-posts to billboard
- dashboard: Note→Post, Item→Line across models, forms, views, API, urls & tests
- new-post (9×3) & my-posts (3×3) applets migrate from dashboard→billboard context; billboard view passes form & recent_posts
- drama: Recognition→Note, related_name notes; billboard URL /recognition/→/my-notes/, set-palette at /note/<slug>/set-palette
- recognition.js→note.js (module Note, data.note key); recognition-page.js→note-page.js; .recog-*→.note-*
- _recognition.scss→_note.scss; BillNotes page header; applet slug billboard-recognition→billboard-notes (My Notes)
- NoteSpec.js replaces RecognitionSpec.js; test_recognition.py→test_applet_my_notes.py
- 4 migrations applied: dashboard 0004, applets 0011+0012, drama 0005; 683 ITs green
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-22 22:32:34 -04:00
|
|
|
for n in qs
|
2026-04-22 04:02:14 -04:00
|
|
|
]
|
rename: Note→Post/Line (dashboard); Recognition→Note (drama); new-post/my-posts to billboard
- dashboard: Note→Post, Item→Line across models, forms, views, API, urls & tests
- new-post (9×3) & my-posts (3×3) applets migrate from dashboard→billboard context; billboard view passes form & recent_posts
- drama: Recognition→Note, related_name notes; billboard URL /recognition/→/my-notes/, set-palette at /note/<slug>/set-palette
- recognition.js→note.js (module Note, data.note key); recognition-page.js→note-page.js; .recog-*→.note-*
- _recognition.scss→_note.scss; BillNotes page header; applet slug billboard-recognition→billboard-notes (My Notes)
- NoteSpec.js replaces RecognitionSpec.js; test_recognition.py→test_applet_my_notes.py
- 4 migrations applied: dashboard 0004, applets 0011+0012, drama 0005; 683 ITs green
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-22 22:32:34 -04:00
|
|
|
return render(request, "apps/billboard/my_notes.html", {
|
|
|
|
|
"notes": qs,
|
|
|
|
|
"note_items": note_items,
|
|
|
|
|
"page_class": "page-notes",
|
2026-04-22 04:02:14 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
2026-03-24 17:44:34 -04:00
|
|
|
@login_required(login_url="/")
|
|
|
|
|
def save_scroll_position(request, room_id):
|
|
|
|
|
if request.method != "POST":
|
|
|
|
|
from django.http import HttpResponseNotAllowed
|
|
|
|
|
return HttpResponseNotAllowed(["POST"])
|
|
|
|
|
room = Room.objects.get(id=room_id)
|
|
|
|
|
position = int(request.POST.get("position", 0))
|
|
|
|
|
ScrollPosition.objects.update_or_create(
|
|
|
|
|
user=request.user, room=room,
|
|
|
|
|
defaults={"position": position},
|
|
|
|
|
)
|
|
|
|
|
from django.http import HttpResponse
|
|
|
|
|
return HttpResponse(status=204)
|