Files
TimeTracker/app/utils/context_processors.py
Dries Peeters 1b3a703c04 feat: comprehensive project cleanup and timezone enhancement
- Remove redundant documentation files (DATABASE_INIT_FIX_*.md, TIMEZONE_FIX_README.md)
- Delete unused Docker files (Dockerfile.test, Dockerfile.combined, docker-compose.yml)
- Remove obsolete deployment scripts (deploy.sh) and unused files (index.html, _config.yml)
- Clean up logs directory (remove 2MB timetracker.log, keep .gitkeep)
- Remove .pytest_cache directory

- Consolidate Docker setup to two main container types:
  * Simple container (recommended for production)
  * Public container (for development/testing)

- Enhance timezone support in admin settings:
  * Add 100+ timezone options organized by region
  * Implement real-time timezone preview with current time display
  * Add timezone offset calculation and display
  * Remove search functionality for cleaner interface
  * Update timezone utility functions for database-driven configuration

- Update documentation:
  * Revise README.md to reflect current project state
  * Add comprehensive timezone features documentation
  * Update Docker deployment instructions
  * Create PROJECT_STRUCTURE.md for project overview
  * Remove references to deleted files

- Improve project structure:
  * Streamlined file organization
  * Better maintainability and focus
  * Preserved all essential functionality
  * Cleaner deployment options
2025-08-28 14:52:09 +02:00

60 lines
2.1 KiB
Python

from flask import g, request
from app.models import Settings
from app.utils.timezone import get_timezone_offset_for_timezone
def register_context_processors(app):
"""Register context processors for the application"""
@app.context_processor
def inject_settings():
"""Inject settings into all templates"""
try:
from app import db
# Check if we have an active database session
if db.session.is_active:
settings = Settings.get_settings()
return {
'settings': settings,
'currency': settings.currency,
'timezone': settings.timezone
}
except Exception as e:
# Log the error but continue with defaults
print(f"Warning: Could not inject settings: {e}")
pass
# Return defaults if settings not available
return {
'settings': None,
'currency': 'EUR',
'timezone': 'Europe/Rome'
}
@app.context_processor
def inject_globals():
"""Inject global variables into all templates"""
try:
from app import db
# Check if we have an active database session
if db.session.is_active:
settings = Settings.get_settings()
timezone_name = settings.timezone if settings else 'Europe/Rome'
else:
timezone_name = 'Europe/Rome'
except Exception as e:
# Log the error but continue with defaults
print(f"Warning: Could not inject globals: {e}")
timezone_name = 'Europe/Rome'
return {
'app_name': 'Time Tracker',
'app_version': '1.0.0',
'timezone': timezone_name,
'timezone_offset': get_timezone_offset_for_timezone(timezone_name)
}
@app.before_request
def before_request():
"""Set up request-specific data"""
g.request_start_time = request.start_time if hasattr(request, 'start_time') else None