-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsettings.py
More file actions
448 lines (379 loc) · 13.7 KB
/
Copy pathsettings.py
File metadata and controls
448 lines (379 loc) · 13.7 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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
import os
from pathlib import Path
import django
from django.utils.encoding import smart_str
django.utils.encoding.smart_text = smart_str
import django.utils.translation as original_translation
from django.utils.translation import gettext_lazy
original_translation.ugettext_lazy = gettext_lazy
from django.utils.encoding import force_str
django.utils.encoding.force_text = force_str
from dotenv import load_dotenv
load_dotenv() # take environment variables
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-s$(*=)6^h$p=d6e4tpv#-s7_hg&cl!vc@yzas371ubj=+ks&cc'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.environ.get('DEBUG', 'True') == 'True'
print(f'DEBUG: {DEBUG}')
ENV = os.environ.get('ENV', 'local')
print(f'ENV: {ENV}')
ALLOWED_HOSTS = [
'127.0.0.1',
'localhost',
'bonos.fa2022.org',
'eventos.fuegoaustral.org',
os.environ.get('EXTRA_HOST')
]
print(f'ALLOWED_HOSTS: {ALLOWED_HOSTS}')
APP_URL = os.environ.get('APP_URL', 'http://localhost:8000')
print(f'APP_URL: {APP_URL}')
# Application definition
AUTHENTICATION_BACKENDS = [
# Needed to login by username in Django admin, regardless of `allauth`
'django.contrib.auth.backends.ModelBackend',
# `allauth` specific authentication methods, such as login by email
'allauth.account.auth_backends.AuthenticationBackend',
]
INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.humanize',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'bootstrap5',
'django_inlinecss',
'django_s3_storage',
'auditlog',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.google',
'import_export',
'django_ckeditor_5',
'user_profile.apps.UserProfileConfig',
'tickets.apps.TicketsConfig',
'events.apps.EventsConfig',
'espaciozen.apps.EspaciozenConfig',
'caja.apps.CajaConfig',
'logros.apps.LogrosConfig',
]
MIDDLEWARE = [
'utils.loggerMiddleware.LoggerMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'auditlog.middleware.AuditlogMiddleware',
"allauth.account.middleware.AccountMiddleware",
'tickets.middleware.ProfileCompletionMiddleware',
'tickets.middleware.DeviceDetectionMiddleware'
]
ROOT_URLCONF = 'deprepagos.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, 'tickets/templates'),
os.path.join(BASE_DIR, 'user_profile/templates'),
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'utils.context_processors.current_event',
'utils.context_processors.app_url',
'utils.context_processors.chatwoot_token',
'utils.context_processors.env',
'utils.context_processors.chatwoot_identifier_hash',
'utils.context_processors.pending_terms_and_conditions',
'caja.context_processors.cajas_v2_menu',
],
},
},
]
WSGI_APPLICATION = 'deprepagos.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
db_host = os.environ.get('DB_HOST', '127.0.0.1')
db_sslmode = os.environ.get('DB_SSLMODE')
if not db_sslmode and db_host not in ('127.0.0.1', 'localhost'):
# Most managed PostgreSQL instances (RDS/Supabase) require encrypted connections.
db_sslmode = 'require'
db_options = {}
if db_sslmode:
db_options['sslmode'] = db_sslmode
db_connect_timeout = os.environ.get('DB_CONNECT_TIMEOUT')
if db_connect_timeout:
db_options['connect_timeout'] = int(db_connect_timeout)
elif db_host not in ('127.0.0.1', 'localhost'):
# Fail fast instead of hanging when remote DB access is blocked.
db_options['connect_timeout'] = 10
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': os.environ.get('DB_DATABASE', 'deprepagos'),
'USER': os.environ.get('DB_USER', 'mauro'),
'PASSWORD': os.environ.get('DB_PASSWORD', ''),
'HOST': db_host,
'PORT': os.environ.get('DB_PORT', '5432'),
'OPTIONS': db_options,
}
}
print(f'DATABASE HOST: {DATABASES["default"]["HOST"]}')
# Password validation
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/
LANGUAGE_CODE = 'es-AR'
TIME_ZONE = 'America/Argentina/Buenos_Aires'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'media')
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
MERCADOPAGO = {
'PUBLIC_KEY': os.environ.get('MERCADOPAGO_PUBLIC_KEY'),
'ACCESS_TOKEN': os.environ.get('MERCADOPAGO_ACCESS_TOKEN'),
'WEBHOOK_SECRET': os.environ.get('MERCADOPAGO_WEBHOOK_SECRET'),
'COLLECTOR_USER_ID': os.environ.get('MERCADOPAGO_COLLECTOR_USER_ID'),
}
SEDE_SUBSCRIPTION_PLAN_IDS = [
plan_id.strip()
for plan_id in os.environ.get('SUBS_IDS', '').split(',')
if plan_id.strip()
]
SEDE_DEFAULT_PLAN_ID = '2c9380847dbdc0a1017dbe5e16a1005c'
EMAIL_HOST = os.environ.get('EMAIL_HOST')
EMAIL_HOST_USER = os.environ.get('EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD')
EMAIL_PORT = os.environ.get('EMAIL_PORT')
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = os.environ.get('DEFAULT_FROM_EMAIL', 'Fuego Austral <bonos@eventos.fuegoaustral.org>').replace('"',
'').replace(
"'", '')
TEMPLATED_EMAIL_TEMPLATE_DIR = 'emails/'
TEMPLATED_EMAIL_FILE_EXTENSION = 'html'
TWILIO_ACCOUNT_SID = os.environ.get('TWILIO_ACCOUNT_SID', '')
TWILIO_AUTH_TOKEN = os.environ.get('TWILIO_AUTH_TOKEN', '')
TWILIO_VERIFY_SERVICE_SID = os.environ.get('TWILIO_VERIFY_SERVICE_SID', '')
SOCIALACCOUNT_PROVIDERS = {
'google': {
'SCOPE': [
'email',
],
'APP': {
'client_id': os.environ.get('GOOGLE_CLIENT_ID', ''),
'secret': os.environ.get('GOOGLE_SECRET', '')
}
}
}
try:
from deprepagos.local_settings import *
INSTALLED_APPS.extend(EXTRA_INSTALLED_APPS)
except ImportError:
# using print and not log here as logging is yet not configured
print('local settings not found')
pass
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
},
'root': {
'handlers': ['console'],
'level': 'DEBUG',
},
'loggers': {
'caja.http': {
'handlers': ['console'],
'level': 'DEBUG',
'propagate': False,
},
'botocore': {
'level': 'ERROR', # Change to ERROR to reduce logs
'handlers': ['console'],
'propagate': False,
},
's3transfer': {
'level': 'ERROR', # Change to ERROR to reduce logs
'handlers': ['console'],
'propagate': False,
},
'': {
'handlers': ['console'],
'level': os.getenv('DJANGO_LOG_LEVEL', 'DEBUG'),
'propagate': False,
}
},
}
# ENABLE DEBUG LOGGING FOR DATABASE QUERIES
# if ENV == 'local':
# LOGGING['loggers']['django.db'] = {
# 'level': 'DEBUG'
# }
AUTH_PASSWORD_VALIDATORS = [
{
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
"OPTIONS": {
"min_length": 8,
},
}
]
# Email settings
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_USER_MODEL_USERNAME_FIELD = None
# Login settings
LOGIN_REDIRECT_URL = 'mi_fuego'
LOGIN_URL = '/mi-fuego/login/'
ACCOUNT_LOGOUT_REDIRECT_URL = APP_URL
ACCOUNT_AUTHENTICATION_METHOD = 'email' # 'username_email', 'username'
ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS = 3
SOCIALACCOUNT_EMAIL_AUTHENTICATION = True
SOCIALACCOUNT_LOGIN_ON_GET = True
ACCOUNT_LOGOUT_ON_GET = True
ACCOUNT_CONFIRM_EMAIL_ON_GET = True
ACCOUNT_LOGIN_ON_EMAIL_CONFIRMATION = True
# Disable automatic messages for login/logout
ACCOUNT_MESSAGE_TEMPLATE = None
ACCOUNT_DEFAULT_HTTP_PROTOCOL = (
"http" if "localhost" in APP_URL or "127.0.0.1" in APP_URL else "https"
)
CSRF_TRUSTED_ORIGINS = [APP_URL]
CHATWOOT_TOKEN = os.environ.get('CHATWOOT_TOKEN')
CHATWOOT_IDENTITY_VALIDATION = os.environ.get('CHATWOOT_IDENTITY_VALIDATION')
CHATWOOT_BASE_URL = os.environ.get('CHATWOOT_BASE_URL', 'https://app.chatwoot.com')
CHATWOOT_API_ACCESS_TOKEN = os.environ.get('CHATWOOT_API_ACCESS_TOKEN', '')
CHATWOOT_ACCOUNT_ID = os.environ.get('CHATWOOT_ACCOUNT_ID', '')
CHATWOOT_SOPORTE_INBOX_ID = os.environ.get('CHATWOOT_SOPORTE_INBOX_ID', '')
# Agente que recibe asignación (opcional; útil si el inbox es WebWidget)
CHATWOOT_SOPORTE_ASSIGNEE_ID = os.environ.get('CHATWOOT_SOPORTE_ASSIGNEE_ID', '')
SECRET = os.environ.get('SECRET')
MOCK_PHONE_VERIFICATION = os.environ.get('ENV') == 'local'
DISABLE_PHONE_VERIFICATION = 'True'
# CKEditor 5 Configuration
customColorPalette = [
{
'color': 'hsl(4, 90%, 58%)',
'label': 'Red'
},
{
'color': 'hsl(340, 82%, 52%)',
'label': 'Pink'
},
{
'color': 'hsl(291, 64%, 42%)',
'label': 'Purple'
},
{
'color': 'hsl(262, 52%, 47%)',
'label': 'Deep Purple'
},
{
'color': 'hsl(231, 48%, 48%)',
'label': 'Indigo'
},
{
'color': 'hsl(207, 90%, 54%)',
'label': 'Blue'
},
]
CKEDITOR_5_CONFIGS = {
'default': {
'toolbar': ['heading', '|', 'bold', 'italic', 'link',
'bulletedList', 'numberedList', 'blockQuote', 'imageUpload', ],
},
'extends': {
'blockToolbar': [
'paragraph', 'heading1', 'heading2', 'heading3',
'|',
'bulletedList', 'numberedList',
'|',
'blockQuote',
],
'toolbar': ['heading', '|', 'outdent', 'indent', '|', 'bold', 'italic', 'link', 'underline', 'strikethrough',
'code','subscript', 'superscript', 'highlight', '|', 'codeBlock', 'sourceEditing', '|', 'bulletedList', 'numberedList', 'todoList', '|', 'blockQuote', 'insertTable', '|',
'fontSize', 'fontFamily', 'fontColor', 'fontBackgroundColor', 'mediaEmbed', 'removeFormat', 'insertHorizontalRule', 'specialCharacters', '|',
'alignment', '|', 'linkImage', 'uploadImage', '|', 'undo', 'redo'],
'image': {
'toolbar': ['imageTextAlternative', '|', 'imageStyle:alignLeft',
'imageStyle:alignRight', 'imageStyle:alignCenter', 'imageStyle:side', '|'],
'styles': [
'full',
'side',
'alignLeft',
'alignRight',
'alignCenter',
]
},
'table': {
'contentToolbar': [ 'tableColumn', 'tableRow', 'mergeTableCells',
'tableProperties', 'tableCellProperties' ],
'tableProperties': {
'borderColors': customColorPalette,
'backgroundColors': customColorPalette
},
'tableCellProperties': {
'borderColors': customColorPalette,
'backgroundColors': customColorPalette
}
},
'heading' : {
'options': [
{ 'model': 'paragraph', 'title': 'Paragraph', 'class': 'ck-heading_paragraph' },
{ 'model': 'heading1', 'view': 'h1', 'title': 'Heading 1', 'class': 'ck-heading_heading1' },
{ 'model': 'heading2', 'view': 'h2', 'title': 'Heading 2', 'class': 'ck-heading_heading2' },
{ 'model': 'heading3', 'view': 'h3', 'title': 'Heading 3', 'class': 'ck-heading_heading3' }
]
}
},
'list': {
'properties': {
'styles': 'true',
'startIndex': 'true',
'reversed': 'true',
}
}
}