Browse Source

Logger creation simplified

master
Dirk Alders 2 months ago
parent
commit
77f8f61aab
6 changed files with 92 additions and 83 deletions
  1. 20
    10
      config_example/config.py
  2. 1
    1
      mycreole
  3. 2
    6
      pages/context.py
  4. 2
    5
      pages/views.py
  5. 66
    60
      piki/settings.py
  6. 1
    1
      users

+ 20
- 10
config_example/config.py View File

1
+#######################################################################
2
+# Configuration of your django application
3
+#######################################################################
1
 #
4
 #
2
 # Piki Setting
5
 # Piki Setting
3
 #
6
 #
4
 STARTPAGE = "startpage"
7
 STARTPAGE = "startpage"
5
 
8
 
9
+#
10
+# Users library
11
+#
12
+# This enables or disables the self registration
6
 USERS_SELF_REGISTRATION = False
13
 USERS_SELF_REGISTRATION = False
7
 
14
 
8
-
9
 #
15
 #
10
-# General settings
16
+# Themes library
11
 #
17
 #
12
-# APP_NAME is used for logging
13
-APP_NAME = 'piki'
18
+# This defines the default theme, if no theme is set in the django parameters
19
+DEFAULT_THEME = 'clear-blue'
14
 
20
 
21
+#
22
+# Django
23
+#
24
+# This defines the mode of the running server
15
 # SECURITY WARNING: don't run with debug turned on in production!
25
 # SECURITY WARNING: don't run with debug turned on in production!
16
 DEBUG = False
26
 DEBUG = False
17
 
27
 
18
-# SECURITY WARNING: don't run with a dummy secret in production!
28
+# This a the secret key for your application.
29
+# SECURITY WARNING: don't run with a dummy secret in production! And don't let others read this key!
19
 SECRET_KEY = None
30
 SECRET_KEY = None
20
 
31
 
32
+# This defines the listener hostnames for your django server
21
 # SECURITY WARNING: don't run with '0.0.0.0' in in production, unless you know what you are doing!
33
 # SECURITY WARNING: don't run with '0.0.0.0' in in production, unless you know what you are doing!
22
-ALLOWED_HOSTS = ['127.0.0.1', 'localhost', ]
34
+# ALLOWED_HOSTS = ['<YOUR_SERVER_HOSTNAME>', ]
23
 
35
 
24
-#
25
-# Style settings
26
-#
27
-DEFAULT_THEME = 'clear-blue'
36
+# This might be needed for usage in a docker environment
37
+# CSRF_TRUSTED_ORIGINS = ['<YOUR_SERVER_URL>', ]

+ 1
- 1
mycreole

1
-Subproject commit e093c48e91aa378ac87bb32e90bc391a81024acb
1
+Subproject commit 997594e37149b55e598f7dedfefed3c2998a2c87

+ 2
- 6
pages/context.py View File

2
 import logging
2
 import logging
3
 import os
3
 import os
4
 
4
 
5
+from django.conf import settings
5
 from django.utils.translation import gettext as _
6
 from django.utils.translation import gettext as _
6
 
7
 
7
-
8
 from pages import access
8
 from pages import access
9
 from .help import actionbar as actionbar_add_help
9
 from .help import actionbar as actionbar_add_help
10
 import mycreole
10
 import mycreole
12
 from themes import empty_entry_parameters, gray_icon_url, color_icon_url
12
 from themes import empty_entry_parameters, gray_icon_url, color_icon_url
13
 from users.context import menubar as menubar_users
13
 from users.context import menubar as menubar_users
14
 
14
 
15
-try:
16
-    from config import APP_NAME as ROOT_LOGGER_NAME
17
-except ImportError:
18
-    ROOT_LOGGER_NAME = 'root'
19
-logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
15
+logger = logging.getLogger(settings.ROOT_LOGGER_NAME).getChild(__name__)
20
 
16
 
21
 ATTACHMENT_UID = 'attachment'
17
 ATTACHMENT_UID = 'attachment'
22
 BACK_UID = 'back'
18
 BACK_UID = 'back'

+ 2
- 5
pages/views.py View File

1
+from django.conf import settings
1
 from django.shortcuts import render
2
 from django.shortcuts import render
2
 from django.http import HttpResponse, HttpResponseRedirect
3
 from django.http import HttpResponse, HttpResponseRedirect
3
 from django.utils.translation import gettext as _
4
 from django.utils.translation import gettext as _
15
 from .page import creol_page
16
 from .page import creol_page
16
 from themes import Context
17
 from themes import Context
17
 
18
 
18
-try:
19
-    from config import APP_NAME as ROOT_LOGGER_NAME
20
-except ImportError:
21
-    ROOT_LOGGER_NAME = 'root'
22
-logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
19
+logger = logging.getLogger(settings.ROOT_LOGGER_NAME).getChild(__name__)
23
 
20
 
24
 
21
 
25
 def root(request):
22
 def root(request):

+ 66
- 60
piki/settings.py View File

10
 https://docs.djangoproject.com/en/5.1/ref/settings/
10
 https://docs.djangoproject.com/en/5.1/ref/settings/
11
 """
11
 """
12
 
12
 
13
+from pathlib import Path
14
+
13
 import config
15
 import config
14
-from config import APP_NAME as ROOT_LOGGER_NAME
15
 import os
16
 import os
16
-from pathlib import Path
17
 import random
17
 import random
18
 import stat
18
 import stat
19
 import sys
19
 import sys
21
 # Build paths inside the project like this: BASE_DIR / 'subdir'.
21
 # Build paths inside the project like this: BASE_DIR / 'subdir'.
22
 BASE_DIR = Path(__file__).resolve().parent.parent
22
 BASE_DIR = Path(__file__).resolve().parent.parent
23
 
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
-    'DEBUG': False,
35
-    'SECRET_KEY': None,
36
-    'DEFAULT_THEME': 'clear-blue',
37
-    'ALLOWED_HOSTS': ['127.0.0.1', 'localhost', ],
38
-    'CSRF_TRUSTED_ORIGINS': [],
39
-}
40
-
41
-# Set configuration parameters
42
-#
43
-thismodule = sys.modules[__name__]
44
-for property_name in USER_CONFIG_DEFAULTS:
45
-    try:
46
-        value = getattr(config, property_name)
47
-    except AttributeError:
48
-        value = USER_CONFIG_DEFAULTS[property_name]
49
-    setattr(thismodule, property_name, value)
50
-
51
-# SECURITY WARNING: keep the secret key used in production secret!
52
-#
53
-if SECRET_KEY is None:
54
-    chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
55
-    s_key = ''.join([random.choice(chars) for n in range(50)])
56
-    secret_key_warning = "You need to create a config.py file including at least a SECRET_KEY definition (e.g.: --> %s <--).    " % repr(s_key)
57
-    raise KeyError(secret_key_warning)
58
 
24
 
59
 # Quick-start development settings - unsuitable for production
25
 # Quick-start development settings - unsuitable for production
60
 # See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/
26
 # See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/
148
 
114
 
149
 USE_TZ = True
115
 USE_TZ = True
150
 
116
 
117
+
118
+# Static files (CSS, JavaScript, Images)
119
+# https://docs.djangoproject.com/en/5.1/howto/static-files/
120
+STATIC_ROOT = os.path.join(BASE_DIR, 'data', 'static')
121
+STATIC_URL = 'static/'
122
+
123
+MEDIA_ROOT = os.path.join(BASE_DIR, 'data', 'media')
124
+MEDIA_URL = '/media/'
125
+
126
+MYCREOLE_ROOT = os.path.join(BASE_DIR, 'data', 'pages')
127
+MYCREOLE_ATTACHMENT_ACCESS = {
128
+    'read': 'pages.access.read_attachment',
129
+    'modify': 'pages.access.modify_attachment',
130
+}
131
+MYCREOLE_BAR = {
132
+    'navibar': 'pages.context.navigationbar',
133
+    'menubar': 'pages.context.menubar',
134
+}
135
+
136
+PAGES_ROOT = os.path.join(BASE_DIR, 'data', 'pages')
137
+
138
+# Default primary key field type
139
+# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
140
+
141
+DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
142
+
143
+
144
+# Check permission of config.py
145
+#
146
+if sys.platform == 'linux' or sys.platform == 'linux2':
147
+    st = os.stat(os.path.join(BASE_DIR, 'config.py'))
148
+    if st.st_mode & stat.S_IRGRP or st.st_mode & stat.S_IROTH:
149
+        raise PermissionError("conig.py is readable by group or others.")
150
+
151
+# Default values, if not defined in config.py
152
+#
153
+USER_CONFIG_DEFAULTS = {
154
+    'DEBUG': False,
155
+    'SECRET_KEY': None,
156
+    'DEFAULT_THEME': 'clear-blue',
157
+    'ALLOWED_HOSTS': ['127.0.0.1', 'localhost', ],
158
+    'CSRF_TRUSTED_ORIGINS': [],
159
+}
160
+
161
+# Set configuration parameters
162
+#
163
+thismodule = sys.modules[__name__]
164
+for property_name in USER_CONFIG_DEFAULTS:
165
+    try:
166
+        value = getattr(config, property_name)
167
+    except AttributeError:
168
+        value = USER_CONFIG_DEFAULTS[property_name]
169
+    setattr(thismodule, property_name, value)
170
+
171
+# SECURITY WARNING: keep the secret key used in production secret!
172
+#
173
+if SECRET_KEY is None:
174
+    chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
175
+    s_key = ''.join([random.choice(chars) for n in range(50)])
176
+    secret_key_warning = "You need to create a config.py file including at least a SECRET_KEY definition (e.g.: --> %s <--).    " % repr(s_key)
177
+    raise KeyError(secret_key_warning)
178
+
179
+
151
 # Logging Configuration
180
 # Logging Configuration
152
 #
181
 #
182
+ROOT_LOGGER_NAME = 'apps'
153
 LOGGING = {
183
 LOGGING = {
154
     'version': 1,
184
     'version': 1,
155
     'disable_existing_loggers': False,
185
     'disable_existing_loggers': False,
186
     },
216
     },
187
 }
217
 }
188
 
218
 
189
-# Static files (CSS, JavaScript, Images)
190
-# https://docs.djangoproject.com/en/5.1/howto/static-files/
191
-
192
-STATIC_ROOT = os.path.join(BASE_DIR, 'data', 'static')
193
-STATIC_URL = 'static/'
194
-
195
-MEDIA_ROOT = os.path.join(BASE_DIR, 'data', 'media')
196
-MEDIA_URL = '/media/'
197
-
198
-PAGES_ROOT = os.path.join(BASE_DIR, 'data', 'pages')
199
-
200
-MYCREOLE_ROOT = os.path.join(BASE_DIR, 'data', 'pages')
201
-MYCREOLE_ATTACHMENT_ACCESS = {
202
-    'read': 'pages.access.read_attachment',
203
-    'modify': 'pages.access.modify_attachment',
204
-}
205
-MYCREOLE_BAR = {
206
-    'navibar': 'pages.context.navigationbar',
207
-    'menubar': 'pages.context.menubar',
208
-}
209
-# Default primary key field type
210
-# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
211
-
212
-DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

+ 1
- 1
users

1
-Subproject commit 6b55e81816ace1583051c8c62298c8a7281e2fcb
1
+Subproject commit c9532aaf37cc785583d7ffc89d1d2f738985171d

Loading…
Cancel
Save