mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 05:51:08 -05:00
Refactor test utilities and enhance ASGI settings
- Cleaned up and standardized assertions in ApiTestMixin for API response validation. - Updated ASGI settings to use os.environ for setting the DJANGO_SETTINGS_MODULE. - Removed unused imports and improved formatting in settings.py. - Refactored URL patterns in urls.py for better readability and organization. - Enhanced view functions in views.py for consistency and clarity. - Added .flake8 configuration for linting and style enforcement. - Introduced type stubs for django-environ to improve type checking with Pylance.
This commit is contained in:
@@ -1,2 +1 @@
|
||||
# Django settings package
|
||||
|
||||
|
||||
@@ -3,38 +3,37 @@ Base Django settings for thrillwiki project.
|
||||
Common settings shared across all environments.
|
||||
"""
|
||||
|
||||
import os
|
||||
import environ
|
||||
import environ # type: ignore[import]
|
||||
from pathlib import Path
|
||||
|
||||
# Initialize environment variables
|
||||
env = environ.Env(
|
||||
DEBUG=(bool, False),
|
||||
SECRET_KEY=(str, ''),
|
||||
SECRET_KEY=(str, ""),
|
||||
ALLOWED_HOSTS=(list, []),
|
||||
DATABASE_URL=(str, ''),
|
||||
CACHE_URL=(str, 'locmem://'),
|
||||
EMAIL_URL=(str, ''),
|
||||
REDIS_URL=(str, ''),
|
||||
DATABASE_URL=(str, ""),
|
||||
CACHE_URL=(str, "locmem://"),
|
||||
EMAIL_URL=(str, ""),
|
||||
REDIS_URL=(str, ""),
|
||||
)
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent.parent
|
||||
|
||||
# Read environment file if it exists
|
||||
environ.Env.read_env(BASE_DIR / '.env')
|
||||
environ.Env.read_env(BASE_DIR / ".env")
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = env('SECRET_KEY')
|
||||
SECRET_KEY = env("SECRET_KEY")
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = env('DEBUG')
|
||||
DEBUG = env("DEBUG")
|
||||
|
||||
# Allowed hosts
|
||||
ALLOWED_HOSTS = env('ALLOWED_HOSTS')
|
||||
ALLOWED_HOSTS = env("ALLOWED_HOSTS")
|
||||
|
||||
# CSRF trusted origins
|
||||
CSRF_TRUSTED_ORIGINS = env('CSRF_TRUSTED_ORIGINS', default=[])
|
||||
CSRF_TRUSTED_ORIGINS = env("CSRF_TRUSTED_ORIGINS", default=[]) # type: ignore[arg-type]
|
||||
|
||||
# Application definition
|
||||
DJANGO_APPS = [
|
||||
@@ -119,7 +118,7 @@ TEMPLATES = [
|
||||
"django.contrib.messages.context_processors.messages",
|
||||
"moderation.context_processors.moderation_access",
|
||||
]
|
||||
}
|
||||
},
|
||||
}
|
||||
]
|
||||
|
||||
@@ -128,7 +127,9 @@ WSGI_APPLICATION = "thrillwiki.wsgi.application"
|
||||
# Password validation
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
|
||||
"NAME": (
|
||||
"django.contrib.auth.password_validation.UserAttributeSimilarityValidator"
|
||||
),
|
||||
},
|
||||
{
|
||||
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
|
||||
@@ -167,8 +168,8 @@ AUTHENTICATION_BACKENDS = [
|
||||
|
||||
# django-allauth settings
|
||||
SITE_ID = 1
|
||||
ACCOUNT_SIGNUP_FIELDS = ['email*', 'username*', 'password1*', 'password2*']
|
||||
ACCOUNT_LOGIN_METHODS = {'email', 'username'}
|
||||
ACCOUNT_SIGNUP_FIELDS = ["email*", "username*", "password1*", "password2*"]
|
||||
ACCOUNT_LOGIN_METHODS = {"email", "username"}
|
||||
ACCOUNT_EMAIL_VERIFICATION = "optional"
|
||||
LOGIN_REDIRECT_URL = "/"
|
||||
ACCOUNT_LOGOUT_REDIRECT_URL = "/"
|
||||
@@ -189,7 +190,7 @@ SOCIALACCOUNT_PROVIDERS = {
|
||||
"discord": {
|
||||
"SCOPE": ["identify", "email"],
|
||||
"OAUTH_PKCE_ENABLED": True,
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
# Additional social account settings
|
||||
@@ -222,149 +223,155 @@ ROADTRIP_BACKOFF_FACTOR = 2
|
||||
|
||||
# Django REST Framework Settings
|
||||
REST_FRAMEWORK = {
|
||||
'DEFAULT_AUTHENTICATION_CLASSES': [
|
||||
'rest_framework.authentication.SessionAuthentication',
|
||||
'rest_framework.authentication.TokenAuthentication',
|
||||
"DEFAULT_AUTHENTICATION_CLASSES": [
|
||||
"rest_framework.authentication.SessionAuthentication",
|
||||
"rest_framework.authentication.TokenAuthentication",
|
||||
],
|
||||
'DEFAULT_PERMISSION_CLASSES': [
|
||||
'rest_framework.permissions.IsAuthenticated',
|
||||
"DEFAULT_PERMISSION_CLASSES": [
|
||||
"rest_framework.permissions.IsAuthenticated",
|
||||
],
|
||||
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
|
||||
'PAGE_SIZE': 20,
|
||||
'DEFAULT_VERSIONING_CLASS': 'rest_framework.versioning.AcceptHeaderVersioning',
|
||||
'DEFAULT_VERSION': 'v1',
|
||||
'ALLOWED_VERSIONS': ['v1'],
|
||||
'DEFAULT_RENDERER_CLASSES': [
|
||||
'rest_framework.renderers.JSONRenderer',
|
||||
'rest_framework.renderers.BrowsableAPIRenderer',
|
||||
"DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination",
|
||||
"PAGE_SIZE": 20,
|
||||
"DEFAULT_VERSIONING_CLASS": "rest_framework.versioning.AcceptHeaderVersioning",
|
||||
"DEFAULT_VERSION": "v1",
|
||||
"ALLOWED_VERSIONS": ["v1"],
|
||||
"DEFAULT_RENDERER_CLASSES": [
|
||||
"rest_framework.renderers.JSONRenderer",
|
||||
"rest_framework.renderers.BrowsableAPIRenderer",
|
||||
],
|
||||
'DEFAULT_PARSER_CLASSES': [
|
||||
'rest_framework.parsers.JSONParser',
|
||||
'rest_framework.parsers.FormParser',
|
||||
'rest_framework.parsers.MultiPartParser',
|
||||
"DEFAULT_PARSER_CLASSES": [
|
||||
"rest_framework.parsers.JSONParser",
|
||||
"rest_framework.parsers.FormParser",
|
||||
"rest_framework.parsers.MultiPartParser",
|
||||
],
|
||||
'EXCEPTION_HANDLER': 'core.api.exceptions.custom_exception_handler',
|
||||
'DEFAULT_FILTER_BACKENDS': [
|
||||
'django_filters.rest_framework.DjangoFilterBackend',
|
||||
'rest_framework.filters.SearchFilter',
|
||||
'rest_framework.filters.OrderingFilter',
|
||||
"EXCEPTION_HANDLER": "core.api.exceptions.custom_exception_handler",
|
||||
"DEFAULT_FILTER_BACKENDS": [
|
||||
"django_filters.rest_framework.DjangoFilterBackend",
|
||||
"rest_framework.filters.SearchFilter",
|
||||
"rest_framework.filters.OrderingFilter",
|
||||
],
|
||||
'TEST_REQUEST_DEFAULT_FORMAT': 'json',
|
||||
'NON_FIELD_ERRORS_KEY': 'non_field_errors',
|
||||
'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
|
||||
"TEST_REQUEST_DEFAULT_FORMAT": "json",
|
||||
"NON_FIELD_ERRORS_KEY": "non_field_errors",
|
||||
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
|
||||
}
|
||||
|
||||
# CORS Settings for API
|
||||
CORS_ALLOWED_ORIGINS = env('CORS_ALLOWED_ORIGINS', default=[])
|
||||
CORS_ALLOWED_ORIGINS = env("CORS_ALLOWED_ORIGINS", default=[]) # type: ignore[arg-type]
|
||||
CORS_ALLOW_CREDENTIALS = True
|
||||
CORS_ALLOW_ALL_ORIGINS = env('CORS_ALLOW_ALL_ORIGINS', default=False)
|
||||
CORS_ALLOW_ALL_ORIGINS = env(
|
||||
"CORS_ALLOW_ALL_ORIGINS", default=False
|
||||
) # type: ignore[arg-type]
|
||||
|
||||
# API-specific settings
|
||||
API_RATE_LIMIT_PER_MINUTE = env.int('API_RATE_LIMIT_PER_MINUTE', default=60)
|
||||
API_RATE_LIMIT_PER_HOUR = env.int('API_RATE_LIMIT_PER_HOUR', default=1000)
|
||||
API_RATE_LIMIT_PER_MINUTE = env.int(
|
||||
"API_RATE_LIMIT_PER_MINUTE", default=60
|
||||
) # type: ignore[arg-type]
|
||||
API_RATE_LIMIT_PER_HOUR = env.int(
|
||||
"API_RATE_LIMIT_PER_HOUR", default=1000
|
||||
) # type: ignore[arg-type]
|
||||
|
||||
# drf-spectacular settings
|
||||
SPECTACULAR_SETTINGS = {
|
||||
'TITLE': 'ThrillWiki API',
|
||||
'DESCRIPTION': 'Comprehensive theme park and ride information API',
|
||||
'VERSION': '1.0.0',
|
||||
'SERVE_INCLUDE_SCHEMA': False,
|
||||
'COMPONENT_SPLIT_REQUEST': True,
|
||||
'TAGS': [
|
||||
{'name': 'parks', 'description': 'Theme park operations'},
|
||||
{'name': 'rides', 'description': 'Ride information and management'},
|
||||
{'name': 'locations', 'description': 'Geographic location services'},
|
||||
{'name': 'accounts', 'description': 'User account management'},
|
||||
{'name': 'media', 'description': 'Media and image management'},
|
||||
{'name': 'moderation', 'description': 'Content moderation'},
|
||||
"TITLE": "ThrillWiki API",
|
||||
"DESCRIPTION": "Comprehensive theme park and ride information API",
|
||||
"VERSION": "1.0.0",
|
||||
"SERVE_INCLUDE_SCHEMA": False,
|
||||
"COMPONENT_SPLIT_REQUEST": True,
|
||||
"TAGS": [
|
||||
{"name": "parks", "description": "Theme park operations"},
|
||||
{"name": "rides", "description": "Ride information and management"},
|
||||
{"name": "locations", "description": "Geographic location services"},
|
||||
{"name": "accounts", "description": "User account management"},
|
||||
{"name": "media", "description": "Media and image management"},
|
||||
{"name": "moderation", "description": "Content moderation"},
|
||||
],
|
||||
'SCHEMA_PATH_PREFIX': '/api/',
|
||||
'DEFAULT_GENERATOR_CLASS': 'drf_spectacular.generators.SchemaGenerator',
|
||||
'SERVE_PERMISSIONS': ['rest_framework.permissions.AllowAny'],
|
||||
'SWAGGER_UI_SETTINGS': {
|
||||
'deepLinking': True,
|
||||
'persistAuthorization': True,
|
||||
'displayOperationId': False,
|
||||
'displayRequestDuration': True,
|
||||
"SCHEMA_PATH_PREFIX": "/api/",
|
||||
"DEFAULT_GENERATOR_CLASS": "drf_spectacular.generators.SchemaGenerator",
|
||||
"SERVE_PERMISSIONS": ["rest_framework.permissions.AllowAny"],
|
||||
"SWAGGER_UI_SETTINGS": {
|
||||
"deepLinking": True,
|
||||
"persistAuthorization": True,
|
||||
"displayOperationId": False,
|
||||
"displayRequestDuration": True,
|
||||
},
|
||||
"REDOC_UI_SETTINGS": {
|
||||
"hideDownloadButton": False,
|
||||
"hideHostname": False,
|
||||
"hideLoading": False,
|
||||
"hideSchemaPattern": True,
|
||||
"scrollYOffset": 0,
|
||||
"theme": {"colors": {"primary": {"main": "#1976d2"}}},
|
||||
},
|
||||
'REDOC_UI_SETTINGS': {
|
||||
'hideDownloadButton': False,
|
||||
'hideHostname': False,
|
||||
'hideLoading': False,
|
||||
'hideSchemaPattern': True,
|
||||
'scrollYOffset': 0,
|
||||
'theme': {
|
||||
'colors': {
|
||||
'primary': {
|
||||
'main': '#1976d2'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Health Check Configuration
|
||||
HEALTH_CHECK = {
|
||||
'DISK_USAGE_MAX': 90, # Fail if disk usage is over 90%
|
||||
'MEMORY_MIN': 100, # Fail if less than 100MB available memory
|
||||
"DISK_USAGE_MAX": 90, # Fail if disk usage is over 90%
|
||||
"MEMORY_MIN": 100, # Fail if less than 100MB available memory
|
||||
}
|
||||
|
||||
# Custom health check backends
|
||||
HEALTH_CHECK_BACKENDS = [
|
||||
'health_check.db',
|
||||
'health_check.cache',
|
||||
'health_check.storage',
|
||||
'core.health_checks.custom_checks.CacheHealthCheck',
|
||||
'core.health_checks.custom_checks.DatabasePerformanceCheck',
|
||||
'core.health_checks.custom_checks.ApplicationHealthCheck',
|
||||
'core.health_checks.custom_checks.ExternalServiceHealthCheck',
|
||||
'core.health_checks.custom_checks.DiskSpaceHealthCheck',
|
||||
"health_check.db",
|
||||
"health_check.cache",
|
||||
"health_check.storage",
|
||||
"core.health_checks.custom_checks.CacheHealthCheck",
|
||||
"core.health_checks.custom_checks.DatabasePerformanceCheck",
|
||||
"core.health_checks.custom_checks.ApplicationHealthCheck",
|
||||
"core.health_checks.custom_checks.ExternalServiceHealthCheck",
|
||||
"core.health_checks.custom_checks.DiskSpaceHealthCheck",
|
||||
]
|
||||
|
||||
# Enhanced Cache Configuration
|
||||
DJANGO_REDIS_CACHE_BACKEND = 'django_redis.cache.RedisCache'
|
||||
DJANGO_REDIS_CLIENT_CLASS = 'django_redis.client.DefaultClient'
|
||||
DJANGO_REDIS_CACHE_BACKEND = "django_redis.cache.RedisCache"
|
||||
DJANGO_REDIS_CLIENT_CLASS = "django_redis.client.DefaultClient"
|
||||
|
||||
CACHES = {
|
||||
'default': {
|
||||
'BACKEND': DJANGO_REDIS_CACHE_BACKEND,
|
||||
'LOCATION': env('REDIS_URL', default='redis://127.0.0.1:6379/1'),
|
||||
'OPTIONS': {
|
||||
'CLIENT_CLASS': DJANGO_REDIS_CLIENT_CLASS,
|
||||
'PARSER_CLASS': 'redis.connection.HiredisParser',
|
||||
'CONNECTION_POOL_CLASS': 'redis.BlockingConnectionPool',
|
||||
'CONNECTION_POOL_CLASS_KWARGS': {
|
||||
'max_connections': 50,
|
||||
'timeout': 20,
|
||||
"default": {
|
||||
"BACKEND": DJANGO_REDIS_CACHE_BACKEND,
|
||||
# type: ignore[arg-type]
|
||||
# pyright: ignore[reportArgumentType]
|
||||
# pyright: ignore[reportArgumentType]
|
||||
# type: ignore
|
||||
"LOCATION": env("REDIS_URL", default="redis://127.0.0.1:6379/1"),
|
||||
"OPTIONS": {
|
||||
"CLIENT_CLASS": DJANGO_REDIS_CLIENT_CLASS,
|
||||
"PARSER_CLASS": "redis.connection.HiredisParser",
|
||||
"CONNECTION_POOL_CLASS": "redis.BlockingConnectionPool",
|
||||
"CONNECTION_POOL_CLASS_KWARGS": {
|
||||
"max_connections": 50,
|
||||
"timeout": 20,
|
||||
},
|
||||
'COMPRESSOR': 'django_redis.compressors.zlib.ZlibCompressor',
|
||||
'IGNORE_EXCEPTIONS': True,
|
||||
"COMPRESSOR": "django_redis.compressors.zlib.ZlibCompressor",
|
||||
"IGNORE_EXCEPTIONS": True,
|
||||
},
|
||||
'KEY_PREFIX': 'thrillwiki',
|
||||
'VERSION': 1,
|
||||
"KEY_PREFIX": "thrillwiki",
|
||||
"VERSION": 1,
|
||||
},
|
||||
'sessions': {
|
||||
'BACKEND': DJANGO_REDIS_CACHE_BACKEND,
|
||||
'LOCATION': env('REDIS_URL', default='redis://127.0.0.1:6379/2'),
|
||||
'OPTIONS': {
|
||||
'CLIENT_CLASS': DJANGO_REDIS_CLIENT_CLASS,
|
||||
}
|
||||
"sessions": {
|
||||
"BACKEND": DJANGO_REDIS_CACHE_BACKEND,
|
||||
# type: ignore[arg-type]
|
||||
# type: ignore
|
||||
"LOCATION": env("REDIS_URL", default="redis://127.0.0.1:6379/2"),
|
||||
"OPTIONS": {
|
||||
"CLIENT_CLASS": DJANGO_REDIS_CLIENT_CLASS,
|
||||
},
|
||||
},
|
||||
"api": {
|
||||
"BACKEND": DJANGO_REDIS_CACHE_BACKEND,
|
||||
# type: ignore[arg-type]
|
||||
"LOCATION": env("REDIS_URL", default="redis://127.0.0.1:6379/3"),
|
||||
"OPTIONS": {
|
||||
"CLIENT_CLASS": DJANGO_REDIS_CLIENT_CLASS,
|
||||
},
|
||||
},
|
||||
'api': {
|
||||
'BACKEND': DJANGO_REDIS_CACHE_BACKEND,
|
||||
'LOCATION': env('REDIS_URL', default='redis://127.0.0.1:6379/3'),
|
||||
'OPTIONS': {
|
||||
'CLIENT_CLASS': DJANGO_REDIS_CLIENT_CLASS,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Use Redis for sessions
|
||||
SESSION_ENGINE = 'django.contrib.sessions.backends.cache'
|
||||
SESSION_CACHE_ALIAS = 'sessions'
|
||||
SESSION_ENGINE = "django.contrib.sessions.backends.cache"
|
||||
SESSION_CACHE_ALIAS = "sessions"
|
||||
SESSION_COOKIE_AGE = 86400 # 24 hours
|
||||
|
||||
# Cache middleware settings
|
||||
CACHE_MIDDLEWARE_SECONDS = 300 # 5 minutes
|
||||
CACHE_MIDDLEWARE_KEY_PREFIX = 'thrillwiki'
|
||||
|
||||
CACHE_MIDDLEWARE_KEY_PREFIX = "thrillwiki"
|
||||
|
||||
@@ -5,11 +5,10 @@ Local development settings for thrillwiki project.
|
||||
import logging
|
||||
from .base import *
|
||||
from ..settings import database
|
||||
|
||||
# Import the module and use its members, e.g., email.EMAIL_HOST
|
||||
from ..settings import email
|
||||
|
||||
# Import the module and use its members, e.g., security.SECURE_HSTS_SECONDS
|
||||
from ..settings import security
|
||||
from .base import env # Import env for environment variable access
|
||||
|
||||
# Import database configuration
|
||||
DATABASES = database.DATABASES
|
||||
@@ -18,7 +17,7 @@ DATABASES = database.DATABASES
|
||||
DEBUG = True
|
||||
|
||||
# For local development, allow all hosts
|
||||
ALLOWED_HOSTS = ['*']
|
||||
ALLOWED_HOSTS = ["*"]
|
||||
|
||||
# CSRF trusted origins for local development
|
||||
CSRF_TRUSTED_ORIGINS = [
|
||||
@@ -51,7 +50,7 @@ CACHES = {
|
||||
"LOCATION": "api-cache",
|
||||
"TIMEOUT": 300, # 5 minutes
|
||||
"OPTIONS": {"MAX_ENTRIES": 2000},
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
# Development-friendly cache settings
|
||||
@@ -68,10 +67,10 @@ CSRF_COOKIE_SECURE = False
|
||||
|
||||
# Development monitoring tools
|
||||
DEVELOPMENT_APPS = [
|
||||
'silk',
|
||||
'debug_toolbar',
|
||||
'nplusone.ext.django',
|
||||
'django_extensions',
|
||||
"silk",
|
||||
"debug_toolbar",
|
||||
"nplusone.ext.django",
|
||||
"django_extensions",
|
||||
]
|
||||
|
||||
# Add development apps if available
|
||||
@@ -81,11 +80,11 @@ for app in DEVELOPMENT_APPS:
|
||||
|
||||
# Development middleware
|
||||
DEVELOPMENT_MIDDLEWARE = [
|
||||
'silk.middleware.SilkyMiddleware',
|
||||
'debug_toolbar.middleware.DebugToolbarMiddleware',
|
||||
'nplusone.ext.django.NPlusOneMiddleware',
|
||||
'core.middleware.performance_middleware.PerformanceMiddleware',
|
||||
'core.middleware.performance_middleware.QueryCountMiddleware',
|
||||
"silk.middleware.SilkyMiddleware",
|
||||
"debug_toolbar.middleware.DebugToolbarMiddleware",
|
||||
"nplusone.ext.django.NPlusOneMiddleware",
|
||||
"core.middleware.performance_middleware.PerformanceMiddleware",
|
||||
"core.middleware.performance_middleware.QueryCountMiddleware",
|
||||
]
|
||||
|
||||
# Add development middleware
|
||||
@@ -94,14 +93,15 @@ for middleware in DEVELOPMENT_MIDDLEWARE:
|
||||
MIDDLEWARE.insert(1, middleware) # Insert after security middleware
|
||||
|
||||
# Debug toolbar configuration
|
||||
INTERNAL_IPS = ['127.0.0.1', '::1']
|
||||
INTERNAL_IPS = ["127.0.0.1", "::1"]
|
||||
|
||||
# Silk configuration for development
|
||||
# Disable profiler to avoid silk_profile installation issues
|
||||
SILKY_PYTHON_PROFILER = False
|
||||
SILKY_PYTHON_PROFILER_BINARY = False # Disable binary profiler
|
||||
SILKY_PYTHON_PROFILER_RESULT_PATH = BASE_DIR / \
|
||||
'profiles' # Not needed when profiler is disabled
|
||||
SILKY_PYTHON_PROFILER_RESULT_PATH = (
|
||||
BASE_DIR / "profiles"
|
||||
) # Not needed when profiler is disabled
|
||||
SILKY_AUTHENTICATION = True # Require login to access Silk
|
||||
SILKY_AUTHORISATION = True # Enable authorization
|
||||
SILKY_MAX_REQUEST_BODY_SIZE = -1 # Don't limit request body size
|
||||
@@ -110,77 +110,80 @@ SILKY_MAX_RESPONSE_BODY_SIZE = 1024
|
||||
SILKY_META = True # Record metadata about requests
|
||||
|
||||
# NPlusOne configuration
|
||||
NPLUSONE_LOGGER = logging.getLogger('nplusone')
|
||||
NPLUSONE_LOGGER = logging.getLogger("nplusone")
|
||||
NPLUSONE_LOG_LEVEL = logging.WARN
|
||||
|
||||
# Enhanced development logging
|
||||
LOGGING = {
|
||||
'version': 1,
|
||||
'disable_existing_loggers': False,
|
||||
'formatters': {
|
||||
'verbose': {
|
||||
'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',
|
||||
'style': '{',
|
||||
"version": 1,
|
||||
"disable_existing_loggers": False,
|
||||
"formatters": {
|
||||
"verbose": {
|
||||
"format": "{levelname} {asctime} {module} {process:d} {thread:d} {message}",
|
||||
"style": "{",
|
||||
},
|
||||
'json': {
|
||||
'()': 'pythonjsonlogger.jsonlogger.JsonFormatter',
|
||||
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
|
||||
"json": {
|
||||
"()": "pythonjsonlogger.jsonlogger.JsonFormatter",
|
||||
"format": (
|
||||
"%(levelname)s %(asctime)s %(module)s %(process)d "
|
||||
"%(thread)d %(message)s"
|
||||
),
|
||||
},
|
||||
},
|
||||
'handlers': {
|
||||
'console': {
|
||||
'class': 'logging.StreamHandler',
|
||||
'formatter': 'verbose',
|
||||
"handlers": {
|
||||
"console": {
|
||||
"class": "logging.StreamHandler",
|
||||
"formatter": "verbose",
|
||||
},
|
||||
'file': {
|
||||
'class': 'logging.handlers.RotatingFileHandler',
|
||||
'filename': BASE_DIR / 'logs' / 'thrillwiki.log',
|
||||
'maxBytes': 1024*1024*10, # 10MB
|
||||
'backupCount': 5,
|
||||
'formatter': 'json',
|
||||
"file": {
|
||||
"class": "logging.handlers.RotatingFileHandler",
|
||||
"filename": BASE_DIR / "logs" / "thrillwiki.log",
|
||||
"maxBytes": 1024 * 1024 * 10, # 10MB
|
||||
"backupCount": 5,
|
||||
"formatter": "json",
|
||||
},
|
||||
'performance': {
|
||||
'class': 'logging.handlers.RotatingFileHandler',
|
||||
'filename': BASE_DIR / 'logs' / 'performance.log',
|
||||
'maxBytes': 1024*1024*10, # 10MB
|
||||
'backupCount': 5,
|
||||
'formatter': 'json',
|
||||
"performance": {
|
||||
"class": "logging.handlers.RotatingFileHandler",
|
||||
"filename": BASE_DIR / "logs" / "performance.log",
|
||||
"maxBytes": 1024 * 1024 * 10, # 10MB
|
||||
"backupCount": 5,
|
||||
"formatter": "json",
|
||||
},
|
||||
},
|
||||
'root': {
|
||||
'level': 'INFO',
|
||||
'handlers': ['console'],
|
||||
"root": {
|
||||
"level": "INFO",
|
||||
"handlers": ["console"],
|
||||
},
|
||||
'loggers': {
|
||||
'django': {
|
||||
'handlers': ['file'],
|
||||
'level': 'INFO',
|
||||
'propagate': False,
|
||||
"loggers": {
|
||||
"django": {
|
||||
"handlers": ["file"],
|
||||
"level": "INFO",
|
||||
"propagate": False,
|
||||
},
|
||||
'django.db.backends': {
|
||||
'handlers': ['console'],
|
||||
'level': 'DEBUG',
|
||||
'propagate': False,
|
||||
"django.db.backends": {
|
||||
"handlers": ["console"],
|
||||
"level": "DEBUG",
|
||||
"propagate": False,
|
||||
},
|
||||
'thrillwiki': {
|
||||
'handlers': ['console', 'file'],
|
||||
'level': 'DEBUG',
|
||||
'propagate': False,
|
||||
"thrillwiki": {
|
||||
"handlers": ["console", "file"],
|
||||
"level": "DEBUG",
|
||||
"propagate": False,
|
||||
},
|
||||
'performance': {
|
||||
'handlers': ['performance'],
|
||||
'level': 'INFO',
|
||||
'propagate': False,
|
||||
"performance": {
|
||||
"handlers": ["performance"],
|
||||
"level": "INFO",
|
||||
"propagate": False,
|
||||
},
|
||||
'query_optimization': {
|
||||
'handlers': ['console', 'file'],
|
||||
'level': 'WARNING',
|
||||
'propagate': False,
|
||||
"query_optimization": {
|
||||
"handlers": ["console", "file"],
|
||||
"level": "WARNING",
|
||||
"propagate": False,
|
||||
},
|
||||
'nplusone': {
|
||||
'handlers': ['console'],
|
||||
'level': 'WARNING',
|
||||
'propagate': False,
|
||||
"nplusone": {
|
||||
"handlers": ["console"],
|
||||
"level": "WARNING",
|
||||
"propagate": False,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -4,25 +4,25 @@ Production settings for thrillwiki project.
|
||||
|
||||
# Import the module and use its members, e.g., base.BASE_DIR, base***REMOVED***
|
||||
from . import base
|
||||
|
||||
# Import the module and use its members, e.g., database.DATABASES
|
||||
from ..settings import database
|
||||
|
||||
# Import the module and use its members, e.g., email.EMAIL_HOST
|
||||
from ..settings import email
|
||||
|
||||
# Import the module and use its members, e.g., security.SECURE_HSTS_SECONDS
|
||||
from ..settings import security
|
||||
|
||||
# Import the module and use its members, e.g., email.EMAIL_HOST
|
||||
from ..settings import email
|
||||
|
||||
# Import the module and use its members, e.g., security.SECURE_HSTS_SECONDS
|
||||
from ..settings import security
|
||||
|
||||
# Production settings
|
||||
DEBUG = False
|
||||
|
||||
# Allowed hosts must be explicitly set in production
|
||||
ALLOWED_HOSTS = base.env.list('ALLOWED_HOSTS')
|
||||
ALLOWED_HOSTS = base.env.list("ALLOWED_HOSTS")
|
||||
|
||||
# CSRF trusted origins for production
|
||||
CSRF_TRUSTED_ORIGINS = base.env.list('CSRF_TRUSTED_ORIGINS')
|
||||
CSRF_TRUSTED_ORIGINS = base.env.list("CSRF_TRUSTED_ORIGINS")
|
||||
|
||||
# Security settings for production
|
||||
SECURE_SSL_REDIRECT = True
|
||||
@@ -34,70 +34,70 @@ SECURE_HSTS_PRELOAD = True
|
||||
|
||||
# Production logging
|
||||
LOGGING = {
|
||||
'version': 1,
|
||||
'disable_existing_loggers': False,
|
||||
'formatters': {
|
||||
'verbose': {
|
||||
'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',
|
||||
'style': '{',
|
||||
"version": 1,
|
||||
"disable_existing_loggers": False,
|
||||
"formatters": {
|
||||
"verbose": {
|
||||
"format": "{levelname} {asctime} {module} {process:d} {thread:d} {message}",
|
||||
"style": "{",
|
||||
},
|
||||
'simple': {
|
||||
'format': '{levelname} {message}',
|
||||
'style': '{',
|
||||
"simple": {
|
||||
"format": "{levelname} {message}",
|
||||
"style": "{",
|
||||
},
|
||||
},
|
||||
'handlers': {
|
||||
'file': {
|
||||
'level': 'INFO',
|
||||
'class': 'logging.handlers.RotatingFileHandler',
|
||||
'filename': base.BASE_DIR / 'logs' / 'django.log',
|
||||
'maxBytes': 1024*1024*15, # 15MB
|
||||
'backupCount': 10,
|
||||
'formatter': 'verbose',
|
||||
"handlers": {
|
||||
"file": {
|
||||
"level": "INFO",
|
||||
"class": "logging.handlers.RotatingFileHandler",
|
||||
"filename": base.BASE_DIR / "logs" / "django.log",
|
||||
"maxBytes": 1024 * 1024 * 15, # 15MB
|
||||
"backupCount": 10,
|
||||
"formatter": "verbose",
|
||||
},
|
||||
'error_file': {
|
||||
'level': 'ERROR',
|
||||
'class': 'logging.handlers.RotatingFileHandler',
|
||||
'filename': base.BASE_DIR / 'logs' / 'django_error.log',
|
||||
'maxBytes': 1024*1024*15, # 15MB
|
||||
'backupCount': 10,
|
||||
'formatter': 'verbose',
|
||||
"error_file": {
|
||||
"level": "ERROR",
|
||||
"class": "logging.handlers.RotatingFileHandler",
|
||||
"filename": base.BASE_DIR / "logs" / "django_error.log",
|
||||
"maxBytes": 1024 * 1024 * 15, # 15MB
|
||||
"backupCount": 10,
|
||||
"formatter": "verbose",
|
||||
},
|
||||
},
|
||||
'root': {
|
||||
'handlers': ['file'],
|
||||
'level': 'INFO',
|
||||
"root": {
|
||||
"handlers": ["file"],
|
||||
"level": "INFO",
|
||||
},
|
||||
'loggers': {
|
||||
'django': {
|
||||
'handlers': ['file', 'error_file'],
|
||||
'level': 'INFO',
|
||||
'propagate': False,
|
||||
"loggers": {
|
||||
"django": {
|
||||
"handlers": ["file", "error_file"],
|
||||
"level": "INFO",
|
||||
"propagate": False,
|
||||
},
|
||||
'thrillwiki': {
|
||||
'handlers': ['file', 'error_file'],
|
||||
'level': 'INFO',
|
||||
'propagate': False,
|
||||
"thrillwiki": {
|
||||
"handlers": ["file", "error_file"],
|
||||
"level": "INFO",
|
||||
"propagate": False,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
# Static files collection for production
|
||||
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
|
||||
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
|
||||
|
||||
# Cache settings for production (Redis recommended)
|
||||
redis_url = base.env.str('REDIS_URL', default=None)
|
||||
redis_url = base.env.str("REDIS_URL", default=None)
|
||||
if redis_url:
|
||||
CACHES = {
|
||||
'default': {
|
||||
'BACKEND': 'django_redis.cache.RedisCache',
|
||||
'LOCATION': redis_url,
|
||||
'OPTIONS': {
|
||||
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
|
||||
}
|
||||
"default": {
|
||||
"BACKEND": "django_redis.cache.RedisCache",
|
||||
"LOCATION": redis_url,
|
||||
"OPTIONS": {
|
||||
"CLIENT_CLASS": "django_redis.client.DefaultClient",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
# Use Redis for sessions in production
|
||||
SESSION_ENGINE = 'django.contrib.sessions.backends.cache'
|
||||
SESSION_CACHE_ALIAS = 'default'
|
||||
SESSION_ENGINE = "django.contrib.sessions.backends.cache"
|
||||
SESSION_CACHE_ALIAS = "default"
|
||||
|
||||
@@ -9,17 +9,17 @@ DEBUG = False
|
||||
|
||||
# Use in-memory database for faster tests
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.contrib.gis.db.backends.spatialite',
|
||||
'NAME': ':memory:',
|
||||
"default": {
|
||||
"ENGINE": "django.contrib.gis.db.backends.spatialite",
|
||||
"NAME": ":memory:",
|
||||
}
|
||||
}
|
||||
|
||||
# Use in-memory cache for tests
|
||||
CACHES = {
|
||||
'default': {
|
||||
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
|
||||
'LOCATION': 'test-cache',
|
||||
"default": {
|
||||
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
|
||||
"LOCATION": "test-cache",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,28 +37,28 @@ class DisableMigrations:
|
||||
MIGRATION_MODULES = DisableMigrations()
|
||||
|
||||
# Email backend for tests
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend'
|
||||
EMAIL_BACKEND = "django.core.mail.backends.locmem.EmailBackend"
|
||||
|
||||
# Password hashers for faster tests
|
||||
PASSWORD_HASHERS = [
|
||||
'django.contrib.auth.hashers.MD5PasswordHasher',
|
||||
"django.contrib.auth.hashers.MD5PasswordHasher",
|
||||
]
|
||||
|
||||
# Disable logging during tests
|
||||
LOGGING_CONFIG = None
|
||||
|
||||
# Media files for tests
|
||||
MEDIA_ROOT = BASE_DIR / 'test_media'
|
||||
MEDIA_ROOT = BASE_DIR / "test_media"
|
||||
|
||||
# Static files for tests
|
||||
STATIC_ROOT = BASE_DIR / 'test_static'
|
||||
STATIC_ROOT = BASE_DIR / "test_static"
|
||||
|
||||
# Disable Turnstile for tests
|
||||
TURNSTILE_SITE_KEY = 'test-key'
|
||||
TURNSTILE_SECRET_KEY = 'test-secret'
|
||||
TURNSTILE_SITE_KEY = "test-key"
|
||||
TURNSTILE_SECRET_KEY = "test-secret"
|
||||
|
||||
# Test-specific middleware (remove caching middleware)
|
||||
MIDDLEWARE = [m for m in MIDDLEWARE if 'cache' not in m.lower()]
|
||||
MIDDLEWARE = [m for m in MIDDLEWARE if "cache" not in m.lower()]
|
||||
|
||||
# Celery settings for tests (if Celery is used)
|
||||
CELERY_TASK_ALWAYS_EAGER = True
|
||||
|
||||
@@ -2,24 +2,22 @@
|
||||
Test Django settings for thrillwiki accounts app.
|
||||
"""
|
||||
|
||||
from .base import *
|
||||
|
||||
# Use in-memory database for tests
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.contrib.gis.db.backends.postgis',
|
||||
'NAME': 'test_db',
|
||||
"default": {
|
||||
"ENGINE": "django.contrib.gis.db.backends.postgis",
|
||||
"NAME": "test_db",
|
||||
}
|
||||
}
|
||||
|
||||
# Use a faster password hasher for tests
|
||||
PASSWORD_HASHERS = [
|
||||
'django.contrib.auth.hashers.MD5PasswordHasher',
|
||||
"django.contrib.auth.hashers.MD5PasswordHasher",
|
||||
]
|
||||
|
||||
# Disable whitenoise for tests
|
||||
WHITENOISE_AUTOREFRESH = True
|
||||
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
|
||||
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
|
||||
|
||||
INSTALLED_APPS = [
|
||||
"django.contrib.admin",
|
||||
@@ -42,5 +40,5 @@ INSTALLED_APPS = [
|
||||
"media.apps.MediaConfig",
|
||||
]
|
||||
|
||||
GDAL_LIBRARY_PATH = '/opt/homebrew/lib/libgdal.dylib'
|
||||
GEOS_LIBRARY_PATH = '/opt/homebrew/lib/libgeos_c.dylib'
|
||||
GDAL_LIBRARY_PATH = "/opt/homebrew/lib/libgdal.dylib"
|
||||
GEOS_LIBRARY_PATH = "/opt/homebrew/lib/libgeos_c.dylib"
|
||||
|
||||
Reference in New Issue
Block a user