|
@@ -10,13 +10,10 @@ For the full list of settings and their values, see
|
10
|
10
|
https://docs.djangoproject.com/en/2.2/ref/settings/
|
11
|
11
|
"""
|
12
|
12
|
|
13
|
|
-try:
|
14
|
|
- from config import config
|
15
|
|
- # required keys: SECRET_KEY
|
16
|
|
- # optional keys: ALLOWED_HOSTS, DEFAULT_THEME, ITEM_ROOT, THUMBNAIL_SIZES, WEBNAIL_SIZES
|
17
|
|
-except ImportError:
|
18
|
|
- config = {}
|
|
13
|
+import config
|
19
|
14
|
import os
|
|
15
|
+import stat
|
|
16
|
+import sys
|
20
|
17
|
import random
|
21
|
18
|
|
22
|
19
|
|
|
@@ -24,25 +21,55 @@ import random
|
24
|
21
|
#
|
25
|
22
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
26
|
23
|
|
|
24
|
+# Check permission of config.py
|
|
25
|
+#
|
|
26
|
+if sys.platform == 'linux' or sys.platform == 'linux2':
|
|
27
|
+ st = os.stat(os.path.join(BASE_DIR, 'config.py'))
|
|
28
|
+ if st.st_mode & stat.S_IRGRP or st.st_mode & stat.S_IROTH:
|
|
29
|
+ raise PermissionError("conig.py is readable by group or others.")
|
|
30
|
+
|
|
31
|
+# Default values, if not defined in config.py
|
|
32
|
+#
|
|
33
|
+USER_CONFIG_DEFAULTS = {
|
|
34
|
+ 'SECRET_KEY': None,
|
|
35
|
+ 'DEFAULT_THEME': 'clear-red',
|
|
36
|
+ 'ALLOWED_HOSTS': [],
|
|
37
|
+ 'ITEM_ROOT': os.path.join(BASE_DIR, 'data', 'example_data'),
|
|
38
|
+ 'THUMBNAIL_SIZES': [137, 175, 250],
|
|
39
|
+ 'WEBNAIL_SIZES': [450, 1100, 1750],
|
|
40
|
+ 'SUSPEND_PUBLIC': True,
|
|
41
|
+ 'SORT_BY_DATE': True,
|
|
42
|
+ 'SHOW_IMAGE': True,
|
|
43
|
+ 'SHOW_VIDEO': True,
|
|
44
|
+ 'SHOW_AUDIO': False,
|
|
45
|
+ 'SHOW_OTHER': False,
|
|
46
|
+}
|
|
47
|
+
|
|
48
|
+# Set configuration parameters
|
|
49
|
+#
|
|
50
|
+thismodule = sys.modules[__name__]
|
|
51
|
+for property_name in USER_CONFIG_DEFAULTS:
|
|
52
|
+ try:
|
|
53
|
+ value = getattr(config, property_name)
|
|
54
|
+ except AttributeError:
|
|
55
|
+ value = USER_CONFIG_DEFAULTS[property_name]
|
|
56
|
+ setattr(thismodule, property_name, value)
|
27
|
57
|
|
28
|
58
|
# Quick-start development settings - unsuitable for production
|
29
|
59
|
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
|
30
|
60
|
|
31
|
61
|
# SECURITY WARNING: keep the secret key used in production secret!
|
32
|
62
|
#
|
33
|
|
-try:
|
34
|
|
- SECRET_KEY = config['SECRET_KEY']
|
35
|
|
-except KeyError:
|
|
63
|
+if SECRET_KEY is None:
|
36
|
64
|
chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
|
37
|
65
|
s_key = ''.join([random.choice(chars) for n in range(50)])
|
38
|
66
|
secret_key_warning = "You need to create a config.py file including a variable config which is a dict with at least a SECRET_KEY definition (e.g.: %s)." % repr(s_key)
|
39
|
67
|
raise KeyError(secret_key_warning)
|
|
68
|
+
|
40
|
69
|
# SECURITY WARNING: don't run with debug turned on in production!
|
41
|
70
|
#
|
42
|
71
|
DEBUG = False
|
43
|
72
|
|
44
|
|
-ALLOWED_HOSTS = config.get('ALLOWED_HOSTS', [])
|
45
|
|
-
|
46
|
73
|
|
47
|
74
|
# Application definition
|
48
|
75
|
#
|
|
@@ -243,11 +270,3 @@ LOGIN_URL = 'users-login'
|
243
|
270
|
|
244
|
271
|
XNAIL_ROOT = os.path.join(BASE_DIR, 'data', 'xnails')
|
245
|
272
|
TEMP_ROOT = os.path.join(BASE_DIR, 'data', 'temp')
|
246
|
|
-
|
247
|
|
-
|
248
|
|
-# App Configuration
|
249
|
|
-#
|
250
|
|
-DEFAULT_THEME = config.get('DEFAULT_THEME', 'clear-red')
|
251
|
|
-ITEM_ROOT = config.get('ITEM_ROOT', os.path.join(BASE_DIR, 'data', 'example_data'))
|
252
|
|
-THUMBNAIL_SIZES = config.get('THUMBNAIL_SIZES', [137, 175, 250])
|
253
|
|
-WEBNAIL_SIZES = config.get('WEBNAIL_SIZES', [450, 1100, 1750])
|