Bishall10/ipo
0
1"""2Django settings for ipo_backend project.3 4Generated by 'django-admin startproject' using Django 4.2.5 6For more information on this file, see7https://docs.djangoproject.com/en/4.2/topics/settings/8 9For the full list of settings and their values, see10https://docs.djangoproject.com/en/4.2/ref/settings/11"""12 13from pathlib import Path14 15# Build paths inside the project like this: BASE_DIR / 'subdir'.16BASE_DIR = Path(__file__).resolve().parent.parent17 18 19# Quick-start development settings - unsuitable for production20# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/21 22# SECURITY WARNING: keep the secret key used in production secret!23SECRET_KEY = 'django-insecure-azjx#96-4kp94gos^&#)n=1*p*u6lkqwgkaqt+c@7hy*$tszlg'24 25# SECURITY WARNING: don't run with debug turned on in production!26DEBUG = True27 28ALLOWED_HOSTS = [29 'ipoautomation.vercel.app',30 '.vercel.app',31 'bishall10-ipo.hf.space',32 '.hf.space',33 'localhost',34 '127.0.0.1',35 '*',36]37 38# Production settings for Hugging Face / Proxies39SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')40USE_X_FORWARDED_HOST = True41USE_X_FORWARDED_PORT = True42X_FRAME_OPTIONS = 'ALLOWALL'43CSRF_TRUSTED_ORIGINS = [44 'https://*.hf.space',45 'https://*.huggingface.co',46]47 48 49# Application definition50 51INSTALLED_APPS = [52 'django.contrib.admin',53 'django.contrib.auth',54 'django.contrib.contenttypes',55 'django.contrib.sessions',56 'django.contrib.messages',57 'django.contrib.staticfiles',58 'rest_framework.authtoken',59 'rest_framework',60 'corsheaders',61 'django_celery_beat',62 'automation',63]64 65MIDDLEWARE = [66 'django.middleware.security.SecurityMiddleware',67 'whitenoise.middleware.WhiteNoiseMiddleware',68 'corsheaders.middleware.CorsMiddleware',69 'django.contrib.sessions.middleware.SessionMiddleware',70 'django.middleware.common.CommonMiddleware',71 'django.middleware.csrf.CsrfViewMiddleware',72 'django.contrib.auth.middleware.AuthenticationMiddleware',73 'django.contrib.messages.middleware.MessageMiddleware',74 'django.middleware.clickjacking.XFrameOptionsMiddleware',75]76 77ROOT_URLCONF = 'config.urls'78 79TEMPLATES = [80 {81 'BACKEND': 'django.template.backends.django.DjangoTemplates',82 'DIRS': [],83 'APP_DIRS': True,84 'OPTIONS': {85 'context_processors': [86 'django.template.context_processors.debug',87 'django.template.context_processors.request',88 'django.contrib.auth.context_processors.auth',89 'django.contrib.messages.context_processors.messages',90 ],91 },92 },93]94 95WSGI_APPLICATION = 'config.wsgi.application'96 97 98import os99import dj_database_url100 101# Database102# https://docs.djangoproject.com/en/4.2/ref/settings/#databases103 104# Use DATABASE_URL environment variable if it exists (for Neon/PostgreSQL)105# Fallback to local SQLite for development106DATABASES = {107 'default': dj_database_url.config(108 default=f'sqlite:///{BASE_DIR / "db.sqlite3"}',109 conn_max_age=30,110 ssl_require=True if os.environ.get('DATABASE_URL') else False111 )112}113 114# If we are using local SQLite, we don't need ssl_require115if not os.environ.get('DATABASE_URL'):116 DATABASES['default']['OPTIONS'] = {}117 118 119# Password validation120# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators121 122AUTH_PASSWORD_VALIDATORS = [123 {124 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',125 },126 {127 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',128 },129 {130 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',131 },132 {133 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',134 },135]136 137 138# Internationalization139# https://docs.djangoproject.com/en/4.2/topics/i18n/140 141LANGUAGE_CODE = 'en-us'142 143TIME_ZONE = 'UTC'144 145USE_I18N = True146 147USE_TZ = True148 149 150# Static files (CSS, JavaScript, Images)151# https://docs.djangoproject.com/en/4.2/howto/static-files/152 153STATIC_URL = 'static/'154STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')155STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'156 157# Default primary key field type158# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field159 160DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'161 162CORS_ALLOW_ALL_ORIGINS = True163 164# Celery Configuration165CELERY_BROKER_URL = os.environ.get('CELERY_BROKER_URL', '')166CELERY_RESULT_BACKEND = os.environ.get('CELERY_RESULT_BACKEND', '')167 168# If no broker is provided (common on HF Spaces), run tasks synchronously to avoid hangs169if not CELERY_BROKER_URL:170 CELERY_TASK_ALWAYS_EAGER = True171 print("Warning: CELERY_BROKER_URL not set. Running tasks in EAGER mode (synchronous).")172 173CELERY_ACCEPT_CONTENT = ['json']174CELERY_TASK_SERIALIZER = 'json'175CELERY_RESULT_SERIALIZER = 'json'176CELERY_TIMEZONE = 'UTC'177CELERY_BEAT_SCHEDULER = 'django_celery_beat.schedulers:DatabaseScheduler'178 