fork download
  1. """
  2. Django settings for blink_crm_api project.
  3.  
  4. Generated by 'django-admin startproject' using Django 3.1.3.
  5.  
  6. For more information on this file, see
  7. https://d...content-available-to-author-only...t.com/en/3.1/topics/settings/
  8.  
  9. For the full list of settings and their values, see
  10. https://d...content-available-to-author-only...t.com/en/3.1/ref/settings/
  11. """
  12.  
  13. from pathlib import Path
  14. import os
  15. import socket
  16. import sys
  17. from datetime import timedelta
  18. import dj_database_url
  19. import sentry_sdk
  20. from sentry_sdk.integrations.django import DjangoIntegration
  21. from django.conf import settings
  22. from firebase_admin import initialize_app
  23. from notification.services.slack_service import SlackService
  24.  
  25. from core import config
  26. import django
  27. from django.utils.translation import gettext
  28. django.utils.translation.ugettext = gettext
  29.  
  30. # sentry_sdk.init(
  31. # dsn=os.environ.get('SENTRY_DSN', ''),
  32. # integrations=[DjangoIntegration()],
  33.  
  34. # # Set traces_sample_rate to 1.0 to capture 100%
  35. # # of transactions for performance monitoring.
  36. # # We recommend adjusting this value in production.
  37. # traces_sample_rate=0.1,
  38.  
  39. # # If you wish to associate users to errors (assuming you are using
  40. # # django.contrib.auth) you may enable sending PII data.
  41. # send_default_pii=True
  42. # )
  43.  
  44.  
  45. # Build paths inside the project like this: BASE_DIR / 'subdir'.
  46. BASE_DIR = Path(__file__).resolve().parent.parent
  47.  
  48. # Quick-start development settings - unsuitable for production
  49. # See https://d...content-available-to-author-only...t.com/en/3.1/howto/deployment/checklist/
  50.  
  51. # SECURITY WARNING: keep the secret key used in production secret!
  52. SECRET_KEY = 'wnia2ie9-(c2_)4g%ck%bw6lyfjtdgf@imcg*xe*n!uo%1^&0%'
  53.  
  54. # SECURITY WARNING: don't run with debug turned on in production!
  55. DEBUG = os.getenv('DEBUG', False) == 'True'
  56.  
  57. ALLOWED_HOSTS = [
  58. '*'
  59. ]
  60.  
  61.  
  62. print('_________________THE PLATFORM IS _________')
  63. print('_____________' + os.environ.get('PLATFORM', '') + '___________________')
  64.  
  65.  
  66. # Application definition
  67. MIGRATION_COMMAND = sys.argv[1] in (
  68. 'makemigrations', 'migrate', 'loaddata', 'import_coa_blink', 'import_entry_templates')
  69. INSTALLED_APPS = [
  70. "django.contrib.admin.apps.SimpleAdminConfig" if MIGRATION_COMMAND else 'django.contrib.admin',
  71. 'django.contrib.auth',
  72. 'django.contrib.contenttypes',
  73. 'django.contrib.sessions',
  74. 'django.contrib.messages',
  75. 'django.contrib.postgres',
  76. 'whitenoise.runserver_nostatic',
  77. 'django.contrib.staticfiles',
  78. 'drf_yasg',
  79. 'rest_framework',
  80. 'django_reactive',
  81. 'mathfilters',
  82. 'crm_app.apps.CrmAppConfig',
  83. 'ekyc_app.apps.EkycAppConfig',
  84. 'auth_app.apps.AuthAppConfig',
  85. 'datasets.apps.DatasetsConfig',
  86. 'ledger',
  87. 'lms.apps.LmsConfig',
  88. 'loan_app.apps.LoanAppConfig',
  89. 'reports_app.apps.ReportsAppConfig',
  90. 'payments.apps.PaymentsConfig',
  91. "fcm_django",
  92. 'notification.apps.NotificationConfig',
  93. 'django_extensions',
  94. 'polymorphic',
  95. 'import_export',
  96. 'django_filters',
  97. 'rest_framework_simplejwt.token_blacklist',
  98. 'django_summernote',
  99. 'rangefilter',
  100. 'storages',
  101. 'call_center',
  102. 'elasticapm.contrib.django',
  103. 'credit_alerts',
  104. 'flutter_consumer',
  105. 'credit_app',
  106. 'merchant_dashboard',
  107. 'configurations',
  108. 'ticket_app',
  109. 'settlement_dashboard',
  110. 'tms_app',
  111. 'newEkyc_app',
  112. 'call_centerv2',
  113. 'ticket_appV2',
  114. 'archive_app',
  115. 'new_lms',
  116. 'log_app',
  117. 'collection',
  118. 'sales_tracking',
  119. 'django_rename_app',
  120. 'django_celery_results',
  121.  
  122. ]
  123.  
  124. MIDDLEWARE = [
  125. 'django.middleware.locale.LocaleMiddleware',
  126. 'django.middleware.security.SecurityMiddleware',
  127. 'django.contrib.sessions.middleware.SessionMiddleware',
  128. 'corsheaders.middleware.CorsMiddleware',
  129. 'django.middleware.common.CommonMiddleware',
  130. 'django.middleware.csrf.CsrfViewMiddleware',
  131. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  132. 'django.contrib.messages.middleware.MessageMiddleware',
  133. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  134. 'whitenoise.middleware.WhiteNoiseMiddleware',
  135. # Timezone
  136. "core.timezone_middleware.TimezoneMiddleware",
  137. # Translation
  138. "core.translation_middleware.TranslationMiddleware",
  139. 'elasticapm.contrib.django.middleware.TracingMiddleware'
  140. ]
  141.  
  142.  
  143. ROOT_URLCONF = 'blink_crm_api.urls'
  144.  
  145. TEMPLATES = [
  146. {
  147. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  148. 'DIRS': [os.path.join(BASE_DIR, 'templates')],
  149. 'APP_DIRS': True,
  150. 'OPTIONS': {
  151. 'context_processors': [
  152. 'django.template.context_processors.debug',
  153. 'django.template.context_processors.request',
  154. 'django.contrib.auth.context_processors.auth',
  155. 'django.contrib.messages.context_processors.messages',
  156. 'core.context_processors.from_settings'
  157. ],
  158. },
  159. },
  160. ]
  161.  
  162. WSGI_APPLICATION = 'blink_crm_api.wsgi.application'
  163.  
  164. # Database
  165. # https://d...content-available-to-author-only...t.com/en/3.1/ref/settings/#databases
  166.  
  167. DATABASES = {
  168. 'default': {
  169. 'ENGINE': 'django.db.backends.sqlite3',
  170. 'NAME': BASE_DIR / 'db.sqlite3',
  171. }
  172. }
  173.  
  174. if os.environ.get('DATABASE_URL'):
  175. print('found env database')
  176. print(os.environ.get('DATABASE_URL'))
  177. DATABASES = {'default': dj_database_url.config(conn_max_age=600)}
  178.  
  179. if "test" in sys.argv:
  180. DATABASES["default"] = {
  181. "ENGINE": "django.db.backends.postgresql",
  182. "NAME": "test_db",
  183. "USER": "postgres",
  184. "PASSWORD": "1234",
  185. "HOST": "localhost",
  186. "PORT": "5432",
  187. }
  188.  
  189. AUTH_USER_MODEL = 'auth_app.User'
  190.  
  191. # Password validation
  192. # https://d...content-available-to-author-only...t.com/en/3.1/ref/settings/#auth-password-validators
  193.  
  194. AUTH_PASSWORD_VALIDATORS = [
  195. {
  196. 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  197. },
  198. {
  199. 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  200. },
  201. {
  202. 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  203. },
  204. {
  205. 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  206. },
  207. ]
  208.  
  209. # Internationalization
  210. # https://d...content-available-to-author-only...t.com/en/3.1/topics/i18n/
  211.  
  212. LANGUAGES = [
  213. ('en', 'English'),
  214. ('ar', 'Arabic'),
  215. ]
  216.  
  217.  
  218. # LANGUAGE_CODE = 'en-us'
  219.  
  220. LANGUAGE_CODE = 'ar'
  221. TIME_ZONE = 'UTC'
  222.  
  223. USE_I18N = True
  224.  
  225. USE_L10N = True
  226.  
  227. USE_TZ = True
  228.  
  229. LOCALE_PATHS = (
  230. os.path.join(BASE_DIR, 'locale/'),
  231. )
  232.  
  233.  
  234. # Static files (CSS, JavaScript, Images)
  235. # https://d...content-available-to-author-only...t.com/en/3.1/howto/static-files/
  236.  
  237. PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
  238.  
  239. STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
  240. STATIC_URL = '/static/'
  241. STATICFILES_DIRS = [
  242. os.path.join(BASE_DIR, 'static'),
  243. ]
  244. DATA_UPLOAD_MAX_MEMORY_SIZE=4194304 #4 MB
  245.  
  246. CHECK_CONSUMER_RATE = os.getenv("CHECK_CONSUMER_RATE", "5/day")
  247.  
  248. REST_FRAMEWORK = {
  249. 'DEFAULT_AUTHENTICATION_CLASSES': (
  250. 'rest_framework_simplejwt.authentication.JWTAuthentication',
  251. ),
  252. 'EXCEPTION_HANDLER': 'core.exception_handler.exception_handler',
  253. 'DEFAULT_THROTTLE_RATES': {
  254. 'check_consumer_daily': CHECK_CONSUMER_RATE,
  255. }
  256. }
  257.  
  258. SWAGGER_SETTINGS = {
  259. 'SECURITY_DEFINITIONS': {
  260. 'Bearer': {
  261. 'type': 'apiKey',
  262. 'name': 'Authorization',
  263. 'in': 'header'
  264. }
  265. }
  266. }
  267.  
  268. SIMPLE_JWT = {
  269. 'ACCESS_TOKEN_LIFETIME': timedelta(minutes=30),
  270. 'REFRESH_TOKEN_LIFETIME': timedelta(days=5),
  271. 'ROTATE_REFRESH_TOKENS': True,
  272. 'BLACKLIST_AFTER_ROTATION': True,
  273. 'ALGORITHM': 'HS256',
  274. 'SIGNING_KEY': SECRET_KEY,
  275. }
  276.  
  277. # FOR HTTPS
  278. print(os.environ.get('NOT_SECURE_CONNECTION'))
  279. if os.environ.get('NOT_SECURE_CONNECTION'):
  280. print('Secure connection disabled')
  281. SESSION_COOKIE_SECURE = False
  282. CSRF_COOKIE_SECURE = False
  283. else:
  284. SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
  285. SESSION_COOKIE_SECURE = True
  286. CSRF_COOKIE_SECURE = True
  287. SECURE_SSL_REDIRECT = True
  288.  
  289. # Security Headers
  290. SECURE_CONTENT_TYPE_NOSNIFF = True
  291. SECURE_HSTS_INCLUDE_SUBDOMAINS = True
  292. SECURE_HSTS_PRELOAD = True
  293. SECURE_HSTS_SECONDS = 3600
  294.  
  295. # CORS
  296. CORS_ALLOW_ALL_ORIGINS = True
  297.  
  298. EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
  299. EMAIL_HOST = 'smtp.gmail.com'
  300. EMAIL_USE_TLS = True
  301. EMAIL_PORT = 587
  302. DEFAULT_FROM_EMAIL = os.environ.get('EMAIL_HOST','tech-alerts@blnk.ai')
  303. EMAIL_HOST_USER = os.environ.get('EMAIL_HOST','tech-alerts@blnk.ai')
  304. EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_PASSWORD','jcvl kknv hdze eyvi')
  305.  
  306.  
  307. AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID')
  308. AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY')
  309. AWS_STORAGE_BUCKET_NAME = os.environ.get('AWS_STORAGE_BUCKET_NAME')
  310.  
  311. AWS_S3_REGION_NAME = os.environ.get('AWS_REGION')
  312. AWS_S3_SIGNATURE_VERSION = 's3v4'
  313.  
  314. # SFTP - DJANGO_STORAGE
  315. DEFAULT_FILE_STORAGE = 'storages.backends.sftpstorage.SFTPStorage'
  316. SFTP_STORAGE_HOST = os.environ.get('SFTP_STORAGE_HOST', '')
  317. SFTP_STORAGE_ROOT = os.environ.get('SFTP_STORAGE_ROOT', '')
  318. #tel3et mohema metlasma
  319. SFTP_STORAGE_PARAMS = {
  320. 'username': os.environ.get('SFTP_STORAGE_USERNAME', ''),
  321. 'password': os.environ.get('SFTP_STORAGE_PASS', ''),
  322. 'allow_agent': False,
  323. 'look_for_keys': False,
  324. 'timeout': float(os.environ.get('SFTP_TIMEOUT', '10.0')),
  325. 'banner_timeout': float(os.environ.get('SFTP_BANNER_TIMEOUT', '10.0')),
  326. 'auth_timeout': float(os.environ.get('SFTP_AUTH_TIMEOUT', '10.0')),
  327. }
  328.  
  329. SFTP_STORAGE_PARAM_BLNK_UPLOADS = {
  330. 'username': os.environ.get('SFTP_STORAGE_BLNK_UPLOADS_USERNAME', ''),
  331. 'password': os.environ.get('SFTP_STORAGE_BLNK_UPLOADS_PASS', ''),
  332. 'allow_agent': False,
  333. 'look_for_keys': False,
  334. 'timeout': float(os.environ.get('SFTP_TIMEOUT', '10.0')),
  335. 'banner_timeout': float(os.environ.get('SFTP_BANNER_TIMEOUT', '10.0')),
  336. 'auth_timeout': float(os.environ.get('SFTP_AUTH_TIMEOUT', '10.0')),
  337. }
  338.  
  339.  
  340. # Text editor plugin
  341. X_FRAME_OPTIONS = 'SAMEORIGIN'
  342. SUMMERNOTE_CONFIG = {
  343. # You can put custom Summernote settings
  344. 'summernote': {
  345. # Toolbar customization
  346. # https://s...content-available-to-author-only...e.org/deep-dive/#custom-toolbar-popover
  347. 'toolbar': [
  348. ['view', ['fullscreen', 'codeview']],
  349. ],
  350. },
  351. 'js': (
  352. '/static/admin/summernote/custom.js',
  353. ),
  354. }
  355.  
  356. # DATA_UPLOAD_MAX_NUMBER_FIELDS = None
  357.  
  358. FIREBASE_APP = initialize_app()
  359.  
  360. FCM_DJANGO_SETTINGS = {
  361.  
  362. }
  363. # FCM_DJANGO_SETTINGS = {
  364. # "FCM_SERVER_KEY": os.environ.get('FCM_SERVER_KEY', ''),
  365. # "FCM_SENDER_ID": os.environ.get('FCM_SENDER_ID', ''),
  366. # }
  367.  
  368.  
  369. if os.environ.get('USE_X_FORWARDED_HOST'):
  370. USE_X_FORWARDED_HOST = True
  371. SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
  372.  
  373. # MEDIA_ROOT = "/NationalID/"
  374. #MEDIA_URL = os.environ.get('SFTP_STORAGE_URL', '')
  375.  
  376. # LOGGING = {
  377. # 'version': 1,
  378. # 'disable_existing_loggers': False,
  379. # 'handlers': {
  380. # 'applogfile': {
  381. # 'level': 'DEBUG',
  382. # 'class': 'logging.FileHandler',
  383. # 'filename': '../blnk_errors.log',
  384. # 'maxBytes': 1024 * 1024 * 15, # 15MB
  385. # 'backupCount': 10,
  386. # },
  387. # },
  388. # 'loggers': {
  389. # 'django': {
  390. # 'handlers': ['applogfile','console'],
  391. # 'level': 'DEBUG',
  392. # },
  393. # }
  394. # }
  395.  
  396. # LOGGING = {
  397. # 'version': 1,
  398. # 'disable_existing_loggers': False,
  399. # 'handlers': {
  400. # 'applogfile': {
  401. # 'level': 'DEBUG',
  402. # 'class': 'logging.FileHandler',
  403. # 'filename': '../blnk_errors.log',
  404. # 'maxBytes': 1024 * 1024 * 15, # 15MB
  405. # 'backupCount': 10,
  406. # },
  407. # },
  408. # 'loggers': {
  409. # 'django': {
  410. # 'handlers': ['applogfile',],
  411. # 'level': 'DEBUG',
  412. # },
  413. # }
  414. # }
  415.  
  416.  
  417. # LOGGING = {
  418. # 'version': 1,
  419. # 'disable_existing_loggers': False,
  420. # 'handlers': {
  421. # 'file': {
  422. # 'level': 'DEBUG',
  423. # 'class': 'logging.FileHandler',
  424. # 'filename': '../blnk_errors.log',
  425. # 'maxBytes': 1024 * 1024 * 15, # 15MB
  426. # 'backupCount': 10,
  427. # },
  428. # },
  429. # 'loggers': {
  430. # 'django': {
  431. # 'handlers': ['file'],
  432. # 'level': 'DEBUG',
  433. # # 'propagate': True,
  434. # },
  435. # },
  436. # }
  437.  
  438. LOGGING = {
  439. 'version': 1,
  440. 'disable_existing_loggers': False,
  441. 'formatters': {
  442. 'verbose': {
  443. 'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d {server_ip} %(message)s'
  444. },
  445. },
  446. 'handlers': {
  447. 'elasticapm': {
  448. 'level': 'DEBUG',
  449. 'class': 'elasticapm.contrib.django.handlers.LoggingHandler',
  450. },
  451. 'console': {
  452. 'level': 'DEBUG',
  453. 'class': 'logging.StreamHandler',
  454. 'formatter': 'verbose'
  455. },
  456. 'to_slack': {
  457. 'level': 'DEBUG',
  458. 'formatter': 'verbose',
  459. 'class': 'core.custom_logging.CustomLoggingHandler',
  460. 'custom_function': SlackService(os.environ.get('API_ERROR_CHANNEL')).send_message
  461. }
  462. },
  463. 'loggers': {
  464. 'mysite': {
  465. 'level': 'DEBUG',
  466. 'handlers': ['elasticapm'],
  467. 'propagate': False,
  468. },
  469. # Log errors from the Elastic APM module to the console (recommended)
  470. 'elasticapm': {
  471. 'level': 'ERROR',
  472. 'handlers': ['to_slack', 'console'],
  473. 'propagate': False,
  474. },
  475. 'crm_app': {
  476. 'level': 'DEBUG',
  477. 'handlers': [ 'console'],
  478. 'propagate': False,
  479. },
  480. },
  481. }
  482.  
  483. # Get the server's IP address
  484. server_ip = socket.gethostbyname(socket.gethostname())
  485. LOGGING['formatters']['verbose']['format'] = LOGGING['formatters']['verbose']['format'].replace('{server_ip}', server_ip)
  486.  
  487. print("APM CLOSE = ",os.environ.get('APM_ClOSE_FLAG',False) == 'True')
  488. ELASTIC_APM = {
  489. # Set the required service name. Allowed characters:
  490. # a-z, A-Z, 0-9, -, _, and space
  491. 'SERVICE_NAME': 'django-test',
  492. # Set the custom APM Server URL (default: http://localhost:8200)
  493. 'SERVER_URL': os.environ.get('APM_SERVER_URL', ''),
  494.  
  495. # Set the service environment
  496.  
  497. # 'DEBUG': os.environ.get('APM_ClOSE_FLAG',False) == 'True',
  498. 'DISABLE_SEND': os.environ.get('APM_ClOSE_FLAG',True) == 'True',
  499. 'CAPTURE_BODY': 'all',
  500. 'PROCESSORS': [
  501. 'core.apm_processors.sanitize_processor',
  502. 'elasticapm.processors.sanitize_stacktrace_locals',
  503. 'elasticapm.processors.sanitize_http_request_cookies',
  504. 'elasticapm.processors.sanitize_http_headers',
  505. 'elasticapm.processors.sanitize_http_wsgi_env',
  506. 'elasticapm.processors.sanitize_http_request_body',
  507. ],
  508. 'INSTRUMENT': True
  509. }
  510.  
  511. CELERY_BROKER_URL = f'amqp://{config.RABBITMQ_USERNAME}:{config.RABBITMQ_PASSWORD}@{config.RABBITMQ_HOST}:{config.RABBITMQ_PORT}/{config.RABBITMQ_VIRTUAL_HOST}'
  512. CELERY_RESULT_BACKEND = 'rpc://'
  513.  
  514. CELERY_ACCEPT_CONTENT = ['json']
  515. CELERY_TASK_SERIALIZER = 'json'
  516. CELERY_RESULT_SERIALIZER = 'json'
  517. CELERY_TIMEZONE = 'UTC'
  518.  
  519. from urllib.parse import quote_plus
  520.  
  521. REDIS_HOST = os.getenv("REDIS_HOST", "127.0.0.1")
  522. REDIS_PORT = os.getenv("REDIS_PORT", "6379")
  523. REDIS_PASSWORD_RAW = os.getenv("REDIS_PASSWORD", "")
  524. REDIS_DB = os.getenv("REDIS_DB", "1")
  525.  
  526. REDIS_PASSWORD = quote_plus(REDIS_PASSWORD_RAW)
  527.  
  528. REDIS_URL = f"redis://:{REDIS_PASSWORD}@{REDIS_HOST}:{REDIS_PORT}/{REDIS_DB}"
  529.  
  530. CACHES = {
  531. "default": {
  532. "BACKEND": "django_redis.cache.RedisCache",
  533. "LOCATION": REDIS_URL,
  534. "OPTIONS": {
  535. "CLIENT_CLASS": "django_redis.client.DefaultClient",
  536. },
  537. }
  538. }
Success #stdin #stdout #stderr 0.01s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: near line 1: near """"
Django settings for blink_crm_api project.

Generated by 'django-admin startproject' using Django 3.1.3.

For more information on this file, see
https://d...content-available-to-author-only...t.com/en/3.1/topics/settings/

For the full list of settings and their values, see
https://d...content-available-to-author-only...t.com/en/3.1/ref/settings/
"""": syntax error