Exesize

Форк
0
/
settings.py 
234 строки · 6.3 Кб
1
"""
2
Django settings for config project.
3

4
Generated by 'django-admin startproject' using Django 4.0.4.
5

6
For more information on this file, see
7
https://docs.djangoproject.com/en/4.0/topics/settings/
8

9
For the full list of settings and their values, see
10
https://docs.djangoproject.com/en/4.0/ref/settings/
11
"""
12
import os
13
from pathlib import Path
14

15
from dotenv import load_dotenv
16

17
# from secret_keys import *
18

19
# from braniacLMS.secret_keys import SOCIAL_AUTH_GITHUB_KEY, SOCIAL_AUTH_GITHUB_SECRET, SECRET_KEY
20

21
BASE_DIR = Path(__file__).resolve().parent.parent
22
load_dotenv(BASE_DIR / '.env')
23
# Quick-start development settings - unsuitable for production
24
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
25

26
# SECURITY WARNING: keep the secret key used in production secret!
27
SECRET_KEY = 'django-insecure-e@fxn*bi#)rga)(kh794ym@%@nflv=&3pc6%63!=sh@_8ny2=%'
28

29
# SECURITY WARNING: don't run with debug turned on in production!
30
DEBUG = True if os.getenv('DEBUG') == 'True' else False
31

32
ALLOWED_HOSTS = ['*']
33

34
ENV_TYPE = os.getenv('ENV_TYPE', 'prod')
35

36
if DEBUG:
37
    INTERNAL_IPS = [
38
        "192.168.1.4",
39
        "127.0.0.1",
40
    ]
41

42
# Application definition
43

44
INSTALLED_APPS = [
45
    'django.contrib.admin',
46
    'django.contrib.auth',
47
    'django.contrib.contenttypes',
48
    'django.contrib.sessions',
49
    'django.contrib.messages',
50
    'django.contrib.staticfiles',
51
    'django-extensions',
52

53
    'social_django',
54
    'crispy_forms',
55
    'authapp',
56
    'mainapp',
57
    'debug_toolbar',
58
]
59

60
MIDDLEWARE = [
61
    'django.middleware.security.SecurityMiddleware',
62
    'django.contrib.sessions.middleware.SessionMiddleware',
63
    'django.middleware.locale.LocaleMiddleware',
64
    'django.middleware.common.CommonMiddleware',
65
    'django.middleware.csrf.CsrfViewMiddleware',
66
    'django.contrib.auth.middleware.AuthenticationMiddleware',
67
    'django.contrib.messages.middleware.MessageMiddleware',
68
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
69
    'debug_toolbar.middleware.DebugToolbarMiddleware',
70
]
71

72
ROOT_URLCONF = 'config.urls'
73

74
TEMPLATES = [
75
    {
76
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
77
        'DIRS': [BASE_DIR / 'templates'],
78
        'APP_DIRS': True,
79
        'OPTIONS': {
80
            'context_processors': [
81
                'django.template.context_processors.debug',
82
                'django.template.context_processors.request',
83
                'django.contrib.auth.context_processors.auth',
84
                'django.contrib.messages.context_processors.messages',
85
                'social_django.context_processors.backends',
86
                'social_django.context_processors.login_redirect',
87

88
            ],
89
        },
90
    },
91
]
92

93
WSGI_APPLICATION = 'config.wsgi.application'
94

95
# Database
96
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
97

98
if ENV_TYPE == 'local':
99
    DATABASES = {
100
        'default': {
101
            'ENGINE': 'django.db.backends.sqlite3',
102
            'NAME': BASE_DIR / 'db.sqlite3',
103
        }
104
    }
105
else:
106
    DATABASES = {
107
        'default': {
108
            'ENGINE': 'django.db.backends.postgresql_psycopg2',
109
            'NAME': 'lms',
110
            'USER': 'postgres'
111
        }
112
    }
113

114
# Password validation
115
# https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators
116

117
AUTH_PASSWORD_VALIDATORS = [
118
    {
119
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
120
    },
121
    {
122
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
123
    },
124
    {
125
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
126
    },
127
    {
128
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
129
    },
130
]
131

132
# Internationalization
133
# https://docs.djangoproject.com/en/4.0/topics/i18n/
134

135
LANGUAGE_CODE = 'ru-ru'
136

137
TIME_ZONE = 'Europe/Moscow'
138

139
USE_I18N = True
140

141
USE_TZ = True
142

143
# Static files (CSS, JavaScript, Images)
144
# https://docs.djangoproject.com/en/4.0/howto/static-files/
145

146
STATIC_URL = 'static/'
147
if ENV_TYPE == 'local':
148
    STATICFILES_DIRS = [
149
        BASE_DIR / 'static',
150
    ]
151
else:
152
    STATIC_ROOT = BASE_DIR / 'static'
153

154
# Default primary key field type
155
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
156

157
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
158

159
MEDIA_URL = '/media/'
160
DEFAULT_AVATAR_URL = '/img/'
161

162
MEDIA_ROOT = BASE_DIR / 'media'
163

164
AUTH_USER_MODEL = 'authapp.User'
165
LOGIN_REDIRECT_URL = 'mainapp:home'
166
LOGOUT_REDIRECT_URL = 'mainapp:home'
167

168
MESSAGE_STORAGE = 'django.contrib.messages.storage.session.SessionStorage'
169

170
AUTHENTICATION_BACKENDS = (
171
    'social_core.backends.github.GithubOAuth2',
172
    'django.contrib.auth.backends.ModelBackend',
173
)
174

175
SOCIAL_AUTH_GITHUB_KEY = os.getenv('GITHUB_KEY')
176
SOCIAL_AUTH_GITHUB_SECRET = os.getenv('GITHUB_SECRET')
177
CRISPY_TEMPLATE_PACK = 'bootstrap4'
178

179
LOG_FILE = BASE_DIR / "log" / "main_log.log"
180
LOGGING = {
181
    "version": 1,
182
    "disable_existing_loggers": False,
183
    "formatters": {
184
        "console": {
185
            "format": "[%(asctime)s] %(levelname)s %(name)s (%(lineno)d) %(message)s"
186
        },
187
    },
188
    "handlers": {
189
        "file": {
190
            "level": "INFO",
191
            "class": "logging.FileHandler",
192
            "filename": LOG_FILE,
193
            "formatter": "console",
194
        },
195
        "console": {"class": "logging.StreamHandler", "formatter": "console"},
196
    },
197
    "loggers": {
198
        "django": {"level": "INFO", "handlers": ["file", "console"]},
199
    },
200
}
201

202
CACHES = {
203
    "default": {
204
        "BACKEND": "django_redis.cache.RedisCache",
205
        "LOCATION": "redis://127.0.0.1:6379",
206
        "OPTIONS": {
207
            "CLIENT_CLASS": "django_redis.client.DefaultClient",
208
        },
209
    }
210
}
211

212
CELERY_BROKER_URL = "redis://localhost:6379"
213
CELERY_RESULT_BACKEND = "redis://localhost:6379"
214

215
# Read about sending email:
216
# https://docs.djangoproject.com/en/3.2/topics/email/
217
# Full list of email settings:
218
# https://docs.djangoproject.com/en/3.2/ref/settings/#email
219
# EMAIL_HOST = "localhost"
220
# EMAIL_PORT = "25"
221

222
# For debugging: python -m smtpd -n -c DebuggingServer localhost:25
223
# EMAIL_HOST_USER = "django@geekshop.local"
224
# EMAIL_HOST_PASSWORD = "geekshop"
225
# EMAIL_USE_SSL = False
226
# If server support TLS:
227
# EMAIL_USE_TLS = True
228
# Email as files for debug
229
EMAIL_BACKEND = "django.core.mail.backends.filebased.EmailBackend"
230
EMAIL_FILE_PATH = "emails-tmp"
231

232
LOCALE_PATHS = [BASE_DIR / 'locale']
233

234
SELENIUM_DRIVER_PATH_FF = BASE_DIR / 'var' / 'selenium' / 'geckodriver'
235

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.