""" Shared Jinja2 templates configuration. All routers should import `templates` from this module to get consistent filter and global function registration. """ from fastapi.templating import Jinja2Templates # Import timezone utilities from backend.utils.timezone import ( format_local_datetime, format_local_time, get_user_timezone, get_timezone_abbreviation ) def jinja_local_datetime(dt, fmt="%Y-%m-%d %H:%M"): """Jinja filter to convert UTC datetime to local timezone.""" return format_local_datetime(dt, fmt) def jinja_local_time(dt): """Jinja filter to format time in local timezone.""" return format_local_time(dt) def jinja_timezone_abbr(): """Jinja global to get current timezone abbreviation.""" return get_timezone_abbreviation() # Create templates instance templates = Jinja2Templates(directory="templates") # Register Jinja filters and globals templates.env.filters["local_datetime"] = jinja_local_datetime templates.env.filters["local_time"] = jinja_local_time templates.env.globals["timezone_abbr"] = jinja_timezone_abbr templates.env.globals["get_user_timezone"] = get_user_timezone