function get_system_settings
Retrieves system-wide configuration settings from a Neo4j database, returning default values if settings are not found or an error occurs.
/tf/active/vicechatdev/CDocs/controllers/admin_controller.py
432 - 475
simple
Purpose
This function fetches application-level system settings stored as a SystemSettings node in Neo4j. It provides a centralized way to access configuration parameters like site name, company name, theme preferences, and security settings. If the database query fails or no settings exist, it returns a predefined set of default values to ensure the application can continue functioning.
Source Code
def get_system_settings() -> Dict[str, Any]:
"""
Get current system settings.
Returns:
Dictionary containing system settings
"""
# For Neo4j, we might store settings as a special node
try:
settings_result = db.run_query(
"""
MATCH (s:SystemSettings)
RETURN s LIMIT 1
"""
)
if settings_result and 's' in settings_result[0]:
return dict(settings_result[0]['s'])
else:
# Return default settings
return {
'site_name': 'Controlled Document System',
'company_name': 'ViceBio',
'admin_email': settings.ADMIN_EMAIL,
'logo_url': '/static/images/logo.png',
'theme': 'light',
'allow_registration': False,
'default_role': 'USER',
'session_timeout': 3600
}
except Exception as e:
logger.error(f"Error getting system settings: {e}")
# Return default values if error occurs
return {
'site_name': 'Controlled Document System',
'company_name': 'ViceBio',
'admin_email': settings.ADMIN_EMAIL if hasattr(settings, 'ADMIN_EMAIL') else '',
'logo_url': '/static/images/logo.png',
'theme': 'light',
'allow_registration': False,
'default_role': 'USER',
'session_timeout': 3600
}
Return Value
Type: Dict[str, Any]
Returns a dictionary (Dict[str, Any]) containing system configuration settings. Keys include: 'site_name' (str), 'company_name' (str), 'admin_email' (str), 'logo_url' (str), 'theme' (str), 'allow_registration' (bool), 'default_role' (str), and 'session_timeout' (int). If the SystemSettings node exists in Neo4j, returns its properties; otherwise returns hardcoded default values.
Dependencies
loggingtypingCDocs.dbCDocs.config
Required Imports
from typing import Dict, Any
from CDocs import db
from CDocs.config import settings
import logging
Usage Example
from typing import Dict, Any
from CDocs import db
from CDocs.config import settings
import logging
logger = logging.getLogger(__name__)
# Get system settings
system_config = get_system_settings()
# Access specific settings
site_name = system_config['site_name']
company_name = system_config['company_name']
theme = system_config['theme']
session_timeout = system_config['session_timeout']
# Use settings in application logic
if system_config['allow_registration']:
# Enable user registration
pass
print(f"Site: {site_name}, Company: {company_name}")
print(f"Theme: {theme}, Timeout: {session_timeout}s")
Best Practices
- This function always returns a valid dictionary, making it safe to use without additional null checks
- The function implements graceful degradation by returning default values on database errors
- Ensure the Neo4j database connection (db module) is properly initialized before calling this function
- The SystemSettings node should follow the pattern: CREATE (s:SystemSettings {site_name: '...', company_name: '...', ...})
- Only one SystemSettings node should exist in the database (enforced by LIMIT 1 in query)
- Consider caching the result of this function if called frequently to reduce database queries
- The function logs errors but does not raise exceptions, ensuring application stability
- Verify that settings.ADMIN_EMAIL is configured to avoid empty admin_email values
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_system_configuration 74.0% similar
-
function get_default_connection_config 55.7% similar
-
function get_config_value 54.3% similar
-
function get_system_stats 50.3% similar
-
function api_get_system_config 49.5% similar