""" Django settings for accounts project. Generated by 'django-admin startproject' using Django 5.0.4. For more information on this file, see https://docs.djangoproject.com/en/5.0/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/5.0/ref/settings/ """ from pathlib import Path from decouple import config, Csv from django.utils.translation import gettext_lazy as _ # 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/5.0/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = 'django-insecure-&+7fi$8#2!r=b6=^i_6surhka6!%uw1a+pz^m0qc!t_#6y=qr2' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = config('DEBUG', default=True, cast=bool) ALLOWED_HOSTS = ['*'] PAGE_SIZE = 20 # Application definition INSTALLED_APPS = [ # django apps 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', # pip installed apps 'drf_spectacular', 'oauth2_provider', 'rest_framework', 'corsheaders', 'crispy_forms', 'crispy_bootstrap5', 'django_filters', # 'jalali_date', 'django_minio_backend.apps.DjangoMinioBackendConfig', # local apps 'apps.core', 'apps.users', 'apps.gooyal_oauth2', ] MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'corsheaders.middleware.CorsMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.locale.LocaleMiddleware', # 'utils.i18n.ForceAdminLanguageMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'utils.exceptions.ErrorMiddleware', ] # Tell Django OAuth Toolkit to use the Gooyal Application model OAUTH2_PROVIDER_ID_TOKEN_MODEL = 'gooyal_oauth2.IDToken' OAUTH2_PROVIDER_APPLICATION_MODEL = 'gooyal_oauth2.Application' OAUTH2_PROVIDER_ACCESS_TOKEN_MODEL = 'gooyal_oauth2.AccessToken' OAUTH2_PROVIDER_GRANT_MODEL = 'gooyal_oauth2.Grant' OAUTH2_PROVIDER_REFRESH_TOKEN_MODEL = 'gooyal_oauth2.RefreshToken' OIDC_RSA_PRIVATE_KEY_FILE_PATH = config('OIDC_RSA_PRIVATE_KEY_FILE_PATH', default=None) if OIDC_RSA_PRIVATE_KEY_FILE_PATH: with open(OIDC_RSA_PRIVATE_KEY_FILE_PATH) as oidc_rsa_private_key_file: OIDC_RSA_PRIVATE_KEY = oidc_rsa_private_key_file.read() else: OIDC_RSA_PRIVATE_KEY = None OAUTH2_PROVIDER = { # this is the list of available scopes 'SCOPES_BACKEND_CLASS': 'apps.gooyal_oauth2.scopes.Scopes', 'SCOPES': {'read': 'Read scope', 'write': 'Write scope', 'groups': 'Access to your groups', 'introspection': 'Introspect token scope'}, 'OAUTH2_VALIDATOR_CLASS': 'apps.gooyal_oauth2.validators.OAuth2Validator', "OIDC_ENABLED": True, "OIDC_RSA_PRIVATE_KEY": OIDC_RSA_PRIVATE_KEY, # Enable and configure RP-Initiated Logout "OIDC_RP_INITIATED_LOGOUT_ENABLED": True, "OIDC_RP_INITIATED_LOGOUT_ALWAYS_PROMPT": True, } # GOOYAL_DYNAMIC_SCOPES RESOURCE_SERVER_REGISTER_SCOPE_URL = None REGISTER_SCOPE_SCOPE = None REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': ( 'oauth2_provider.contrib.rest_framework.OAuth2Authentication', 'rest_framework.authentication.SessionAuthentication', ), 'DEFAULT_PERMISSION_CLASSES': ( 'rest_framework.permissions.IsAuthenticated', ), 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination', 'PAGE_SIZE': PAGE_SIZE, "DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema", # 'DEFAULT_THROTTLE_CLASSES': [ # 'rest_framework.throttling.AnonRateThrottle', # ], 'DEFAULT_THROTTLE_CLASSES': [ 'apps.gooyal_oauth2.throttling.TokenLimitThrottle', # 'rest_framework.throttling.AnonRateThrottle', # 'rest_framework.throttling.UserRateThrottle' ], 'DEFAULT_THROTTLE_RATES': { 'otp_min': '2/min', 'otp_day': '50/day', 'numbered_otp_min': '1/min', 'numbered_otp_day': '10/day', }, 'EXCEPTION_HANDLER': 'utils.exceptions.exception_handler', } SPECTACULAR_SETTINGS = { 'TITLE': 'Accounts', 'DESCRIPTION': 'Accounts API reference', 'VERSION': '1.0.0', 'SERVE_INCLUDE_SCHEMA': False, # OTHER SETTINGS "PARSER_WHITELIST": ["rest_framework.parsers.JSONParser"], } ROOT_URLCONF = 'main.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', ], }, }, ] AUTHENTICATION_BACKENDS = ( 'apps.users.backends.OTPBackend', 'django.contrib.auth.backends.ModelBackend', ) WSGI_APPLICATION = 'main.wsgi.application' # Database # https://docs.djangoproject.com/en/5.0/ref/settings/#databases # DATABASES = { # 'default': { # 'ENGINE': 'django.db.backends.sqlite3', # 'NAME': BASE_DIR / 'db.sqlite3', # } # } DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': config('DB_NAME'), 'USER': config('DB_USER'), 'PASSWORD': config('DB_PASSWORD'), 'HOST': config('DB_HOST', '127.0.0.1'), 'PORT': config('DB_PORT', ''), "CONN_MAX_AGE": 0, "OPTIONS": { "pool": True, }, }, } # Password validation # https://docs.djangoproject.com/en/5.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/5.0/topics/i18n/ LANGUAGE_CODE = 'fa' TIME_ZONE = 'UTC' USE_I18N = True USE_L10N = True USE_TZ = True LANGUAGES = [ ('en', _('English')), ('fa', _('Persian')), ('ar', _('Arabic')), ('tr', _('Turkish')), ] LOCALE_PATHS = [ BASE_DIR / 'locale', ] # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/5.0/howto/static-files/ MEDIA_URL = 'media/' MEDIA_ROOT = BASE_DIR / 'media' STATIC_URL = '/static/' if DEBUG == True: STATICFILES_DIRS = ( BASE_DIR / 'static', ) else: STATIC_ROOT = BASE_DIR / 'static' # Default primary key field type # https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' LOGIN_URL = '/users/login/' # LOGIN_DEFAULT_REDIRECT_URL = '/' CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5" CRISPY_TEMPLATE_PACK = "bootstrap5" AUTH_USER_MODEL = 'users.User' CORS_ORIGIN_ALLOW_ALL = True CORS_ALLOW_ALL_ORIGINS = True CSRF_TRUSTED_ORIGINS = ['http://*.gooyal.com', 'https://*.gooyal.com', 'http://*.gooyal.ir', 'https://*.gooyal.ir'] JALALI_DATE_DEFAULTS = { 'Strftime': { 'date': '%Y/%m/%d', 'datetime': '%H:%M:%S _ %Y/%m/%d', } } PAYAM_SMS_SYSTEM_NAME = config('PAYAM_SMS_SYSTEM_NAME') PAYAM_SMS_USERNAME = config('PAYAM_SMS_USERNAME') PAYAM_SMS_PASSWORD = config('PAYAM_SMS_PASSWORD') PAYAM_SMS_CLIENT_ID = config('PAYAM_SMS_CLIENT_ID') PAYAM_SMS_CLIENT_SECRET = config('PAYAM_SMS_CLIENT_SECRET') SMS_OTP_SIGNITURE = config('SMS_OTP_SIGNITURE', '') SMS_SEND = config('SMS_SEND', True, cast=bool) TEST_PHONENUMBERS = config('TEST_PHONENUMBERS', [], cast=Csv(post_process=list)) CACHES = { "default": { "BACKEND": "django_redis.cache.RedisCache", "LOCATION": config('REDIS_BASE_URL'), "OPTIONS": { "CLIENT_CLASS": "django_redis.client.DefaultClient", } } } LOKI_BASE_PUBLIC_URL = config('LOKI_BASE_PUBLIC_URL', default=None, cast=str) from main.other_settings.logging import LOGGING from datetime import timedelta from typing import List, Tuple STORAGES = { "default": { "BACKEND": "django_minio_backend.models.MinioBackend", "OPTIONS": { "MINIO_ENDPOINT": config('MINIO_ENDPOINT', default='drive.gooyal.ir'), "MINIO_USE_HTTPS": config('MINIO_USE_HTTPS', default=True, cast=bool), "MINIO_EXTERNAL_ENDPOINT": config('MINIO_EXTERNAL_ENDPOINT', default='drive.gooyal.ir'), # Default is same as MINIO_ENDPOINT "MINIO_EXTERNAL_ENDPOINT_USE_HTTPS": config('MINIO_EXTERNAL_ENDPOINT_USE_HTTPS', default=True, cast=bool), # Default is same as MINIO_USE_HTTPS "MINIO_REGION": None, # Default is set to None "MINIO_ACCESS_KEY": config('MINIO_ACCESS_KEY'), "MINIO_SECRET_KEY": config('MINIO_SECRET_KEY'), "MINIO_URL_EXPIRY_HOURS": timedelta(days=1), # Default is 7 days (longest) if not defined "MINIO_CONSISTENCY_CHECK_ON_START": True, "MINIO_DEFAULT_BUCKET": config('MINIO_MEDIA_FILES_BUCKET'), # replacement for MEDIA_ROOT # MINIO_STATIC_FILES_BUCKET = 'my-static-files-bucket' # replacement for STATIC_ROOT "MINIO_PRIVATE_BUCKETS": [ 'default', ], "MINIO_PUBLIC_BUCKETS": [ 'default-public', config('MINIO_MEDIA_FILES_BUCKET') ], "MINIO_POLICY_HOOKS": [], "MINIO_BUCKET_CHECK_ON_SAVE": True # Default: True // Creates bucket if missing, then save }, }, "staticfiles": { # "BACKEND": "django_minio_backend.models.MinioBackendStatic", # "BACKEND": "django.core.files.storage.FileSystemStorage", "BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage", }, } # Custom HTTP Client (OPTIONAL) import os import certifi import urllib3 timeout = timedelta(minutes=5).seconds ca_certs = os.environ.get('SSL_CERT_FILE') or certifi.where() MINIO_HTTP_CLIENT: urllib3.poolmanager.PoolManager = urllib3.PoolManager( timeout=urllib3.util.Timeout(connect=timeout, read=timeout), maxsize=10, cert_reqs='CERT_REQUIRED', ca_certs=ca_certs, retries=urllib3.Retry( total=5, backoff_factor=0.2, status_forcelist=[500, 502, 503, 504] ) ) MINIO_ENDPOINT = config('MINIO_ENDPOINT', default='drive.gooyal.ir') MINIO_USE_HTTPS = config('MINIO_USE_HTTPS', default=True, cast=bool) MINIO_EXTERNAL_ENDPOINT = config('MINIO_EXTERNAL_ENDPOINT', default='drive.gooyal.ir') # Default is same as MINIO_ENDPOINT MINIO_EXTERNAL_ENDPOINT_USE_HTTPS = config('MINIO_EXTERNAL_ENDPOINT_USE_HTTPS', default=True, cast=bool) # Default is same as MINIO_USE_HTTPS MINIO_REGION = None # Default is set to None MINIO_ACCESS_KEY = config('MINIO_ACCESS_KEY') MINIO_SECRET_KEY = config('MINIO_SECRET_KEY') MINIO_URL_EXPIRY_HOURS = timedelta(days=1) # Default is 7 days (longest) if not defined MINIO_CONSISTENCY_CHECK_ON_START = False MINIO_MEDIA_FILES_BUCKET = config('MINIO_MEDIA_FILES_BUCKET') # replacement for MEDIA_ROOT # MINIO_STATIC_FILES_BUCKET = 'my-static-files-bucket' # replacement for STATIC_ROOT MINIO_PRIVATE_BUCKETS = [ 'default', ] MINIO_PUBLIC_BUCKETS = [ 'default-public', MINIO_MEDIA_FILES_BUCKET ] MINIO_POLICY_HOOKS: List[Tuple[str, dict]] = [] MINIO_BUCKET_CHECK_ON_SAVE = True # Default: True // Creates bucket if missing, then save MOBIN_SMS_TOKEN = config('MOBIN_SMS_TOKEN', default='') PROMOTIONS_BASE_PUBLIC_URL = config('PROMOTIONS_BASE_PUBLIC_URL', default=None, cast=str) PROMOTIONS_BASE_PRIVATE_URL = config('PROMOTIONS_BASE_PRIVATE_URL', default=None, cast=str) PROMOTIONS_REFERRAL_PLAN = config('PROMOTIONS_REFERRAL_PLAN', default=None, cast=str)