Files
python-tdd/src/apps/dashboard/forms.py
Disco DeDisco 473e6bc45a 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

33 lines
963 B
Python

from django import forms
from django.core.exceptions import ValidationError
from .models import Line
DUPLICATE_LINE_ERROR = "You've already logged this to your post"
EMPTY_LINE_ERROR = "You can't have an empty post line"
class LineForm(forms.Form):
text = forms.CharField(
error_messages = {"required": EMPTY_LINE_ERROR},
required=True,
)
def save(self, for_post):
return Line.objects.create(
post=for_post,
text=self.cleaned_data["text"],
)
class ExistingPostLineForm(LineForm):
def __init__(self, for_post, *args, **kwargs):
super().__init__(*args, **kwargs)
self._for_post = for_post
def clean_text(self):
text = self.cleaned_data["text"]
if self._for_post.lines.filter(text=text).exists():
raise forms.ValidationError(DUPLICATE_LINE_ERROR)
return text
def save(self):
return super().save(for_post=self._for_post)