Skip to content

Commit

Permalink
Merge pull request #4035 from airqo-platform/website-trigger-3
Browse files Browse the repository at this point in the history
website: updating settings file
  • Loading branch information
Baalmart authored Dec 10, 2024
2 parents 6dbfb84 + fff0667 commit 7a1d5dd
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 6 deletions.
157 changes: 153 additions & 4 deletions src/website/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def require_env_var(env_var: str) -> str:
ALLOWED_HOSTS = parse_env_list('ALLOWED_HOSTS', default='localhost,127.0.0.1')

# ---------------------------------------------------------
# Applications
# Installed Apps
# ---------------------------------------------------------
INSTALLED_APPS = [
# Django Defaults
Expand Down Expand Up @@ -115,9 +115,11 @@ def require_env_var(env_var: str) -> str:
CORS_ALLOWED_ORIGIN_REGEXES = parse_env_list('CORS_ORIGIN_REGEX_WHITELIST')
CSRF_TRUSTED_ORIGINS = parse_env_list('CSRF_TRUSTED_ORIGINS')

# If no CORS settings provided, consider defaulting to empty lists
CORS_ALLOWED_ORIGINS = CORS_ALLOWED_ORIGINS if CORS_ALLOWED_ORIGINS else []
CORS_ALLOWED_ORIGIN_REGEXES = CORS_ALLOWED_ORIGIN_REGEXES if CORS_ALLOWED_ORIGIN_REGEXES else []
# Ensure no trailing slashes and correct schemes
CORS_ALLOWED_ORIGINS = [origin.rstrip('/') for origin in CORS_ALLOWED_ORIGINS]
CORS_ALLOWED_ORIGIN_REGEXES = [regex.rstrip(
'/') for regex in CORS_ALLOWED_ORIGIN_REGEXES]
CSRF_TRUSTED_ORIGINS = [origin.rstrip('/') for origin in CSRF_TRUSTED_ORIGINS]

# Security cookies
CSRF_COOKIE_SECURE = not DEBUG
Expand Down Expand Up @@ -269,3 +271,150 @@ def require_env_var(env_var: str) -> str:
'scrollingContainer': '#scrolling-container',
},
}

# ---------------------------------------------------------
# File Upload Settings
# ---------------------------------------------------------
# Increase these values as needed to handle larger uploads
FILE_UPLOAD_MAX_MEMORY_SIZE = 10485760 # 10 MB
DATA_UPLOAD_MAX_MEMORY_SIZE = 10485760 # 10 MB

# ---------------------------------------------------------
# SSL and Proxy Settings (if behind a reverse proxy)
# ---------------------------------------------------------
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
USE_X_FORWARDED_HOST = True

# ---------------------------------------------------------
# Logging Configuration
# ---------------------------------------------------------
LOG_DIR = BASE_DIR / 'logs'
LOG_DIR.mkdir(exist_ok=True) # Ensure log directory exists

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
# Formatters
'formatters': {
'verbose': {
'format': '[%(asctime)s] %(levelname)s %(name)s [%(filename)s:%(lineno)d] %(message)s',
'datefmt': '%Y-%m-%d %H:%M:%S'
},
'simple': {
'format': '%(levelname)s %(message)s'
},
},
# Handlers
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'formatter': 'verbose',
'level': 'DEBUG' if DEBUG else 'INFO',
},
'file': {
'class': 'logging.FileHandler',
'filename': LOG_DIR / 'django.log',
'formatter': 'verbose',
'level': 'INFO',
},
'error_file': {
'class': 'logging.FileHandler',
'filename': LOG_DIR / 'django_errors.log',
'formatter': 'verbose',
'level': 'ERROR',
},
},
# Loggers
'loggers': {
# Django Logs
'django': {
'handlers': ['console', 'file', 'error_file'],
'level': 'INFO',
'propagate': True,
},
# Cloudinary Logs
'cloudinary': {
'handlers': ['console', 'file', 'error_file'],
'level': 'INFO',
'propagate': True,
},
# Event App Logs
'apps.event': {
'handlers': ['console', 'file', 'error_file'],
'level': 'DEBUG' if DEBUG else 'INFO',
'propagate': False,
},
# CleanAir App Logs
'apps.cleanair': {
'handlers': ['console', 'file', 'error_file'],
'level': 'DEBUG' if DEBUG else 'INFO',
'propagate': False,
},
# AfricanCities App Logs
'apps.africancities': {
'handlers': ['console', 'file', 'error_file'],
'level': 'DEBUG' if DEBUG else 'INFO',
'propagate': False,
},
# Publications App Logs
'apps.publications': {
'handlers': ['console', 'file', 'error_file'],
'level': 'DEBUG' if DEBUG else 'INFO',
'propagate': False,
},
# Press App Logs
'apps.press': {
'handlers': ['console', 'file', 'error_file'],
'level': 'DEBUG' if DEBUG else 'INFO',
'propagate': False,
},
# Impact App Logs
'apps.impact': {
'handlers': ['console', 'file', 'error_file'],
'level': 'DEBUG' if DEBUG else 'INFO',
'propagate': False,
},
# FAQs App Logs
'apps.faqs': {
'handlers': ['console', 'file', 'error_file'],
'level': 'DEBUG' if DEBUG else 'INFO',
'propagate': False,
},
# Highlights App Logs
'apps.highlights': {
'handlers': ['console', 'file', 'error_file'],
'level': 'DEBUG' if DEBUG else 'INFO',
'propagate': False,
},
# Career App Logs
'apps.career': {
'handlers': ['console', 'file', 'error_file'],
'level': 'DEBUG' if DEBUG else 'INFO',
'propagate': False,
},
# Partners App Logs
'apps.partners': {
'handlers': ['console', 'file', 'error_file'],
'level': 'DEBUG' if DEBUG else 'INFO',
'propagate': False,
},
# Board App Logs
'apps.board': {
'handlers': ['console', 'file', 'error_file'],
'level': 'DEBUG' if DEBUG else 'INFO',
'propagate': False,
},
# Team App Logs
'apps.team': {
'handlers': ['console', 'file', 'error_file'],
'level': 'DEBUG' if DEBUG else 'INFO',
'propagate': False,
},
# ExternalTeams App Logs
'apps.externalteams': {
'handlers': ['console', 'file', 'error_file'],
'level': 'DEBUG' if DEBUG else 'INFO',
'propagate': False,
},
}
}
3 changes: 1 addition & 2 deletions src/website/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ python manage.py collectstatic --noinput

# Start Gunicorn server to serve the Django application
echo "Starting Gunicorn server..."
exec gunicorn core.wsgi:application --bind 0.0.0.0:8000 --timeout 600 --log-level info
# exec gunicorn core.wsgi:application --bind 0.0.0.0:8000 --timeout 600 --workers ${GUNICORN_WORKERS:-3} --log-level info
exec gunicorn core.wsgi:application --bind 0.0.0.0:8000 --timeout 600 --workers 3 --log-level info

0 comments on commit 7a1d5dd

Please sign in to comment.