Files
postbot/app/bots/editor/templates.py

25 lines
874 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Функции для работы с шаблонами."""
from __future__ import annotations
from typing import Optional
from sqlalchemy import select
from app.db.session import async_session_maker
from app.models.templates import Template
async def list_templates(owner_id: Optional[int] = None):
"""Получение списка шаблонов."""
async with async_session_maker() as session:
stmt = select(Template)
if owner_id:
stmt = stmt.filter(Template.owner_id == owner_id)
result = await session.execute(stmt)
return result.scalars().all()
async def create_template(template_data: dict):
"""Создание нового шаблона."""
async with async_session_maker() as session:
template = Template(**template_data)
session.add(template)
await session.commit()