· 6 years ago · Apr 17, 2019, 06:22 PM
1# -*- coding: utf-8 -*-
2"""
3Django settings for snc project.
4
5For more information on this file, see
6https://docs.djangoproject.com/en/dev/topics/settings/
7
8For the full list of settings and their values, see
9https://docs.djangoproject.com/en/dev/ref/settings/
10"""
11# from __future__ import absolute_import, unicode_literals
12from django.contrib.messages import constants as messages
13
14import environ
15
16import sentry_sdk
17from sentry_sdk.integrations.django import DjangoIntegration
18
19
20env = environ.Env(
21 DEBUG=(bool, False),
22 SENTRY_DSN=(str, None),
23 )
24
25env.read_env()
26
27ROOT_DIR = environ.Path(__file__) - 2 # (/a/b/myfile.py - 3 = /)
28
29RECEIVER_EMAIL = env("RECEIVER_EMAIL", default="none@email.com")
30# DEBUG
31# See: https://docs.djangoproject.com/en/dev/ref/settings/#debug
32DEBUG = env("DEBUG", default=False)
33
34# SECRET CONFIGURATION
35# See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
36SECRET_KEY = env("DJANGO_SECRET_KEY", default='CHANGEME!!!')
37
38# Allowed Hosts
39ALLOWED_HOSTS = env.list("ALLOWED_HOSTS", default=['localhost'])
40
41INTERNAL_IPS = ("127.0.0.1",)
42
43# APP CONFIGURATION
44
45MESSAGE_TAGS = {
46 messages.DEBUG: 'alert-info',
47 messages.INFO: 'alert-info',
48 messages.SUCCESS: 'alert-success',
49 messages.WARNING: 'alert-warning',
50 messages.ERROR: 'alert-danger',
51}
52
53DJANGO_APPS = (
54 # Default Django apps:
55 'django.contrib.auth',
56 'django.contrib.contenttypes',
57 'django.contrib.sessions',
58 'django.contrib.sites',
59 'django.contrib.messages',
60 'django.contrib.staticfiles',
61 'django.contrib.postgres',
62
63 # Useful template tags:
64 # 'django.contrib.humanize',
65 'dal',
66 'dal_select2',
67
68 # Admin
69 'django.contrib.admin',
70)
71
72THIRD_PARTY_APPS = (
73 'localflavor',
74 'ckeditor',
75 'widget_tweaks',
76 'rest_framework',
77 'django_filters',
78 'drf_hal_json',
79 'rest_framework_xml',
80 'rest_framework_csv',
81 'corsheaders',
82 'simple_history'
83)
84
85# Apps specific for this project go here.
86LOCAL_APPS = (
87 'adesao',
88 'gestao',
89 'planotrabalho',
90 'snc',
91 'apiv2',
92)
93
94# App used on development process
95DEVELOPMENT_SUPPORT_APPS = (
96 'django_extensions',
97 'debug_toolbar',
98)
99
100# See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
101INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
102
103if DEBUG:
104 INSTALLED_APPS = INSTALLED_APPS + DEVELOPMENT_SUPPORT_APPS
105
106REST_FRAMEWORK = {
107 'DEFAULT_PAGINATION_CLASS': 'apiv2.pagination.HalLimitOffsetPagination',
108 'PAGE_SIZE': 10,
109 'DEFAULT_FILTER_BACKENDS': ('django_filters.rest_framework.DjangoFilterBackend',),
110 'DEFAULT_PARSER_CLASSES':
111 ('rest_framework_xml.parsers.XMLParser',),
112 'DEFAULT_RENDERER_CLASSES': (
113 'drf_hal_json.renderers.JsonHalRenderer',
114 'rest_framework_xml.renderers.XMLRenderer',
115 'rest_framework_csv.renderers.CSVRenderer',
116# 'rest_framework.renderers.BrowsableAPIRenderer',
117 ),
118
119 'URL_FIELD_NAME': 'self',
120}
121
122# MIDDLEWARE CONFIGURATION
123# ------------------------------------------------------------------------------
124MIDDLEWARE = (
125 # Make sure djangosecure.middleware.SecurityMiddleware is listed first
126 'django.contrib.sessions.middleware.SessionMiddleware',
127 'django.middleware.csrf.CsrfViewMiddleware',
128 'corsheaders.middleware.CorsMiddleware',
129 'django.middleware.common.CommonMiddleware',
130 'django.contrib.auth.middleware.AuthenticationMiddleware',
131 'django.contrib.messages.middleware.MessageMiddleware',
132 'adesao.middleware.ThreadLocalUserMiddleware',
133 'simple_history.middleware.HistoryRequestMiddleware'
134)
135
136if DEBUG:
137 MIDDLEWARE = ('debug_toolbar.middleware.DebugToolbarMiddleware',) + MIDDLEWARE
138
139CORS_ORIGIN_ALLOW_ALL = True
140
141# MIGRATIONS CONFIGURATION
142# ------------------------------------------------------------------------------
143# MIGRATION_MODULES = {
144# 'sites': 'sistema-nacional-cultura.contrib.sites.migrations'
145# }
146
147# FIXTURE CONFIGURATION
148# ------------------------------------------------------------------------------
149# See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FIXTURE_DIRS
150# FIXTURE_DIRS = (
151# str(ROOT_DIR.path('fixtures')),
152# )
153
154# EMAIL CONFIGURATION
155DEFAULT_FROM_EMAIL = env('DEFAULT_FROM_EMAIL', default='naoresponda@cultura.gov.br')
156EMAIL_HOST = env('EMAIL_HOST', default='localhost')
157EMAIL_PORT = env('EMAIL_PORT', default=1025)
158EMAIL_BACKEND = env('DJANGO_EMAIL_BACKEND', default='django.core.mail.backends.smtp.EmailBackend')
159
160# MANAGER CONFIGURATION
161# See: https://docs.djangoproject.com/en/dev/ref/settings/#admins
162ADMINS = (
163 ("""Your Name""", 'Your email'),
164)
165
166CACHES = {
167 'default': {
168 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
169 'LOCATION': ''
170 }
171}
172
173# See: https://docs.djangoproject.com/en/dev/ref/settings/#managers
174MANAGERS = ADMINS
175
176# DATABASE CONFIGURATION
177# See: https://docs.djangoproject.com/en/dev/ref/settings/#databases
178DATABASES = {
179 'default': env.db("DATABASE_URL", default="postgres://postgres:postgres123@localhost/dbsnc"),
180}
181
182DATABASES['default']['ATOMIC_REQUESTS'] = True
183
184
185# GENERAL CONFIGURATION
186# Local time zone for this installation. Choices can be found here:
187# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
188# although not all choices may be available on all operating systems.
189# In a Windows environment this must be set to your system time zone.
190TIME_ZONE = 'America/Sao_Paulo'
191
192# See: https://docs.djangoproject.com/en/dev/ref/settings/#language-code
193LANGUAGE_CODE = 'pt-br'
194
195# See: https://docs.djangoproject.com/en/dev/ref/settings/#site-id
196SITE_ID = 2
197
198# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-i18n
199USE_I18N = True
200
201# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-l10n
202USE_L10N = True
203
204# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-tz
205USE_TZ = True
206
207# TEMPLATE CONFIGURATION
208# See: https://docs.djangoproject.com/en/dev/ref/settings/#templates
209TEMPLATES = [
210 {
211 # See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-TEMPLATES-BACKEND
212 'BACKEND': 'django.template.backends.django.DjangoTemplates',
213 # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs
214 'DIRS': [
215 str(ROOT_DIR.path('snc/templates')),
216 ],
217 'OPTIONS': {
218 # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-debug
219 'debug': DEBUG,
220 # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-loaders
221 # https://docs.djangoproject.com/en/dev/ref/templates/api/#loader-types
222 'loaders': [
223 'django.template.loaders.filesystem.Loader',
224 'django.template.loaders.app_directories.Loader',
225 ],
226 # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors
227 'context_processors': [
228 'django.template.context_processors.debug',
229 'django.template.context_processors.request',
230 'django.contrib.auth.context_processors.auth',
231 # 'allauth.account.context_processors.account',
232 # 'allauth.socialaccount.context_processors.socialaccount',
233 'django.template.context_processors.i18n',
234 'django.template.context_processors.media',
235 'django.template.context_processors.static',
236 'django.template.context_processors.tz',
237 'django.contrib.messages.context_processors.messages',
238 # Your stuff: custom template context processors go here
239 ],
240 },
241 },
242]
243
244# STATIC FILE CONFIGURATION
245# ------------------------------------------------------------------------------
246# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-root
247STATIC_ROOT = str(ROOT_DIR('staticfiles'))
248
249# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url
250STATIC_URL = '/static/'
251
252# See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
253STATICFILES_DIRS = (
254 str(ROOT_DIR.path('snc/static')),
255)
256
257# See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders
258STATICFILES_FINDERS = (
259 'django.contrib.staticfiles.finders.FileSystemFinder',
260 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
261)
262
263# MEDIA CONFIGURATION
264# ------------------------------------------------------------------------------
265# See: https://docs.djangoproject.com/en/dev/ref/settings/#media-root
266MEDIA_ROOT = str(ROOT_DIR('media'))
267FILE_UPLOAD_PERMISSIONS = 0o644
268
269# See: https://docs.djangoproject.com/en/dev/ref/settings/#media-url
270MEDIA_URL = '/media/'
271
272# URL Configuration
273# ------------------------------------------------------------------------------
274ROOT_URLCONF = 'snc.urls'
275
276# See: https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application
277# WSGI_APPLICATION = 'config.wsgi.application'
278
279# AUTHENTICATION CONFIGURATION
280# ------------------------------------------------------------------------------
281AUTHENTICATION_BACKENDS = (
282 'django.contrib.auth.backends.ModelBackend',
283 # 'allauth.account.auth_backends.AuthenticationBackend',
284)
285
286# Some really nice defaults
287# ACCOUNT_AUTHENTICATION_METHOD = 'username'
288# ACCOUNT_EMAIL_REQUIRED = True
289# ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
290
291# Custom user app defaults
292# Select the correct user model
293# AUTH_USER_MODEL = 'users.User'
294LOGIN_REDIRECT_URL = 'adesao:home'
295LOGIN_URL = 'adesao:login'
296LOGOUT_URL = 'adesao:logout'
297
298# Your common stuff: Below this line define 3rd party library settings
299USE_DJANGO_JQUERY = False
300JQUERY_URL = STATIC_URL + 'js/jquery.min.js'
301
302CKEDITOR_JQUERY_URL = JQUERY_URL
303CKEDITOR_UPLOAD_PATH = 'uploads/'
304CKEDITOR_CONFIGS = {
305 'default': {
306 'toolbar': 'Custom',
307 'toolbar_Custom': [
308 ['Bold', 'Italic', 'Underline'],
309 ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'],
310 ['Link', 'Unlink'],
311 ['RemoveFormat', 'Source']
312 ]
313 },
314}
315
316PIWIK_SITE_ID = 1
317PIWIK_URL = ''
318
319if env("SENTRY_DSN"):
320 sentry_sdk.init(
321 dsn=env("SENTRY_DSN"),
322 integrations=[DjangoIntegration()],
323 send_default_pii=True
324 )