265 lines
7.8 KiB
Python
265 lines
7.8 KiB
Python
"""
|
|
Django settings for ArtaSystem project.
|
|
|
|
Generated by 'django-admin startproject' using Django 3.2.14.
|
|
|
|
For more information on this file, see
|
|
https://docs.djangoproject.com/en/3.2/topics/settings/
|
|
|
|
For the full list of settings and their values, see
|
|
https://docs.djangoproject.com/en/3.2/ref/settings/
|
|
"""
|
|
import socket
|
|
from pathlib import Path
|
|
import os
|
|
from dotenv import load_dotenv
|
|
|
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
|
|
|
loc_ip = socket.gethostbyname(socket.gethostname())
|
|
|
|
|
|
if not os.getenv("RUNNING_IN_DOCKER"):
|
|
dotenv_path = BASE_DIR / ".env.local"
|
|
load_dotenv(dotenv_path)
|
|
|
|
SECRET_KEY = os.environ.get("SECRET_KEY")
|
|
|
|
DEBUG = os.environ.get("DEBUG")
|
|
|
|
ALLOWED_HOSTS = os.environ.get("ALLOWED_HOSTS").split(',')
|
|
# Application definition
|
|
|
|
INSTALLED_APPS = [
|
|
'django.contrib.auth',
|
|
'django.contrib.contenttypes',
|
|
'django.contrib.messages',
|
|
'django.contrib.staticfiles',
|
|
'django.contrib.admin',
|
|
'django.contrib.sessions',
|
|
'oauth2_provider',
|
|
'rest_framework',
|
|
'django_filters',
|
|
'corsheaders',
|
|
'Authentication.apps.AuthenticationConfig',
|
|
'Notification.apps.NotificationConfig',
|
|
'Core.apps.CoreConfig',
|
|
'Wallet.apps.WalletConfig',
|
|
]
|
|
|
|
MIDDLEWARE = [
|
|
'django.middleware.security.SecurityMiddleware',
|
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
|
'corsheaders.middleware.CorsMiddleware',
|
|
'django.middleware.common.CommonMiddleware',
|
|
'django.middleware.csrf.CsrfViewMiddleware',
|
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
|
'oauth2_provider.middleware.OAuth2TokenMiddleware',
|
|
'django.contrib.messages.middleware.MessageMiddleware',
|
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
|
]
|
|
|
|
ROOT_URLCONF = 'ArtaSystem.urls'
|
|
|
|
TEMPLATES = [
|
|
{
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
|
'DIRS': [BASE_DIR / 'templates'],
|
|
'APP_DIRS': True,
|
|
'OPTIONS': {
|
|
'context_processors': [
|
|
'django.template.context_processors.debug',
|
|
'django.template.context_processors.request',
|
|
'django.contrib.auth.context_processors.auth',
|
|
'django.contrib.messages.context_processors.messages',
|
|
],
|
|
},
|
|
},
|
|
]
|
|
|
|
WSGI_APPLICATION = 'ArtaSystem.wsgi.application'
|
|
|
|
# Database
|
|
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
|
|
|
|
DATABASES = {
|
|
'default': {
|
|
'ENGINE': 'django.db.backends.postgresql_psycopg2',
|
|
'NAME': os.environ.get("DB_NAME"),
|
|
'USER': os.environ.get("DB_USER"),
|
|
'PASSWORD': os.environ.get("DB_PASSWORD"),
|
|
'HOST': os.environ.get("DB_HOST"),
|
|
'PORT': os.environ.get("DB_PORT"),
|
|
}
|
|
|
|
}
|
|
# DATABASES['default'] = DATABASES['Auth_db']
|
|
# DATABASE_ROUTERS = ['ArtaSystem.dbrouter.MyDatabaseRouter']
|
|
|
|
REST_FRAMEWORK = {
|
|
'DEFAULT_AUTHENTICATION_CLASSES': (
|
|
'rest_framework.authentication.BasicAuthentication',
|
|
# 'rest_framework.authentication.SessionAuthentication',
|
|
'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
|
|
'rest_framework.authentication.TokenAuthentication',
|
|
),
|
|
'DEFAULT_PERMISSION_CLASSES': (
|
|
'rest_framework.permissions.IsAuthenticated',
|
|
),
|
|
'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend']
|
|
}
|
|
|
|
OAUTH2_PROVIDER = {
|
|
# other OAUTH2 settings
|
|
'REFRESH_TOKEN_EXPIRE_SECONDS': 360000,
|
|
'OAUTH2_BACKEND_CLASS': 'oauth2_provider.oauth2_backends.JSONOAuthLibCore',
|
|
'SCOPES': {'read': 'Read scope', 'write': 'Write scope', 'groups': 'Access to your groups'},
|
|
'ACCESS_TOKEN_EXPIRE_SECONDS': 360000
|
|
}
|
|
|
|
AUTHENTICATION_BACKENDS = [
|
|
'oauth2_provider.backends.OAuth2Backend',
|
|
# Uncomment following if you want to access the admin
|
|
'django.contrib.auth.backends.ModelBackend',
|
|
]
|
|
|
|
# CACHES = {
|
|
# "default": {
|
|
# "BACKEND": "django_redis.cache.RedisCache",
|
|
# "LOCATION": "redis://:ydnW4hwzuDRYcTX3FWCHgQ1f@apo.liara.cloud:33740/0",
|
|
# "OPTIONS": {
|
|
# "CLIENT_CLASS": "django_redis.client.DefaultClient",
|
|
#
|
|
# },
|
|
# "KEY_PREFIX": "You have successfully set up a key-value pair!"
|
|
# }
|
|
# }
|
|
|
|
|
|
|
|
|
|
CACHES = {
|
|
"default": {
|
|
"BACKEND": "django_redis.cache.RedisCache",
|
|
"LOCATION":"redis://default:wHM2fSW8EXtsoTjHxLZyyaRsD8IJm4tOU108252rizfmUYrp709PuCLUhr9mmYDK@31.7.78.133:14353/0",
|
|
"OPTIONS": {
|
|
"CLIENT_CLASS": "django_redis.client.DefaultClient",
|
|
},
|
|
"KEY_PREFIX": "You have successfully set up a key-value pair!"
|
|
}
|
|
}
|
|
|
|
# Password validation
|
|
# https://docs.djangoproject.com/en/3.2/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/3.2/topics/i18n/
|
|
|
|
LANGUAGE_CODE = 'en-us'
|
|
|
|
# TIME_ZONE = 'UTC'
|
|
TIME_ZONE = 'Asia/Tehran'
|
|
|
|
USE_I18N = True
|
|
|
|
USE_L10N = False
|
|
|
|
USE_TZ = False
|
|
|
|
DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S'
|
|
|
|
# Cache time to live is 2 minutes.
|
|
CACHE_TTL = 60 * 2
|
|
# Static files (CSS, JavaScript, Images)
|
|
# https://docs.djangoproject.com/en/3.2/howto/static-files/
|
|
|
|
STATIC_URL = '/static/'
|
|
STATIC_ROOT = BASE_DIR / 'static'
|
|
|
|
# Default primary key field type
|
|
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
|
|
|
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
|
DATA_UPLOAD_MAX_MEMORY_SIZE = 50242880
|
|
|
|
# CELERY STUFF
|
|
BROKER_URL = 'redis://localhost:6379'
|
|
CELERY_RESULT_BACKEND = 'redis://localhost:6379'
|
|
CELERY_ACCEPT_CONTENT = ['application/json']
|
|
CELERY_TASK_SERIALIZER = 'json'
|
|
CELERY_RESULT_SERIALIZER = 'json'
|
|
CELERY_TIMEZONE = 'Asia/Tehran'
|
|
|
|
if DEBUG:
|
|
MIDDLEWARE += [
|
|
'debug_toolbar.middleware.DebugToolbarMiddleware',
|
|
]
|
|
INSTALLED_APPS += [
|
|
'debug_toolbar',
|
|
# 'oauth2_provider',
|
|
# 'rest_framework',
|
|
# 'corsheaders'
|
|
]
|
|
INTERNAL_IPS = [
|
|
# ...
|
|
"51.89.107.194",
|
|
# "127.0.0.1",
|
|
|
|
# ...
|
|
]
|
|
|
|
hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
|
|
INTERNAL_IPS += [".".join(ip.split(".")[:-1] + ["1"]) for ip in ips]
|
|
|
|
DEBUG_TOOLBAR_PANELS = [
|
|
'debug_toolbar.panels.history.HistoryPanel',
|
|
'debug_toolbar.panels.versions.VersionsPanel',
|
|
'debug_toolbar.panels.timer.TimerPanel',
|
|
'debug_toolbar.panels.settings.SettingsPanel',
|
|
'debug_toolbar.panels.headers.HeadersPanel',
|
|
'debug_toolbar.panels.request.RequestPanel',
|
|
'debug_toolbar.panels.sql.SQLPanel',
|
|
'debug_toolbar.panels.staticfiles.StaticFilesPanel',
|
|
'debug_toolbar.panels.templates.TemplatesPanel',
|
|
'debug_toolbar.panels.cache.CachePanel',
|
|
'debug_toolbar.panels.signals.SignalsPanel',
|
|
'debug_toolbar.panels.logging.LoggingPanel',
|
|
'debug_toolbar.panels.redirects.RedirectsPanel',
|
|
'debug_toolbar.panels.profiling.ProfilingPanel',
|
|
]
|
|
|
|
# this is the main reason for not showing up the toolbar
|
|
import mimetypes
|
|
|
|
mimetypes.add_type("application/javascript", ".js", True)
|
|
|
|
DEBUG_TOOLBAR_CONFIG = {
|
|
'INTERCEPT_REDIRECTS': False,
|
|
}
|
|
|
|
|
|
CORS_ORIGIN_ALLOW_ALL = os.environ.get("CORS_ORIGIN_ALLOW_ALL", "False").lower() == "true"
|
|
CORS_ORIGIN_WHITELIST = os.environ.get("CORS_ORIGIN_WHITELIST").split(',')
|
|
|
|
CORS_ALLOWED_ORIGINS = os.environ.get("CORS_ORIGIN_WHITELIST").split(',')
|
|
|
|
SECURE_PROXY_SSL_HEADER = os.environ.get("SECURE_PROXY_SSL_HEADER").split(',')
|
|
SECURE_SSL_REDIRECT = os.environ.get("SECURE_SSL_REDIRECT")
|
|
SESSION_COOKIE_SECURE = os.environ.get("SESSION_COOKIE_SECURE")
|
|
CSRF_COOKIE_SECURE = os.environ.get("CSRF_COOKIE_SECURE")
|