|
from fastapi.templating import Jinja2Templates
|
|
from devplacepy.config import TEMPLATES_DIR
|
|
from devplacepy.database import get_table
|
|
from devplacepy.avatar import avatar_url
|
|
|
|
templates = Jinja2Templates(directory=str(TEMPLATES_DIR))
|
|
|
|
|
|
_unread_cache = {}
|
|
|
|
def jinja_unread_count(user_uid: str) -> int:
|
|
if user_uid in _unread_cache:
|
|
return _unread_cache[user_uid]
|
|
notifs = get_table("notifications")
|
|
count = len(list(notifs.find(user_uid=user_uid, read=False)))
|
|
_unread_cache[user_uid] = count
|
|
return count
|
|
|
|
|
|
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
|
|
templates.env.globals["avatar_url"] = avatar_url
|