first commit
This commit is contained in:
260
core/settings.py
Normal file
260
core/settings.py
Normal file
@@ -0,0 +1,260 @@
|
||||
"""
|
||||
Django settings for core project.
|
||||
|
||||
Generated by 'django-admin startproject' using Django 6.0.3.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/6.0/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/6.0/ref/settings/
|
||||
"""
|
||||
|
||||
import os
|
||||
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
|
||||
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/6.0/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = config('SECRET_KEY', default='django-insecure-3rtts!rrr*3om)-um$5go^(-a@a2q#7he!+j&9caava+^%rw5n')
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = config('DEBUG', default=True, cast=bool)
|
||||
|
||||
ALLOWED_HOSTS = config('DJANGO_ALLOWED_HOSTS', default='localhost,127.0.0.1', cast=lambda v: [s.strip() for s in v.split(',')])
|
||||
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
# 3. Party
|
||||
'rest_framework',
|
||||
'djoser',
|
||||
'drf_spectacular',
|
||||
'drf_spectacular_sidecar',
|
||||
'django_celery_results',
|
||||
'django_celery_beat',
|
||||
# My App
|
||||
'accounts',
|
||||
'namecreate',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'accounts.middleware.AccountExpirationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'core.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [BASE_DIR / 'templates']
|
||||
,
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'core.wsgi.application'
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/6.0/ref/settings/#databases
|
||||
|
||||
USE_POSTGRES = config('USE_POSTGRES', default=False, cast=bool)
|
||||
|
||||
if USE_POSTGRES:
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.postgresql',
|
||||
'NAME': config('POSTGRES_DB', default='beyhan_blog'),
|
||||
'USER': config('POSTGRES_USER', default='beyhan_blog'),
|
||||
'PASSWORD': config('POSTGRES_PASSWORD', default='1923btO**'),
|
||||
'HOST': config('POSTGRES_HOST', default='212.64.215.243'),
|
||||
'PORT': config('POSTGRES_PORT', default='5432'),
|
||||
'OPTIONS': {
|
||||
'options': '-c search_path=public'
|
||||
},
|
||||
}
|
||||
}
|
||||
else:
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': BASE_DIR / 'db.sqlite3',
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/6.0/ref/settings/#auth-password-validators
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/6.0/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
TIME_ZONE = 'UTC'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/6.0/howto/static-files/
|
||||
|
||||
STATIC_URL = 'static/'
|
||||
STATIC_ROOT = BASE_DIR / 'staticfiles'
|
||||
STATICFILES_DIRS = [
|
||||
BASE_DIR / 'static',
|
||||
]
|
||||
# Media files (User uploaded files)
|
||||
MEDIA_URL = 'media/'
|
||||
MEDIA_ROOT = BASE_DIR / 'media'
|
||||
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
|
||||
|
||||
REST_FRAMEWORK = {
|
||||
'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
|
||||
'DEFAULT_AUTHENTICATION_CLASSES': (
|
||||
'rest_framework_simplejwt.authentication.JWTAuthentication',
|
||||
),
|
||||
}
|
||||
|
||||
SPECTACULAR_SETTINGS = {
|
||||
'TITLE': 'Your Project API',
|
||||
'DESCRIPTION': 'Your project description',
|
||||
'VERSION': '1.0.0',
|
||||
'SERVE_INCLUDE_SCHEMA': False,
|
||||
'SWAGGER_UI_DIST': 'SIDECAR', # shorthand to use the sidecar instead
|
||||
'SWAGGER_UI_FAVICON_HREF': 'SIDECAR',
|
||||
'REDOC_DIST': 'SIDECAR',
|
||||
'SWAGGER_UI_SETTINGS': {
|
||||
'persistAuthorization': True,
|
||||
},
|
||||
}
|
||||
|
||||
DJOSER = {
|
||||
'LOGIN_FIELD': 'email',
|
||||
'USER_ID_FIELD': 'id',
|
||||
'USER_CREATE_PASSWORD_RETYPE': True,
|
||||
'SERIALIZERS': {
|
||||
'user_create': 'accounts.serializers.CustomUserCreateSerializer',
|
||||
'current_user': 'accounts.serializers.CustomUserSerializer',
|
||||
'user': 'accounts.serializers.CustomUserSerializer',
|
||||
},
|
||||
}
|
||||
|
||||
SIMPLE_JWT = {
|
||||
'AUTH_HEADER_TYPES': ('Bearer',),
|
||||
}
|
||||
|
||||
# ==============================================================================
|
||||
# EMAIL CONFIGURATION
|
||||
# ==============================================================================
|
||||
EMAIL_BACKEND = config('EMAIL_BACKEND', default='django.core.mail.backends.console.EmailBackend')
|
||||
EMAIL_HOST = config('EMAIL_HOST', default='localhost')
|
||||
EMAIL_PORT = config('EMAIL_PORT', default=1025, cast=int)
|
||||
EMAIL_HOST_USER = config('EMAIL_HOST_USER', default='')
|
||||
EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD', default='')
|
||||
EMAIL_USE_TLS = config('EMAIL_USE_TLS', default=False, cast=bool)
|
||||
EMAIL_USE_SSL = config('EMAIL_USE_SSL', default=False, cast=bool)
|
||||
DEFAULT_FROM_EMAIL = config('DEFAULT_FROM_EMAIL', default='noreply@localhost')
|
||||
|
||||
# ==============================================================================
|
||||
# CELERY & REDIS CONFIGURATION
|
||||
# ==============================================================================
|
||||
CELERY_BROKER_URL = config('CELERY_BROKER_URL', default='redis://127.0.0.1:6379/5')
|
||||
CELERY_RESULT_BACKEND = 'django-db'
|
||||
CELERY_ACCEPT_CONTENT = ['json']
|
||||
CELERY_TASK_SERIALIZER = 'json'
|
||||
CELERY_RESULT_SERIALIZER = 'json'
|
||||
CELERY_TIMEZONE = TIME_ZONE
|
||||
CELERY_BEAT_SCHEDULER = 'django_celery_beat.schedulers:DatabaseScheduler'
|
||||
CELERY_BEAT_SCHEDULE = {
|
||||
'deactivate-expired-users-daily': {
|
||||
'task': 'accounts.tasks.deactivate_expired_users_task',
|
||||
'schedule': 60 * 60 * 24,
|
||||
},
|
||||
}
|
||||
|
||||
CACHES = {
|
||||
'default': {
|
||||
'BACKEND': 'django_redis.cache.RedisCache',
|
||||
'LOCATION': config('CELERY_BROKER_URL', default='redis://127.0.0.1:6379/5'),
|
||||
'OPTIONS': {
|
||||
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
|
||||
},
|
||||
'KEY_PREFIX': 'insta',
|
||||
'TIMEOUT': 300, # 5 dakika
|
||||
}
|
||||
}
|
||||
|
||||
# ==============================================================================
|
||||
# CUSTOM USER MODEL
|
||||
# ==============================================================================
|
||||
AUTH_USER_MODEL = 'accounts.CustomUser'
|
||||
|
||||
# ==============================================================================
|
||||
# GO SERVICE CONFIGURATION
|
||||
# ==============================================================================
|
||||
GO_SERVICE_URL = config('GO_SERVICE_URL', default=None)
|
||||
|
||||
# ==============================================================================
|
||||
# LLM GENERATOR CONFIGURATION
|
||||
# ==============================================================================
|
||||
# Ollama icin ornek: http://127.0.0.1:11434/api/chat
|
||||
# OpenAI uyumlu endpoint icin ornek: https://api.openai.com/v1/chat/completions
|
||||
LLM_API_URL = config('LLM_API_URL', default='http://127.0.0.1:11434/api/chat')
|
||||
LLM_MODEL = config('LLM_MODEL', default='llama3.1:8b')
|
||||
LLM_API_KEY = config('LLM_API_KEY', default='')
|
||||
LLM_TIMEOUT = config('LLM_TIMEOUT', default=30, cast=int)
|
||||
|
||||
# ==============================================================================
|
||||
# USERNAME REGENERATION SUFFIX RANGE
|
||||
# ==============================================================================
|
||||
# Yeniden uretimde rastgele sonek bu araliktan secilir.
|
||||
# USERNAME_SUFFIX_MIN ve USERNAME_SUFFIX_MAX .env ile degistirilebilir.
|
||||
USERNAME_SUFFIX_MIN = config('USERNAME_SUFFIX_MIN', default=2, cast=int)
|
||||
USERNAME_SUFFIX_MAX = config('USERNAME_SUFFIX_MAX', default=999, cast=int)
|
||||
Reference in New Issue
Block a user