· 5 years ago · Jun 19, 2020, 07:30 PM
1"""
2Django settings for bloguos project.
3
4Generated by 'django-admin startproject' using Django 1.10.5.
5
6For more information on this file, see
7https://docs.djangoproject.com/en/1.10/topics/settings/
8
9For the full list of settings and their values, see
10https://docs.djangoproject.com/en/1.10/ref/settings/
11"""
12import datetime
13import os
14import yaml
15
16from corsheaders.defaults import default_headers
17
18# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
19BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
20CREDENTIALS = os.environ.get("BLOGUOS_CREDENTIALS") or os.path.join(BASE_DIR, "credentials.yml")
21
22try:
23 with open(CREDENTIALS) as credentials_stream:
24 try:
25 credentials = yaml.load(credentials_stream)
26 django_setup = credentials.get('django_setup')
27 email_credentials = credentials.get('email_credentials')
28 notifications_credentials = credentials.get('notifications')
29 except yaml.YAMLError as exc:
30 print(exc)
31except Exception as exc:
32 print("Error: Credentials not found")
33 print(exc)
34
35# Quick-start development settings - unsuitable for production
36# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/
37
38# SECURITY WARNING: keep the secret key used in production secret!
39SECRET_KEY = django_setup.get("SECRET_KEY")
40
41# SECURITY WARNING: don't run with debug turned on in production! PRODUCTION
42DEBUG = True
43
44ALLOWED_HOSTS = ["*"]
45
46# Application definition
47
48INSTALLED_APPS = [
49 'django.contrib.admin',
50 'django.contrib.auth',
51 'django.contrib.contenttypes',
52 'django.contrib.sessions',
53 'django.contrib.messages',
54 'django.contrib.staticfiles',
55 'rest_framework',
56 'corsheaders',
57 'auth_api',
58 'projects',
59 'newsreviews',
60 'events'
61]
62
63MIDDLEWARE = [
64 'corsheaders.middleware.CorsMiddleware',
65 'django.middleware.common.CommonMiddleware',
66 'django.middleware.security.SecurityMiddleware',
67 'django.contrib.sessions.middleware.SessionMiddleware',
68 'django.middleware.common.CommonMiddleware',
69 # 'django.middleware.csrf.CsrfViewMiddleware',
70 'auth_api.middle.DisableCSRFMiddleware',
71 'django.contrib.auth.middleware.AuthenticationMiddleware',
72 'django.contrib.messages.middleware.MessageMiddleware',
73 'django.middleware.clickjacking.XFrameOptionsMiddleware',
74]
75
76ROOT_URLCONF = 'bloguos.urls'
77
78TEMPLATES = [
79 {
80 'BACKEND': 'django.template.backends.django.DjangoTemplates',
81 'DIRS': [],
82 'APP_DIRS': True,
83 'OPTIONS': {
84 'context_processors': [
85 'django.template.context_processors.debug',
86 'django.template.context_processors.request',
87 'django.contrib.auth.context_processors.auth',
88 'django.contrib.messages.context_processors.messages',
89 ],
90 },
91 },
92]
93
94WSGI_APPLICATION = django_setup.get("WSGI_APPLICATION")
95
96# Database
97# https://docs.djangoproject.com/en/1.10/ref/settings/#databases
98
99# DATABASES = django_setup.get("DATABASES")
100
101DATABASES = {
102 'default': {
103 'ENGINE': 'django.db.backends.postgresql',
104 'NAME': 'abakunov',
105 'USER': 'abakunov',
106 'PASSWORD': '',
107 'HOST': '',
108 'PORT': '5432',
109 }
110}
111
112# Password validation
113# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators
114
115AUTH_PASSWORD_VALIDATORS = django_setup.get("AUTH_PASSWORD_VALIDATORS")
116
117AUTH_USER_MODEL = django_setup.get("AUTH_USER_MODEL")
118
119# Internationalization
120# https://docs.djangoproject.com/en/1.10/topics/i18n/
121
122LANGUAGE_CODE = django_setup.get("LANGUAGE_CODE")
123
124TIME_ZONE = django_setup.get("TIME_ZONE")
125
126USE_I18N = django_setup.get("USE_I18N")
127
128USE_L10N = django_setup.get("USE_L10N")
129
130USE_TZ = django_setup.get("USE_TZ")
131
132# Static files (CSS, JavaScript, Images)
133# https://docs.djangoproject.com/en/1.10/howto/static-files/
134
135# STATIC_URL = django_setup.get("STATIC_URL")
136
137REST_FRAMEWORK = django_setup.get("REST_FRAMEWORK")
138
139CORS_ORIGIN_ALLOW_ALL = django_setup.get("CORS_ORIGIN_ALLOW_ALL")
140CORS_ALLOW_CREDENTIALS = django_setup.get("CORS_ALLOW_CREDENTIALS")
141
142CORS_ALLOW_HEADERS = default_headers + (
143 'content-disposition',
144)
145
146CORS_EXPOSE_HEADERS = django_setup.get("CORS_EXPOSE_HEADERS")
147
148JWT_AUTH = {
149 'JWT_AUTH_HEADER_PREFIX': 'Bearer',
150 'JWT_EXPIRATION_DELTA': datetime.timedelta(seconds=3600),
151 'JWT_ALLOW_REFRESH': True
152}
153
154EMAIL_BACKEND = email_credentials.get("EMAIL_BACKEND")
155EMAIL_USE_SSL = email_credentials.get("EMAIL_USE_SSL")
156EMAIL_HOST = email_credentials.get("EMAIL_HOST")
157EMAIL_PORT = email_credentials.get("EMAIL_PORT")
158EMAIL_HOST_USER = email_credentials.get("EMAIL_HOST_USER")
159EMAIL_HOST_PASSWORD = email_credentials.get("EMAIL_HOST_PASSWORD")
160DEFAULT_FROM_EMAIL = email_credentials.get("DEFAULT_FROM_EMAIL")
161
162TELEGRAM_PROXY = notifications_credentials.get("TELEGRAM_PROXY")
163TELEGRAM_CHAT = notifications_credentials.get("TELEGRAM_CHAT")
164TELEGRAM_TOKEN = notifications_credentials.get("TELEGRAM_TOKEN")
165
166# try:
167# from bloguos.local_settings import *
168# except ImportError as e:
169# print("Local settings doesn't work: %s" % e)
170
171STATIC_URL = '/static/'
172STATIC_ROOT = os.path.join(BASE_DIR, 'static')
173MEDIA_URL = '/media/'
174MEDIA_ROOT = os.path.join(BASE_DIR, 'media')