-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathbase.py
More file actions
283 lines (228 loc) · 8.33 KB
/
base.py
File metadata and controls
283 lines (228 loc) · 8.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
import os
from django.utils.translation import gettext_lazy as _
import dj_database_url
import dj_email_url
from .. import get_project_root_path
from . import get_env_variable
gettext = lambda s: s
# Full filesystem path to the project.
BASE_DIR = get_project_root_path()
# Internationalization
LANGUAGE_CODE = "{{ cookiecutter.default_language }}"
TIME_ZONE = "Europe/Zurich"
USE_I18N = True
USE_L10N = True
USE_TZ = True
LANGUAGES = (
{%- for lang in cookiecutter.language_list.split(',') %}
("{{ lang }}", _("{{ lang }}")),
{%- endfor %}
)
LOCALE_PATHS = ("locale/",)
{%- if cookiecutter.use_djangocms == 'y' %}
SITE_ID = 1
{%- endif %}
# A boolean that turns on/off debug mode. When set to ``True``, stack traces
# are displayed for error pages. Should always be set to ``False`` in
# production. Best set to ``True`` in dev.py
DEBUG = False
# Whether a user's session cookie expires when the Web browser is closed.
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
# Tuple of IP addresses, as strings, that:
# * See debug comments, when DEBUG is true
# * Receive x-headers
INTERNAL_IPS = ("127.0.0.1",)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
)
STATICFILES_STORAGE = "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"
# The numeric mode to set newly-uploaded files to. The value should be
# a mode you'd pass directly to os.chmod.
FILE_UPLOAD_PERMISSIONS = 0o644
ALLOWED_HOSTS = tuple(get_env_variable("ALLOWED_HOSTS", "").splitlines())
SECRET_KEY = get_env_variable("SECRET_KEY", "")
PASSWORD_HASHERS = [
"django.contrib.auth.hashers.Argon2PasswordHasher",
"django.contrib.auth.hashers.PBKDF2PasswordHasher"
]
{% if cookiecutter.use_djangocms == 'y' %}
################
# CMS SETTINGS #
################
CMS_LANGUAGES = {
"default": {
"public": True,
"hide_untranslated": False,
"redirect_on_fallback": True,
},
1: [
{
"public": True,
"code": "en",
"hide_untranslated": False,
"name": gettext("en"),
"redirect_on_fallback": True,
}
],
}
CMS_TEMPLATES = (("base.html", "Base"),)
CMS_PERMISSION = True
CMS_PLACEHOLDER_CONF = {}
{% endif %}
SILENCED_SYSTEM_CHECKS = [
# False positive: we don't need to set `APP_DIRS=True` in template config
# because we already manually specify the "app_directories" loader.
"debug_toolbar.W006",
]
#############
# DATABASES #
#############
DATABASES = {"default": dj_database_url.parse(get_env_variable("DATABASE_URL"))}
#########
# PATHS #
#########
# Name of the directory for the project.
PROJECT_DIRNAME = "{{ cookiecutter.project_slug }}"
# Every cache key will get prefixed with this value - here we set it to
# the name of the directory the project is in to try and use something
# project specific.
CACHE_MIDDLEWARE_KEY_PREFIX = PROJECT_DIRNAME
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = get_env_variable("STATIC_URL", "/static/")
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# This is usually not used in a dev env, hence the default value
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = get_env_variable("STATIC_ROOT", "/tmp/static")
STATICFILES_DIRS = (os.path.join(BASE_DIR, "static"),)
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = get_env_variable("MEDIA_URL", "/media/")
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = get_env_variable("MEDIA_ROOT", "/tmp/static/media")
# Package/module name to import the root urlpatterns from for the project.
ROOT_URLCONF = "%s.config.urls" % PROJECT_DIRNAME
WSGI_APPLICATION = "{{ cookiecutter.project_slug }}.config.wsgi.application"
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [
os.path.join(BASE_DIR, "{{ cookiecutter.project_slug }}", "templates"),
],
"OPTIONS": {
"context_processors": [
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
"django.template.context_processors.i18n",
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.template.context_processors.media",
"django.template.context_processors.csrf",
"django.template.context_processors.tz",
"django.template.context_processors.static",
{%- if cookiecutter.use_djangocms == 'y' %}
"sekizai.context_processors.sekizai",
"cms.context_processors.cms_settings",
{%- endif %}
],
"loaders": [
(
"django.template.loaders.cached.Loader",
[
"django.template.loaders.filesystem.Loader",
"django.template.loaders.app_directories.Loader",
],
)
],
},
}
]
################
# APPLICATIONS #
################
INSTALLED_APPS = (
"{{ cookiecutter.project_slug }}.core.apps.CoreConfig",
{% if cookiecutter.override_user_model == 'y' -%}
"{{ cookiecutter.project_slug }}.accounts.apps.AccountsConfig",
{% endif -%}
{% if cookiecutter.use_djangocms == 'y' -%}
"djangocms_admin_style",
"djangocms_text_ckeditor",
"djangocms_link",
"cms",
"menus",
"treebeard",
"sekizai",
"filer",
"easy_thumbnails",
"django.contrib.sites",
{% endif -%}
"changelogmd",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.admin",
"django.contrib.staticfiles",
"django.contrib.messages",
)
# List of middleware classes to use. Order is important; in the request phase,
# these middleware classes will be applied in the order given, and in the
# response phase the middleware will be applied in reverse order.
MIDDLEWARE = (
{% if cookiecutter.use_djangocms == 'y' -%}
"cms.middleware.utils.ApphookReloadMiddleware",
{% endif -%}
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.locale.LocaleMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
{%- if cookiecutter.use_djangocms == 'y' %}
"cms.middleware.user.CurrentUserMiddleware",
"cms.middleware.page.CurrentPageMiddleware",
"cms.middleware.toolbar.ToolbarMiddleware",
"cms.middleware.language.LanguageCookieMiddleware",
{%- endif %}
)
{% if cookiecutter.override_user_model == 'y' -%}
##################
# AUTHENTICATION #
##################
AUTH_USER_MODEL = "accounts.User"
{% endif -%}
###########
# LOGGING #
###########
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"handlers": {"console": {"level": "INFO", "class": "logging.StreamHandler"}},
"loggers": {"": {"handlers": ["console"], "level": "ERROR", "propagate": True}},
}
#############
# E-Mailing #
#############
EMAIL_URL = get_env_variable("EMAIL_URL", "console://")
email_config = dj_email_url.parse(EMAIL_URL)
EMAIL_FILE_PATH = email_config["EMAIL_FILE_PATH"]
EMAIL_HOST_USER = email_config["EMAIL_HOST_USER"]
EMAIL_HOST_PASSWORD = email_config["EMAIL_HOST_PASSWORD"]
EMAIL_HOST = email_config["EMAIL_HOST"]
EMAIL_PORT = email_config["EMAIL_PORT"]
EMAIL_BACKEND = email_config["EMAIL_BACKEND"]
EMAIL_USE_TLS = email_config["EMAIL_USE_TLS"]
EMAIL_USE_SSL = email_config["EMAIL_USE_SSL"]
DEFAULT_FROM_EMAIL = get_env_variable("EMAIL_FROM", "webmaster@localhost")
#################
# Changelog gen #
#################
CHANGELOG_MD_PATH = os.path.join(BASE_DIR, "CHANGELOG.md")