|
@@ -1,82 +1,34 @@
|
1
|
1
|
"""
|
2
|
|
-Django settings for this project.
|
|
2
|
+Django settings for pygal project.
|
3
|
3
|
|
4
|
|
-Generated by 'django-admin startproject' using Django 3.0.3.
|
|
4
|
+Generated by 'django-admin startproject' using Django 5.1.1.
|
5
|
5
|
|
6
|
6
|
For more information on this file, see
|
7
|
|
-https://docs.djangoproject.com/en/3.0/topics/settings/
|
|
7
|
+https://docs.djangoproject.com/en/5.1/topics/settings/
|
8
|
8
|
|
9
|
9
|
For the full list of settings and their values, see
|
10
|
|
-https://docs.djangoproject.com/en/3.0/ref/settings/
|
|
10
|
+https://docs.djangoproject.com/en/5.1/ref/settings/
|
11
|
11
|
"""
|
12
|
12
|
|
|
13
|
+from pathlib import Path
|
|
14
|
+
|
13
|
15
|
import config
|
14
|
16
|
from logging.handlers import SocketHandler as _SocketHandler
|
15
|
17
|
import os
|
|
18
|
+import random
|
16
|
19
|
import stat
|
17
|
20
|
import sys
|
18
|
|
-import random
|
19
|
21
|
|
20
|
|
-try:
|
21
|
|
- from config import APP_NAME as ROOT_LOGGER_NAME
|
22
|
|
-except ImportError:
|
23
|
|
- ROOT_LOGGER_NAME = 'root'
|
|
22
|
+# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
|
23
|
+BASE_DIR = Path(__file__).resolve().parent.parent
|
24
|
24
|
|
25
|
25
|
|
26
|
|
-# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
27
|
|
-#
|
28
|
|
-BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
29
|
|
-
|
30
|
|
-# Check permission of config.py
|
31
|
|
-#
|
32
|
|
-if sys.platform == 'linux' or sys.platform == 'linux2':
|
33
|
|
- st = os.stat(os.path.join(BASE_DIR, 'config.py'))
|
34
|
|
- if st.st_mode & stat.S_IRGRP or st.st_mode & stat.S_IROTH:
|
35
|
|
- raise PermissionError("conig.py is readable by group or others.")
|
36
|
|
-
|
37
|
|
-# Default values, if not defined in config.py
|
38
|
|
-#
|
39
|
|
-USER_CONFIG_DEFAULTS = {
|
40
|
|
- 'DEBUG': False,
|
41
|
|
- 'SECRET_KEY': None,
|
42
|
|
- 'ALLOWED_HOSTS': ['127.0.0.1', ],
|
43
|
|
- 'CSRF_TRUSTED_ORIGINS': [],
|
44
|
|
- 'DEFAULT_THEME': 'clear-red',
|
45
|
|
- 'ITEM_ROOT': os.path.join(BASE_DIR, 'data', 'example_data'),
|
46
|
|
- 'THUMBNAIL_SIZES': [137, 175, 250],
|
47
|
|
- 'WEBNAIL_SIZES': [450, 1100, 1750],
|
48
|
|
- 'SUSPEND_PUBLIC': True,
|
49
|
|
- 'SORT_BY_DATE': True,
|
50
|
|
- 'SHOW_IMAGE': True,
|
51
|
|
- 'SHOW_VIDEO': True,
|
52
|
|
- 'SHOW_AUDIO': False,
|
53
|
|
- 'SHOW_OTHER': False,
|
54
|
|
-}
|
55
|
|
-
|
56
|
|
-# Set configuration parameters
|
57
|
|
-#
|
58
|
|
-thismodule = sys.modules[__name__]
|
59
|
|
-for property_name in USER_CONFIG_DEFAULTS:
|
60
|
|
- try:
|
61
|
|
- value = getattr(config, property_name)
|
62
|
|
- except AttributeError:
|
63
|
|
- value = USER_CONFIG_DEFAULTS[property_name]
|
64
|
|
- setattr(thismodule, property_name, value)
|
65
|
|
-
|
66
|
26
|
# Quick-start development settings - unsuitable for production
|
67
|
|
-# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
|
68
|
|
-
|
69
|
|
-# SECURITY WARNING: keep the secret key used in production secret!
|
70
|
|
-#
|
71
|
|
-if SECRET_KEY is None:
|
72
|
|
- chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
|
73
|
|
- s_key = ''.join([random.choice(chars) for n in range(50)])
|
74
|
|
- secret_key_warning = "You need to create a config.py file including at least a SECRET_KEY definition (e.g.: --> %s <--)." % repr(s_key)
|
75
|
|
- raise KeyError(secret_key_warning)
|
|
27
|
+# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/
|
76
|
28
|
|
77
|
29
|
|
78
|
30
|
# Application definition
|
79
|
|
-#
|
|
31
|
+
|
80
|
32
|
INSTALLED_APPS = [
|
81
|
33
|
'pygal.apps.PygalConfig',
|
82
|
34
|
'themes.apps.ThemesConfig',
|
|
@@ -124,19 +76,19 @@ WSGI_APPLICATION = 'main.wsgi.application'
|
124
|
76
|
|
125
|
77
|
|
126
|
78
|
# Database
|
127
|
|
-# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
|
128
|
|
-#
|
|
79
|
+# https://docs.djangoproject.com/en/5.1/ref/settings/#databases
|
|
80
|
+
|
129
|
81
|
DATABASES = {
|
130
|
82
|
'default': {
|
131
|
83
|
'ENGINE': 'django.db.backends.sqlite3',
|
132
|
|
- 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
|
|
84
|
+ 'NAME': BASE_DIR / 'db.sqlite3',
|
133
|
85
|
}
|
134
|
86
|
}
|
135
|
87
|
|
136
|
88
|
|
137
|
89
|
# Password validation
|
138
|
|
-# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
|
139
|
|
-#
|
|
90
|
+# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators
|
|
91
|
+
|
140
|
92
|
AUTH_PASSWORD_VALIDATORS = [
|
141
|
93
|
{
|
142
|
94
|
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
|
@@ -153,14 +105,9 @@ AUTH_PASSWORD_VALIDATORS = [
|
153
|
105
|
]
|
154
|
106
|
|
155
|
107
|
|
156
|
|
-# Search Engine
|
157
|
|
-#
|
158
|
|
-WHOOSH_PATH = os.path.join(BASE_DIR, 'data', 'whoosh_index')
|
159
|
|
-
|
160
|
|
-
|
161
|
108
|
# Internationalization
|
162
|
|
-# https://docs.djangoproject.com/en/3.0/topics/i18n/
|
163
|
|
-#
|
|
109
|
+# https://docs.djangoproject.com/en/5.1/topics/i18n/
|
|
110
|
+
|
164
|
111
|
LANGUAGE_CODE = 'en-us'
|
165
|
112
|
LANGUAGES = [
|
166
|
113
|
('en', 'English'),
|
|
@@ -182,25 +129,90 @@ USE_TZ = True
|
182
|
129
|
|
183
|
130
|
|
184
|
131
|
# Static files (CSS, JavaScript, Images)
|
185
|
|
-# https://docs.djangoproject.com/en/3.0/howto/static-files/
|
186
|
|
-#
|
|
132
|
+# https://docs.djangoproject.com/en/5.1/howto/static-files/
|
187
|
133
|
STATIC_ROOT = os.path.join(BASE_DIR, 'data', 'static')
|
188
|
|
-STATIC_URL = '/static/'
|
|
134
|
+STATIC_URL = 'static/'
|
189
|
135
|
|
190
|
136
|
MEDIA_ROOT = os.path.join(BASE_DIR, 'data', 'media')
|
191
|
137
|
MEDIA_URL = '/media/'
|
192
|
138
|
|
|
139
|
+WHOOSH_PATH = os.path.join(BASE_DIR, 'data', 'whoosh')
|
193
|
140
|
|
194
|
|
-# Session parameters
|
|
141
|
+# Default primary key field type
|
|
142
|
+# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
|
|
143
|
+
|
|
144
|
+DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+# Other Configuration issues
|
195
|
149
|
#
|
|
150
|
+DATA_UPLOAD_MAX_NUMBER_FIELDS = 30000
|
196
|
151
|
|
|
152
|
+LOGIN_URL = 'users-login'
|
|
153
|
+
|
|
154
|
+XNAIL_ROOT = os.path.join(BASE_DIR, 'data', 'xnails')
|
|
155
|
+TEMP_ROOT = os.path.join(BASE_DIR, 'data', 'temp')
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+# Session parameters
|
|
159
|
+#
|
197
|
160
|
SESSION_KEY_THUMBNAIL_SIZE = 'thumbnail_size'
|
198
|
161
|
SESSION_KEY_WEBNAIL_SIZE = 'webnail_size'
|
199
|
162
|
PERSISTENT_SESSION_VARIABLES = [SESSION_KEY_THUMBNAIL_SIZE, SESSION_KEY_WEBNAIL_SIZE]
|
200
|
163
|
|
201
|
164
|
|
|
165
|
+# Check permission of config.py
|
|
166
|
+#
|
|
167
|
+if sys.platform == 'linux' or sys.platform == 'linux2':
|
|
168
|
+ st = os.stat(os.path.join(BASE_DIR, 'config.py'))
|
|
169
|
+ if st.st_mode & stat.S_IRGRP or st.st_mode & stat.S_IROTH:
|
|
170
|
+ raise PermissionError("conig.py is readable by group or others.")
|
|
171
|
+
|
|
172
|
+# Default values, if not defined in config.py
|
|
173
|
+#
|
|
174
|
+USER_CONFIG_DEFAULTS = {
|
|
175
|
+ 'ITEM_ROOT': os.path.join(BASE_DIR, 'data', 'example_data'),
|
|
176
|
+ 'SUSPEND_PUBLIC': True,
|
|
177
|
+ 'DEBUG': False,
|
|
178
|
+ 'SECRET_KEY': None,
|
|
179
|
+ 'DEFAULT_THEME': 'clear-red',
|
|
180
|
+ 'ALLOWED_HOSTS': ['127.0.0.1', 'localhost', ],
|
|
181
|
+ 'CSRF_TRUSTED_ORIGINS': [],
|
|
182
|
+ 'THUMBNAIL_SIZES': [137, 175, 250],
|
|
183
|
+ 'WEBNAIL_SIZES': [450, 1100, 1750],
|
|
184
|
+ 'SORT_BY_DATE': True,
|
|
185
|
+ 'SHOW_IMAGE': True,
|
|
186
|
+ 'SHOW_VIDEO': True,
|
|
187
|
+ 'SHOW_AUDIO': False,
|
|
188
|
+ 'SHOW_OTHER': False,
|
|
189
|
+}
|
|
190
|
+
|
|
191
|
+# Set configuration parameters
|
|
192
|
+#
|
|
193
|
+thismodule = sys.modules[__name__]
|
|
194
|
+for property_name in USER_CONFIG_DEFAULTS:
|
|
195
|
+ try:
|
|
196
|
+ value = getattr(config, property_name)
|
|
197
|
+ except AttributeError:
|
|
198
|
+ value = USER_CONFIG_DEFAULTS[property_name]
|
|
199
|
+ setattr(thismodule, property_name, value)
|
|
200
|
+
|
|
201
|
+# SECURITY WARNING: keep the secret key used in production secret!
|
|
202
|
+#
|
|
203
|
+if SECRET_KEY is None:
|
|
204
|
+ chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
|
|
205
|
+ s_key = ''.join([random.choice(chars) for n in range(50)])
|
|
206
|
+ secret_key_warning = "You need to create a config.py file including at least a SECRET_KEY definition (e.g.: --> %s <--)." % repr(s_key)
|
|
207
|
+ raise KeyError(secret_key_warning)
|
|
208
|
+
|
|
209
|
+
|
202
|
210
|
# Logging Configuration
|
203
|
211
|
#
|
|
212
|
+ROOT_LOGGER_NAME = os.path.basename(os.path.dirname(__file__))
|
|
213
|
+default_handler = ['socket', 'console'] if DEBUG else ['console']
|
|
214
|
+
|
|
215
|
+
|
204
|
216
|
class DjangoSocketHandler(_SocketHandler):
|
205
|
217
|
def emit(self, record):
|
206
|
218
|
if hasattr(record, 'request'):
|
|
@@ -208,8 +220,6 @@ class DjangoSocketHandler(_SocketHandler):
|
208
|
220
|
return super().emit(record)
|
209
|
221
|
|
210
|
222
|
|
211
|
|
-default_handler = ['socket'] if DEBUG else ['console']
|
212
|
|
-#
|
213
|
223
|
LOGGING = {
|
214
|
224
|
'version': 1,
|
215
|
225
|
'disable_existing_loggers': False,
|
|
@@ -233,7 +243,7 @@ File "%(pathname)s", line %(lineno)d, in %(funcName)s
|
233
|
243
|
},
|
234
|
244
|
'socket': {
|
235
|
245
|
'level': 'DEBUG',
|
236
|
|
- 'class': 'main.settings.DjangoSocketHandler',
|
|
246
|
+ 'class': f'{ROOT_LOGGER_NAME}.settings.DjangoSocketHandler',
|
237
|
247
|
'host': '127.0.0.1',
|
238
|
248
|
'port': 19996,
|
239
|
249
|
},
|
|
@@ -251,14 +261,3 @@ File "%(pathname)s", line %(lineno)d, in %(funcName)s
|
251
|
261
|
},
|
252
|
262
|
},
|
253
|
263
|
}
|
254
|
|
-
|
255
|
|
-
|
256
|
|
-# Other Configuration issues
|
257
|
|
-#
|
258
|
|
-
|
259
|
|
-DATA_UPLOAD_MAX_NUMBER_FIELDS = 30000
|
260
|
|
-
|
261
|
|
-LOGIN_URL = 'users-login'
|
262
|
|
-
|
263
|
|
-XNAIL_ROOT = os.path.join(BASE_DIR, 'data', 'xnails')
|
264
|
|
-TEMP_ROOT = os.path.join(BASE_DIR, 'data', 'temp')
|