43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
from fastapi import APIRouter, Form, Request, status
|
|
from fastapi.responses import HTMLResponse, RedirectResponse
|
|
from fastapi.templating import Jinja2Templates
|
|
|
|
BASE_DIR = Path(__file__).resolve().parents[1]
|
|
templates = Jinja2Templates(directory=str(BASE_DIR / 'templates'))
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get('/', response_class=HTMLResponse)
|
|
def dashboard(request: Request) -> HTMLResponse:
|
|
summary = request.app.state.store.dashboard_summary()
|
|
return templates.TemplateResponse(
|
|
request,
|
|
'dashboard.html',
|
|
{
|
|
'summary': summary,
|
|
},
|
|
)
|
|
|
|
|
|
@router.post('/quick-actions/notes')
|
|
def quick_add_note_form(
|
|
request: Request,
|
|
title: str = Form(...),
|
|
body: str = Form(...),
|
|
category: str = Form('note'),
|
|
) -> RedirectResponse:
|
|
request.app.state.store.add_quick_note(
|
|
{
|
|
'title': title,
|
|
'body': body,
|
|
'category': category,
|
|
'source': 'dashboard-form',
|
|
'pinned': False,
|
|
}
|
|
)
|
|
return RedirectResponse(url='/', status_code=status.HTTP_303_SEE_OTHER)
|