Browse Source

Configuration adapted

master
Dirk Alders 4 years ago
parent
commit
5cea6d1589
3 changed files with 71 additions and 20 deletions
  1. 32
    0
      config_example/config.py
  2. 38
    19
      main/settings.py
  3. 1
    1
      pygal

+ 32
- 0
config_example/config.py View File

@@ -0,0 +1,32 @@
1
+import os
2
+
3
+BASE_DIR = os.path.dirname(os.path.abspath(__file__))
4
+
5
+#
6
+# General settings
7
+#
8
+# SECRET_KEY = 'define a secret key'
9
+#
10
+# ITEM_ROOT = os.path.join(BASE_DIR, 'data', 'example_data')
11
+# ALLOWED_HOSTS = []
12
+
13
+#
14
+# Access Right settings
15
+#
16
+# SUSPEND_PUBLIC = True       # Set this to True to ensure, that unauthenticated users have no permission
17
+
18
+#
19
+# Style settings
20
+#
21
+# DEFAULT_THEME = 'clear-red'
22
+# THUMBNAIL_SIZES = [137, 175, 250]
23
+# WEBNAIL_SIZES = [450, 1100, 1750]
24
+
25
+#
26
+# Content settings
27
+#
28
+# SORT_BY = False            # Sorting by name if False
29
+# SHOW_IMAGE = True
30
+# SHOW_VIDEO = True
31
+# SHOW_AUDIO = False
32
+# SHOW_OTHER = False

+ 38
- 19
main/settings.py View File

@@ -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])

+ 1
- 1
pygal

@@ -1 +1 @@
1
-Subproject commit 983fa59231403732d08716c1d7677fa3b090bd44
1
+Subproject commit 9da7e60a131d94fe30ecb3d3ae7ec733fa173dd3

Loading…
Cancel
Save