""" Database configuration for thrillwiki project. """ from pathlib import Path from decouple import config # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent.parent DATABASE_URL=config("DATABASE_URL") GDAL_LIBRARY_PATH=config("GDAL_LIBRARY_PATH") GEOS_LIBRARY_PATH=config("GEOS_LIBRARY_PATH") CACHE_URL=config("CACHE_URL") CACHE_MIDDLEWARE_SECONDS=config("CACHE_MIDDLEWARE_SECONDS") CACHE_MIDDLEWARE_KEY_PREFIX=config("CACHE_MIDDLEWARE_KEY_PREFIX") # Database configuration db_url = config("DATABASE_URL") # Parse the database URL and create proper configuration dictionary def parse_db_url(url): # Simple parsing for PostgreSQL URLs if url.startswith('postgres://') or url.startswith('postgis://'): # Format: postgres://username:password@host:port/database # Remove the protocol part if url.startswith('postgis://'): url = url.replace('postgis://', '') elif url.startswith('postgres://'): url = url.replace('postgres://', '') # Split the URL into parts auth_part, rest = url.split('@', 1) host_port, database = rest.split('/', 1) username, password = auth_part.split(':', 1) if ':' in auth_part else (auth_part, '') host, port = host_port.split(':', 1) if ':' in host_port else (host_port, '5432') return { 'ENGINE': 'django.contrib.gis.db.backends.postgis', 'NAME': database, 'USER': username, 'PASSWORD': password, 'HOST': host, 'PORT': port, } # Add support for other database types if needed else: raise ValueError(f"Unsupported database URL format: {url}") # Switch back to PostgreSQL - GeoDjango issues resolved separately DATABASES = { "default": parse_db_url(db_url), } # GeoDjango Settings - Environment specific with fallbacks GDAL_LIBRARY_PATH = config("GDAL_LIBRARY_PATH") GEOS_LIBRARY_PATH = config("GEOS_LIBRARY_PATH") # Cache settings - Use simple local memory cache for development CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', 'LOCATION': 'unique-snowflake', } } CACHE_MIDDLEWARE_SECONDS = config("CACHE_MIDDLEWARE_SECONDS") CACHE_MIDDLEWARE_KEY_PREFIX = config("CACHE_MIDDLEWARE_KEY_PREFIX")