· 4 years ago · Mar 16, 2021, 03:30 PM
1import os
2from pathlib import Path
3
4import environ
5from django.utils.translation import gettext_lazy as _
6
7# Initialise environment variables
8env = environ.Env()
9environ.Env.read_env()
10
11# Build paths inside the project like this: BASE_DIR / 'subdir'.
12BASE_DIR = Path(__file__).resolve().parent.parent
13
14# Quick-start development settings - unsuitable for production
15# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
16
17# SECURITY WARNING: keep the secret key used in production secret!
18SECRET_KEY = os.environ.get("SECRET_KEY", "")
19
20ENVIRONMENT = os.environ.get("ENVIRONMENT", "local") # для rosetta по умолчанию local
21
22# SECURITY WARNING: don't run with debug turned on in production!
23DEBUG = True
24
25ALLOWED_HOSTS = []
26
27# Application definition
28
29INSTALLED_APPS = [
30 "jet.dashboard",
31 "jet",
32 "django.contrib.admin",
33 "django.contrib.auth",
34 "django.contrib.contenttypes",
35 "django.contrib.sessions",
36 "django.contrib.messages",
37 "django.contrib.staticfiles", # required for serving swagger ui's css/js files
38 "rest_framework",
39 "rest_framework.authtoken",
40 # "oauth2_provider",
41 # "social_django",
42 # "rest_framework_social_oauth2",
43 "drf_yasg",
44 "stdimage",
45 "django_celery_beat", # before that django-celery-beat was above drf and i have error
46]
47
48CELERY_BROKER_URL = os.environ.get("CELERY_BROKER_URL", "redis://0.0.0.0:6379/0")
49CELERY_RESULT_BACKEND = os.environ.get("CELERY_RESULT_BACKEND", "redis://0.0.0.0:6379/0")
50
51PROJECT_APPS = [
52 "accounts",
53]
54
55INSTALLED_APPS += PROJECT_APPS
56
57MIDDLEWARE = [
58 "django.middleware.security.SecurityMiddleware",
59 "django.contrib.sessions.middleware.SessionMiddleware",
60 "django.middleware.locale.LocaleMiddleware", # activated translation, after SessionMiddleware
61 "django.middleware.common.CommonMiddleware",
62 "django.middleware.csrf.CsrfViewMiddleware",
63 "django.contrib.auth.middleware.AuthenticationMiddleware",
64 "django.contrib.messages.middleware.MessageMiddleware",
65 "django.middleware.clickjacking.XFrameOptionsMiddleware",
66]
67
68ROOT_URLCONF = "website.urls"
69
70TEMPLATES = [
71 {
72 "BACKEND": "django.template.backends.django.DjangoTemplates",
73 "DIRS": [],
74 "APP_DIRS": True,
75 "OPTIONS": {
76 "context_processors": [
77 "django.template.context_processors.debug",
78 "django.template.context_processors.request",
79 "django.contrib.auth.context_processors.auth",
80 "django.contrib.messages.context_processors.messages",
81 "django.template.context_processors.i18n",
82 ],
83 },
84 },
85]
86
87WSGI_APPLICATION = "website.wsgi.application"
88
89# Database
90# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
91
92DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": BASE_DIR / "db.sqlite3",}}
93
94# Password validation
95# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
96
97AUTH_USER_MODEL = "accounts.CustomUser"
98
99AUTH_PASSWORD_VALIDATORS = [
100 {"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",},
101 {"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",},
102 {"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",},
103 {"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",},
104]
105
106REST_FRAMEWORK = {
107 "DEFAULT_AUTHENTICATION_CLASSES": (
108 "rest_framework.authentication.TokenAuthentication",
109 "rest_framework.authentication.SessionAuthentication",
110 "rest_framework.authentication.BasicAuthentication",
111 # "oauth2_provider.contrib.rest_framework.OAuth2Authentication",
112 # "rest_framework_social_oauth2.authentication.SocialAuthentication",
113 ),
114}
115
116AUTHENTICATION_BACKENDS = (
117 # "rest_framework_social_oauth2.backends.DjangoOAuth2",
118 "django.contrib.auth.backends.ModelBackend",
119)
120
121# Internationalization
122# https://docs.djangoproject.com/en/3.1/topics/i18n/
123
124X_FRAME_OPTIONS = "SAMEORIGIN" # for Django-jet
125
126JET_THEMES = [
127 {
128 "theme": "default", # theme folder name
129 "color": "#47bac1", # color of the theme's button in user menu
130 "title": "Default", # theme title
131 },
132 {"theme": "green", "color": "#44b78b", "title": "Green"},
133 {"theme": "light-green", "color": "#2faa60", "title": "Light Green"},
134 {"theme": "light-violet", "color": "#a464c4", "title": "Light Violet"},
135 {"theme": "light-blue", "color": "#5EADDE", "title": "Light Blue"},
136 {"theme": "light-gray", "color": "#222", "title": "Light Gray"},
137]
138
139EMAIL_BACKEND = os.environ.get("EMAIL_BACKEND", "django.core.mail.backends.smtp.EmailBackend")
140EMAIL_USE_TLS = os.environ.get("EMAIL_USE_TLS", True)
141EMAIL_HOST = os.environ.get("EMAIL_HOST", "")
142EMAIL_HOST_USER = os.environ.get("EMAIL_HOST_USER", "")
143EMAIL_HOST_SENDER = os.environ.get("EMAIL_HOST_SENDER", "")
144EMAIL_HOST_PASSWORD = os.environ.get("EMAIL_HOST_PASSWORD", "")
145EMAIL_PORT = os.environ.get("EMAIL_PORT", 587)
146
147if ENVIRONMENT == "local":
148 INSTALLED_APPS.append("rosetta")
149 ROSETTA_SHOW_AT_ADMIN_PANEL = True
150
151LANGUAGES = [
152 ("ru", _("Russian")),
153 ("en", _("English")),
154]
155
156LOCALE_PATHS = [
157 os.path.join(BASE_DIR, "accounts/locale"),
158]
159
160LANGUAGE_CODE = "en-us"
161
162TIME_ZONE = "Europe/Moscow"
163
164USE_I18N = True
165
166USE_L10N = True
167
168USE_TZ = True
169
170# Static files (CSS, JavaScript, Images)
171# https://docs.djangoproject.com/en/3.1/howto/static-files/
172
173DRFSO2_URL_NAMESPACE = "api" # namespace for reversing URLs
174
175STATIC_URL = "/static/"
176MEDIA_URL = "/media/"
177
178VERIFICATION_TOKEN_EXPIRATION_TIME: int = 60 * 60 # 1 hour
179