Files
gh-christianlouis-leagueledger/app/templates_config.py
T
Christian Krakau-Louis 4a79c5cacb Refactor user authentication and dashboard features
- Added `is_admin` field to User model for role management.
- Updated user context middleware to include current user in templates.
- Enhanced session management with improved debug middleware.
- Refactored dashboard view to fetch user-specific data and recent events.
- Improved login and registration templates for better user experience.
- Added admin routes with access control for admin users.
- Updated Docker configuration for better error logging and dependency management.
- Updated requirements to include new dependencies and specify versions.
2025-04-13 18:49:27 +02:00

24 lines
957 B
Python

#!/usr/bin/env python3
from fastapi.templating import Jinja2Templates
from pathlib import Path
from jinja2 import Environment, FileSystemLoader
from starlette.templating import _TemplateResponse
from datetime import datetime
from typing import Any
BASE_DIR = Path(__file__).resolve().parent
# Create a Jinja2 Environment with the 'jinja2.ext.do' extension
class MyJinjaTemplates(Jinja2Templates):
def __init__(self, directory: str, **kwargs: Any):
super().__init__(directory=directory, **kwargs)
self.env.add_extension('jinja2.ext.do')
self.env.globals['now'] = datetime.now # Add 'now' function
# Create templates object that can be imported elsewhere
templates = MyJinjaTemplates(directory=str(BASE_DIR / "templates"))
# Register a context processor to add current_user to all templates
templates.env.globals["get_current_user"] = lambda: None # Will be overridden at runtime
templates.env.globals["current_user"] = None