2026-05-10 09:08:12 +02:00
|
|
|
from fastapi.templating import Jinja2Templates
|
|
|
|
|
from devplacepy.config import TEMPLATES_DIR
|
|
|
|
|
from devplacepy.database import get_table
|
2026-05-11 03:14:43 +02:00
|
|
|
from devplacepy.avatar import avatar_url
|
2026-05-11 05:30:51 +02:00
|
|
|
from devplacepy.seo import (
|
|
|
|
|
site_url, combine,
|
|
|
|
|
website_schema, breadcrumb_schema,
|
|
|
|
|
discussion_forum_posting, profile_page_schema,
|
|
|
|
|
software_application_schema, truncate,
|
|
|
|
|
)
|
2026-05-10 09:08:12 +02:00
|
|
|
|
|
|
|
|
templates = Jinja2Templates(directory=str(TEMPLATES_DIR))
|
|
|
|
|
|
|
|
|
|
|
2026-05-11 03:14:43 +02:00
|
|
|
_unread_cache = {}
|
|
|
|
|
|
2026-05-10 09:08:12 +02:00
|
|
|
def jinja_unread_count(user_uid: str) -> int:
|
2026-05-11 03:14:43 +02:00
|
|
|
if user_uid in _unread_cache:
|
|
|
|
|
return _unread_cache[user_uid]
|
2026-05-10 09:08:12 +02:00
|
|
|
notifs = get_table("notifications")
|
2026-05-11 03:14:43 +02:00
|
|
|
count = len(list(notifs.find(user_uid=user_uid, read=False)))
|
|
|
|
|
_unread_cache[user_uid] = count
|
|
|
|
|
return count
|
2026-05-10 09:08:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def jinja_user_projects(user_uid: str) -> list:
|
|
|
|
|
projects = get_table("projects")
|
|
|
|
|
return list(projects.find(user_uid=user_uid))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
templates.env.globals["get_unread_count"] = jinja_unread_count
|
|
|
|
|
templates.env.globals["get_user_projects"] = jinja_user_projects
|
2026-05-10 21:33:53 +02:00
|
|
|
templates.env.globals["avatar_url"] = avatar_url
|