· 4 years ago · May 15, 2021, 12:26 PM
1"""
2Django settings for GenericProject project.
3
4Generated by 'django-admin startproject' using Django 2.2.7.
5
6For more information on this file, see
7https://docs.djangoproject.com/en/2.2/topics/settings/
8
9For the full list of settings and their values, see
10https://docs.djangoproject.com/en/2.2/ref/settings/
11"""
12
13import os
14
15# per le traduzioni e help from smart_selects.db_fields import ChainedManyToManyField
16from django.utils.translation import gettext_lazy as _
17
18# from django.contrib.messages import constants as messages
19
20# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
21BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
22
23
24# Quick-start development settings - unsuitable for production
25# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
26
27# SECURITY WARNING: keep the secret key used in production secret!
28SECRET_KEY = '0=%+z+a1^h!ioc86n6q!ifkhx!&w0d@&8__m3qv)y2x(&dmron'
29
30# SECURITY WARNING: don't run with debug turned on in production!
31DEBUG = True
32
33ALLOWED_HOSTS = ['*']
34
35
36# Application definition
37
38INSTALLED_APPS = [
39
40 # Django Core Apps
41 'django.contrib.admin',
42 'django.contrib.auth',
43 'django.contrib.contenttypes',
44 'django.contrib.sessions',
45 'django.contrib.messages',
46 'django.contrib.staticfiles',
47 'django.contrib.sites',
48
49 # Third Party Apps
50 'crispy_forms', # pip install --upgrade pip
51 "crispy_bootstrap5",
52 'clear_cache',
53 'ckeditor',
54 'ckeditor_uploader',
55 'captcha',
56
57 'rest_framework',
58 'rest_framework.authtoken', # ci mette a disposizione l'app di gestione dei token
59 'rest_auth', # ci fornirà degli endpoint per il login e la registrazione via REST
60 'rest_auth.registration',
61
62 'allauth',
63 'allauth.account',
64 'allauth.socialaccount', # atualmente non usato, ma permetterebbe l'autenticazione tramite canali social
65
66
67 # Frontend Apps
68 'core',
69 'users',
70 'profiles',
71 'appModuli',
72 'appForum',
73 'appLibri',
74 'appEventi',
75 'appNews',
76 'appContatti',
77 # 'appAccessi', --> spostata la gestione direttaente nell'app principale GenericProject
78 'products',
79 'madCook',
80
81
82]
83
84
85# MESSAGE_STORAGE = 'django.contrib.messages.storage.cookie.CookieStorage'
86# MESSAGE_TAGS = {
87# messages.DEBUG: 'alert-info',
88# messages.INFO: 'alert-info',
89# messages.SUCCESS: 'alert-success',
90# messages.WARNING: 'alert-warning',
91# messages.ERROR: 'alert-danger',
92# }
93
94MIDDLEWARE = [
95 'django.middleware.security.SecurityMiddleware',
96 'django.contrib.sessions.middleware.SessionMiddleware',
97 # per attivare il multilanguage: va dopo session dato che usa le sessioni e va prima di common dato che common
98 # necessita le lingue attive per risolvere gli url
99 'django.middleware.locale.LocaleMiddleware',
100 'django.middleware.common.CommonMiddleware',
101 'django.middleware.csrf.CsrfViewMiddleware',
102 'django.contrib.auth.middleware.AuthenticationMiddleware',
103 'django.contrib.messages.middleware.MessageMiddleware',
104 'django.middleware.clickjacking.XFrameOptionsMiddleware',
105]
106
107
108ROOT_URLCONF = 'GenericProject.urls'
109
110TEMPLATES = [
111 {
112 'BACKEND': 'django.template.backends.django.DjangoTemplates',
113 'DIRS': [os.path.join(BASE_DIR, 'templates'),
114 os.path.join(BASE_DIR, 'core/templates'),
115 os.path.join(BASE_DIR, 'appModuli/templates'),
116 # os.path.join(BASE_DIR, 'appAccessi/templates'),
117 os.path.join(BASE_DIR, 'users/templates'),
118 os.path.join(BASE_DIR, 'appLibri/templates'),
119 os.path.join(BASE_DIR, 'appForum/templates'),
120 os.path.join(BASE_DIR, 'products/templates')
121 ],
122 'APP_DIRS': True,
123 'OPTIONS': {
124 'context_processors': [
125 'django.template.context_processors.debug',
126 'django.template.context_processors.request',
127 'django.contrib.auth.context_processors.auth',
128 'django.contrib.messages.context_processors.messages',
129 'django.template.context_processors.media',
130 ],
131 },
132 },
133]
134
135
136WSGI_APPLICATION = 'GenericProject.wsgi.application'
137
138
139# Database
140# https://docs.djangoproject.com/en/2.2/ref/settings/#databases
141
142DATABASES = {
143 'default': {
144 'ENGINE': 'django.db.backends.sqlite3',
145 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
146 }
147}
148
149
150# Password validation
151# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
152
153AUTH_PASSWORD_VALIDATORS = [
154 {
155 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
156 },
157 {
158 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
159 },
160 {
161 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
162 },
163 {
164 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
165 },
166]
167
168
169# Internationalization
170# https://docs.djangoproject.com/en/2.2/topics/i18n/
171
172LANGUAGE_CODE = 'en' # 'it-IT'
173LANGUAGES = [
174 ('it', _('Italian')),
175 ('en', _('English')),
176]
177
178DATETIME_INPUT_FORMATS = ['%d/%m/%Y %H:%M'] # '10/25/2006 14:30'
179DATE_INPUT_FORMATS = ['%d-%m-%Y'] # '10 ott. 2006'
180DATE_FORMATS = ['%d-%m-%Y']
181
182TIME_ZONE = 'UTC'
183
184USE_I18N = True
185# andrebbe messo a true per la multilocalizzazione: capire come fare col DATE_FORMATS
186USE_L10N = True # False #messo a false perchè ha la precedenza sul date_format
187
188USE_TZ = True
189
190
191# URL di default a cui si viene rimandati dopo una corretta login
192# settings forniti da django.contrib.auth.urls (gli url sono definiti nell'app users)
193LOGIN_REDIRECT_URL = "/"
194LOGOUT_REDIRECT_URL = "/"
195LOGIN_URL = "/accounts/login"
196
197# Da usare solo in fase di sviluppo per emulare le mail inviate a console
198# EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
199EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
200
201
202EMAIL_USE_TLS = True
203EMAIL_USE_SSL = False
204# EMAIL_HOST = 'authsmtp.securemail.pro'
205EMAIL_HOST = "smtp.gmail.com"
206EMAIL_PORT = 587 # 465
207EMAIL_HOST_USER = "lucabellomi@gmail.com"
208EMAIL_HOST_PASSWORD = "ihxrxcebjkeevtjb"
209
210# EMAIL_HOST_USER = 'info@madlyuk.it'
211# EMAIL_HOST_PASSWORD = 'madlyuk@7777M107064'
212DEFAULT_FROM_EMAIL = 'noreplay@madlyuk.it'
213DEFAULT_TO_EMAIL = 'info@madlyuk.it'
214
215# Static files (CSS, JavaScript, Images)
216# https://docs.djangoproject.com/en/2.2/howto/static-files/
217
218STATICFILES_DIRS = [
219 os.path.join(BASE_DIR, 'static'),
220 os.path.join(BASE_DIR, 'core/static'),
221 os.path.join(BASE_DIR, 'appForum/static'),
222 os.path.join(BASE_DIR, 'appEventi/static')
223]
224
225# DECOMMENTARE LA PRIMA CONFIGURAZIONE E ABILITARE LA SECONDA QUANDO SIAMO IN PRODUZIONE:
226STATIC_URL = '/static/'
227STATIC_ROOT = "/home/django/static-serve"
228
229
230
231# la cartella con i media file (img, ecc.) è consigliabile tenerla fuori dalla
232# cartella di progetto nella stessa posizione dove compare il file manage.py..
233# il corso pero' prevede come best-practices di tenerla fuori dal progetto a livello della cartella v_env
234# MEDIA_ROOT = os.path.join(BASE_DIR, 'media-serve')
235# MEDIA_URL = '/media/'
236MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'media-serve')
237MEDIA_URL = '/media/'
238
239# Lunghezza massima degli slug che altrimenti di deafaul hanno un limite di 50 caratteri
240SLUG_MAX_LENGTH = 120
241
242# Custom User Model
243AUTH_USER_MODEL = "users.CustomUser"
244
245
246# django-contrib-site
247SITE_ID = 1
248
249# django-allauth
250ACCOUNT_EMAIL_VERIFICATION = "none"
251ACCOUNT_EMAIL_REQUIRED = (True)
252
253###################################
254
255REST_FRAMEWORK = {
256 'DEFAULT_AUTHENTICATION_CLASSES': (
257 'rest_framework.authentication.TokenAuthentication',
258 'rest_framework.authentication.SessionAuthentication',
259 ),
260 # 'DEFAULT_PERMISSION_CLASSES': (
261 # 'rest_framework.permissions.IsAuthenticated',
262 # ),
263 # 'PAGE_SIZE': 2,
264 # 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
265}
266
267
268####################################
269## CKEDITOR CONFIGURATION ##
270####################################
271
272CKEDITOR_JQUERY_URL = 'https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js'
273CKEDITOR_UPLOAD_SLUGIFY_FILENAME = True
274CKEDITOR_UPLOAD_PATH = 'ckeditor_uploads' # 'uploads/' --> i file allegati vengono caricati ma poi non si riescono aprire: mettendo la stringa vuota dovrebbe funzionare come media_url
275CKEDITOR_IMAGE_BACKEND = "pillow"
276#CKEDITOR_BROWSE_SHOW_DIRS = True
277
278
279# CKEDITOR_CONFIGS = {
280# 'default': {
281# 'toolbar': None,
282# },
283# }
284# CKEDITOR_CONFIGS = {
285# 'default': {
286# 'toolbar': 'Custom',
287# 'toolbar_Custom': [
288# ['Bold', 'Italic', 'Underline'],
289# ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-',
290# 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'],
291# ['Link', 'Unlink'],
292# ['RemoveFormat', 'Source']
293# ]
294# }
295# }
296
297CKEDITOR_CONFIGS = {
298 'default': {
299 'skin': 'Moono-Lisa',
300 # 'skin': 'office2013',
301 'toolbar_Basic': [
302 ['Source', '-', 'Bold', 'Italic']
303 ],
304 'width': 'auto',
305 'toolbar_YourCustomToolbarConfig': [
306 {'name': 'document', 'items': [
307 'Source', '-', 'Save', 'NewPage', 'Preview', 'Print', '-', 'Templates']},
308 {'name': 'clipboard', 'items': [
309 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo']},
310 {'name': 'editing', 'items': [
311 'Find', '-', 'SelectAll']},
312 # {'name': 'forms',
313 # 'items': ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton',
314 # 'HiddenField']},
315 {'name': 'insert',
316 'items': ['Image', 'Table', 'HorizontalRule', 'Smiley', 'SpecialChar', 'PageBreak', 'Iframe']},
317 '/',
318 {'name': 'basicstyles',
319 'items': ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat']},
320 {'name': 'paragraph',
321 'items': ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-']},
322 {'name': 'extra', 'items': ['CodeSnippet']},
323 {'name': 'paragraph',
324 'items': ['Blockquote', 'CreateDiv', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', """'BidiLtr', 'BidiRtl'""",
325 'Language']},
326 {'name': 'links', 'items': ['Link', 'Unlink', 'Anchor']},
327
328 '/',
329 {'name': 'styles', 'items': [
330 'Styles', 'Format', 'Font', 'FontSize']},
331 {'name': 'colors', 'items': ['TextColor', 'BGColor']},
332 {'name': 'tools', 'items': ['Maximize', 'ShowBlocks']},
333 {'name': 'about', 'items': ['Preview']},
334 # '/', # put this to force next toolbar on new line
335 # {'name': 'yourcustomtools', 'items': [
336 # # put the name of your editor.ui.addButton here
337 # 'Preview',
338 # 'Maximize',
339 #
340 # ]},
341 ],
342 'toolbar': 'YourCustomToolbarConfig', # put selected toolbar config here
343 # inizio: abilita il pulsantino di destra nella toolbar che minimizza l'area di testo e la toolbar stessa
344 # questo blocco era originariamente commentato
345 'toolbarGroups': [{ 'name': 'document', 'groups': [ 'mode', 'document', 'doctools' ] }],
346 'height': 291,
347 'width': '100%',
348 'filebrowserWindowHeight': 725,
349 'filebrowserWindowWidth': 940,
350 'toolbarCanCollapse': True,
351 'mathJaxLib': '//cdn.mathjax.org/mathjax/2.2-latest/MathJax.js?config=TeX-AMS_HTML',
352 # fine: abilita il pulsantino di destra nella toolbar che minimizza l'area di testo e la toolbar stessa
353 'tabSpaces': 4,
354 'extraPlugins': ','.join([
355 'uploadimage', # the upload image feature
356 # your extra plugins here
357 'div',
358 'autolink',
359 'autoembed',
360 'embedsemantic',
361 'autogrow',
362 'devtools',
363 'widget',
364 'lineutils',
365 'clipboard',
366 'dialog',
367 'dialogui',
368 'elementspath',
369 'codesnippet',
370 ]),
371 },
372 'none_toolbar': {
373 'toolbar': None,
374 'width': 'auto',
375 },
376 'toolbar_simple': {
377 'skin': 'moono',
378 'toolbar': 'Custom',
379 'width': 'auto',
380 'toolbar_Custom': [
381 ['Bold', 'Italic', 'Underline'],
382 ['NumberedList', 'BulletedList'],
383 ],
384 },
385 'toolbar_basic': {
386 'toolbar': 'Basic',
387 'width': 'auto',
388 },
389 'toolbar_full': {
390 'toolbar': 'full',
391 'width': 'auto',
392 },
393 'toolbar_office': {
394 'skin': 'moono', #'office2013'
395 'toolbar': 'Custom', #selects from below
396 'width': 'auto',
397 'toolbar_Custom': [
398 ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript']
399 ],
400 },
401 'toolbar_custom': {
402 'toolbar': 'Custom',
403 'skin': 'moono-lisa',
404 'width': 'auto',
405 'toolbar_Custom': [
406 ['Bold', 'Italic', 'Underline'],
407 ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-',
408 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'],
409 ['Link', 'Unlink'],
410 ['RemoveFormat', 'Source',],
411 {'name': 'insert', 'items': ['Image', 'Update', 'Table', 'HorizontalRule', 'Smiley', 'SpecialChar']},
412 {'name': 'extra', 'items': ['CodeSnippet']},
413 ],
414 },
415}
416
417###################################
418
419CAPTCHA_CHALLENGE_FUNCT = 'captcha.helpers.math_challenge'
420CAPTCHA_NOISE_FUNCTIONS = ('captcha.helpers.noise_null',)
421
422###################################
423# django-crispy-forms
424
425# CRISPY_TEMPLATE_PACK = 'bootstrap4'
426CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5"
427CRISPY_TEMPLATE_PACK = "bootstrap5"
428
429
430
431