feat: add license page and version display in templates, update LICENSE file, and enhance footer with license information
This commit is contained in:
@@ -15,6 +15,20 @@ from app.config import settings
|
||||
templates_dir = Path(__file__).parent.parent.parent / "frontend" / "templates"
|
||||
templates = Jinja2Templates(directory=str(templates_dir))
|
||||
|
||||
# Customize Jinja2Templates to include app_version in all templates
|
||||
original_template_response = templates.TemplateResponse
|
||||
|
||||
def template_response_with_version(*args, **kwargs):
|
||||
"""Wrapper for TemplateResponse to include version in all templates"""
|
||||
# If context dict is provided, add version to it
|
||||
if len(args) >= 2 and isinstance(args[1], dict):
|
||||
args[1].setdefault("version", settings.version)
|
||||
elif "context" in kwargs and isinstance(kwargs["context"], dict):
|
||||
kwargs["context"].setdefault("version", settings.version)
|
||||
return original_template_response(*args, **kwargs)
|
||||
|
||||
templates.TemplateResponse = template_response_with_version
|
||||
|
||||
# Set up logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -33,3 +33,44 @@ def favicon():
|
||||
# If favicon doesn't exist, return a 404
|
||||
raise HTTPException(status_code=404, detail="Favicon not found")
|
||||
return FileResponse(favicon_path)
|
||||
|
||||
@router.get("/license", include_in_schema=False)
|
||||
async def serve_license(request: Request):
|
||||
"""Serve the license page."""
|
||||
# Try multiple possible locations for the license file
|
||||
possible_locations = [
|
||||
Path(__file__).parent.parent.parent / "LICENSE", # Repository root
|
||||
Path("/app/LICENSE"), # Docker container path
|
||||
Path.home() / "LICENSE", # Home directory (fallback)
|
||||
]
|
||||
|
||||
license_text = None
|
||||
|
||||
# Try to read from any of the possible locations
|
||||
for path in possible_locations:
|
||||
try:
|
||||
with open(path, "r") as f:
|
||||
license_text = f.read()
|
||||
break # File found and read, exit loop
|
||||
except (FileNotFoundError, PermissionError):
|
||||
continue # Try next location
|
||||
|
||||
# If license text is still None, use embedded text
|
||||
if license_text is None:
|
||||
license_text = """
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
This software is licensed under the Apache License 2.0.
|
||||
The full license text could not be located on this system.
|
||||
Please visit http://www.apache.org/licenses/LICENSE-2.0 for the complete license text.
|
||||
"""
|
||||
|
||||
return templates.TemplateResponse(
|
||||
"license.html",
|
||||
{
|
||||
"request": request,
|
||||
"license_text": license_text
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user