Move default templates to .jinja2 files + add live preview + update CLAUDE.md
Some checks failed
Validate / Hassfest (push) Has been cancelled

Templates:
- Default EN/RU templates moved from inline Python strings to
  14 .jinja2 files in templates/{en,ru}/ directory
- Properly formatted with readable indentation and Jinja2
  whitespace control ({%- -%})
- load_default_templates(locale) loads from files on first access
- Seed function uses file loader instead of inline dicts

Preview:
- New POST /api/template-configs/preview-raw endpoint: renders
  arbitrary Jinja2 text with sample data (for live editing preview)
- Route ordering fixed: /variables before /{config_id}

CLAUDE.md:
- Added Frontend Architecture Notes (i18n, Svelte 5 runes, auth
  flow, Tailwind v4 quirks)
- Added Backend Architecture Notes (SQLAlchemy+aiohttp greenlet
  issue, SandboxedEnvironment import, system-owned entities,
  FastAPI route ordering, __pycache__)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-19 19:12:46 +03:00
parent aab29e253f
commit 5870ebd216
18 changed files with 214 additions and 55 deletions

View File

@@ -38,11 +38,7 @@ async def _seed_default_templates():
from sqlmodel import func, select
from sqlmodel.ext.asyncio.session import AsyncSession
from .database.engine import get_engine
from .database.models import (
TemplateConfig,
DEFAULT_TEMPLATE_EN,
DEFAULT_TEMPLATE_RU,
)
from .database.models import TemplateConfig, get_default_templates
engine = get_engine()
async with AsyncSession(engine) as session:
@@ -52,8 +48,8 @@ async def _seed_default_templates():
return
# user_id=0 means system-owned (available to all users)
en = TemplateConfig(user_id=0, name="Default EN", icon="mdiTranslate", **DEFAULT_TEMPLATE_EN)
ru = TemplateConfig(user_id=0, name="По умолчанию RU", icon="mdiTranslate", **DEFAULT_TEMPLATE_RU)
en = TemplateConfig(user_id=0, name="Default EN", icon="mdiTranslate", **get_default_templates("en"))
ru = TemplateConfig(user_id=0, name="По умолчанию RU", icon="mdiTranslate", **get_default_templates("ru"))
session.add(en)
session.add(ru)
await session.commit()