journal: multi-select emotions and per-category writing templates
- Mood switches from a single enum column to a many-to-many JournalEntryMood table so an entry can carry several feelings at once; the vocabulary is trimmed to 9 named emotions (dropped the overlapping satisfaction scale) with unified noun-style labels. - Categories can define a content_template that pre-fills the "new entry" textarea when selected (only if the user hasn't started typing), seeded with a Story/Feelings/Decisions/Insights/Actions reflection template on the default "일상" category. - Fixes a real attribute-injection bug found while building the template feature: Jinja's built-in |tojson filter doesn't escape double quotes, which breaks a double-quoted x-data="..." attribute when the JSON payload contains one; added |forceescape and a regression test. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -34,6 +34,27 @@ ALLOWED_IMAGE_TYPES = {"image/jpeg", "image/png", "image/webp", "image/gif"}
|
||||
ALLOWED_VIDEO_TYPES = {"video/mp4", "video/quicktime"}
|
||||
THUMBNAIL_WIDTH = 400
|
||||
DEFAULT_CATEGORY_NAME = "일상"
|
||||
DEFAULT_CATEGORY_TEMPLATE = """**1. Story : 오늘 무슨 일이 있었나요?**
|
||||
|
||||
-
|
||||
|
||||
**2. Feelings : 오늘 들었던 생각과 나의 감정은?**
|
||||
|
||||
-
|
||||
|
||||
**3. Decisions : 오늘 내가 내린 결정이 있나요?**
|
||||
|
||||
-
|
||||
|
||||
**4. Insights : 나에 대해 새롭게 알게된 사실이 있나요?**
|
||||
|
||||
-
|
||||
|
||||
→ 나에 대한 인사이트는 메타인지를 키워주는 **소중한 기록**입니다. 꼭 보관하세요.
|
||||
|
||||
**5. Actions : 내가 다음에 할 행동은 무엇인가요?**
|
||||
|
||||
- """
|
||||
|
||||
|
||||
# ---- 카테고리 ----
|
||||
@@ -54,7 +75,9 @@ def get_category(db: Session, category_id: int, user_id: int) -> JournalCategory
|
||||
|
||||
|
||||
def create_category(db: Session, user_id: int, data: JournalCategoryCreate) -> JournalCategory:
|
||||
category = JournalCategory(user_id=user_id, name=data.name, color=data.color)
|
||||
category = JournalCategory(
|
||||
user_id=user_id, name=data.name, color=data.color, content_template=data.content_template
|
||||
)
|
||||
db.add(category)
|
||||
db.commit()
|
||||
db.refresh(category)
|
||||
@@ -64,6 +87,7 @@ def create_category(db: Session, user_id: int, data: JournalCategoryCreate) -> J
|
||||
def update_category(db: Session, category: JournalCategory, data: JournalCategoryCreate) -> JournalCategory:
|
||||
category.name = data.name
|
||||
category.color = data.color
|
||||
category.content_template = data.content_template
|
||||
db.commit()
|
||||
db.refresh(category)
|
||||
return category
|
||||
@@ -79,7 +103,9 @@ def ensure_default_category(db: Session, user_id: int) -> JournalCategory:
|
||||
)
|
||||
if existing is not None:
|
||||
return existing
|
||||
return create_category(db, user_id, JournalCategoryCreate(name=DEFAULT_CATEGORY_NAME))
|
||||
return create_category(
|
||||
db, user_id, JournalCategoryCreate(name=DEFAULT_CATEGORY_NAME, content_template=DEFAULT_CATEGORY_TEMPLATE)
|
||||
)
|
||||
|
||||
|
||||
def reorder_categories(db: Session, user_id: int, ordered_ids: list[int]) -> None:
|
||||
|
||||
Reference in New Issue
Block a user