Browse Source

django_lib update

master
Dirk Alders 2 months ago
parent
commit
d9228b68f2
6 changed files with 98 additions and 93 deletions
  1. 23
    11
      config_example/config.py
  2. 71
    78
      main/settings.py
  3. 1
    1
      mycreole
  4. 1
    1
      patt
  5. 1
    1
      themes
  6. 1
    1
      users

+ 23
- 11
config_example/config.py View File

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

+ 71
- 78
main/settings.py View File

1
 """
1
 """
2
-Django settings for this project.
2
+Django settings for patt 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
 For more information on this file, see
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
 For the full list of settings and their values, see
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/3.0/ref/settings/
11
 """
11
 """
12
 
12
 
13
+from pathlib import Path
14
+
13
 import config
15
 import config
14
 from logging.handlers import SocketHandler as _SocketHandler
16
 from logging.handlers import SocketHandler as _SocketHandler
15
 import os
17
 import os
18
+import random
16
 import stat
19
 import stat
17
 import sys
20
 import sys
18
-import random
19
-
20
-try:
21
-    from config import APP_NAME as ROOT_LOGGER_NAME
22
-except ImportError:
23
-    ROOT_LOGGER_NAME = 'root'
24
 
21
 
22
+# Build paths inside the project like this: BASE_DIR / 'subdir'.
23
+BASE_DIR = Path(__file__).resolve().parent.parent
25
 
24
 
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
-    'DEFAULT_THEME': 'clear-green',
43
-    'ALLOWED_HOSTS': ['127.0.0.1', ],
44
-    'CSRF_TRUSTED_ORIGINS': [],
45
-}
46
-
47
-# Set configuration parameters
48
-#
49
-thismodule = sys.modules[__name__]
50
-for property_name in USER_CONFIG_DEFAULTS:
51
-    try:
52
-        value = getattr(config, property_name)
53
-    except AttributeError:
54
-        value = USER_CONFIG_DEFAULTS[property_name]
55
-    setattr(thismodule, property_name, value)
56
 
25
 
57
 # Quick-start development settings - unsuitable for production
26
 # Quick-start development settings - unsuitable for production
58
 # See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
27
 # See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
59
 
28
 
60
-# SECURITY WARNING: keep the secret key used in production secret!
61
-#
62
-if SECRET_KEY is None:
63
-    chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
64
-    s_key = ''.join([random.choice(chars) for n in range(50)])
65
-    secret_key_warning = "You need to create a config.py file including at least a SECRET_KEY definition (e.g.: --> %s <--)." % repr(s_key)
66
-    raise KeyError(secret_key_warning)
67
-
68
 
29
 
69
 # Application definition
30
 # Application definition
70
-#
31
+
71
 INSTALLED_APPS = [
32
 INSTALLED_APPS = [
72
     'patt.apps.PattConfig',
33
     'patt.apps.PattConfig',
73
     'themes.apps.ThemesConfig',
34
     'themes.apps.ThemesConfig',
74
-    'users.apps.UsersConfig',
75
     'mycreole.apps.MycreoleConfig',
35
     'mycreole.apps.MycreoleConfig',
36
+    'users.apps.UsersConfig',
76
     #
37
     #
77
     'django.contrib.admin',
38
     'django.contrib.admin',
78
     'django.contrib.auth',
39
     'django.contrib.auth',
118
 
79
 
119
 
80
 
120
 # Database
81
 # Database
121
-# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
122
-#
82
+# https://docs.djangoproject.com/en/5.1/ref/settings/#databases
83
+
123
 DATABASES = {
84
 DATABASES = {
124
     'default': {
85
     'default': {
125
         'ENGINE': 'django.db.backends.sqlite3',
86
         'ENGINE': 'django.db.backends.sqlite3',
126
-        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
87
+        'NAME': BASE_DIR / 'db.sqlite3',
127
     }
88
     }
128
 }
89
 }
129
 
90
 
130
 
91
 
131
 # Password validation
92
 # Password validation
132
-# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
133
-#
93
+# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators
94
+
134
 AUTH_PASSWORD_VALIDATORS = [
95
 AUTH_PASSWORD_VALIDATORS = [
135
     {
96
     {
136
         'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
97
         'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
147
 ]
108
 ]
148
 
109
 
149
 
110
 
150
-# Search Engine
151
-#
152
-WHOOSH_PATH = os.path.join(BASE_DIR, 'data', 'whoosh_index')
153
-
154
-
155
 # Internationalization
111
 # Internationalization
156
-# https://docs.djangoproject.com/en/3.0/topics/i18n/
157
-#
112
+# https://docs.djangoproject.com/en/5.1/topics/i18n/
113
+
158
 LANGUAGE_CODE = 'en-us'
114
 LANGUAGE_CODE = 'en-us'
159
 LANGUAGES = [
115
 LANGUAGES = [
160
     ('en', 'English'),
116
     ('en', 'English'),
176
 
132
 
177
 
133
 
178
 # Static files (CSS, JavaScript, Images)
134
 # Static files (CSS, JavaScript, Images)
179
-# https://docs.djangoproject.com/en/3.0/howto/static-files/
180
-#
135
+# https://docs.djangoproject.com/en/5.1/howto/static-files/
181
 STATIC_ROOT = os.path.join(BASE_DIR, 'data', 'static')
136
 STATIC_ROOT = os.path.join(BASE_DIR, 'data', 'static')
182
-STATIC_URL = '/static/'
137
+STATIC_URL = 'static/'
183
 
138
 
184
 MEDIA_ROOT = os.path.join(BASE_DIR, 'data', 'media')
139
 MEDIA_ROOT = os.path.join(BASE_DIR, 'data', 'media')
185
 MEDIA_URL = '/media/'
140
 MEDIA_URL = '/media/'
189
     'read': 'patt.access.read_attachment',
144
     'read': 'patt.access.read_attachment',
190
     'modify': 'patt.access.modify_attachment',
145
     'modify': 'patt.access.modify_attachment',
191
 }
146
 }
147
+MYCREOLE_BAR = {
148
+    'navibar': 'patt.context.navigationbar',
149
+    'menubar': 'patt.context.menubar',
150
+}
192
 MYCREOLE_EXT_FILTERS = [
151
 MYCREOLE_EXT_FILTERS = [
193
     'patt.creole.task_link_filter',
152
     'patt.creole.task_link_filter',
194
     'patt.creole.tasklist_link_filter',
153
     'patt.creole.tasklist_link_filter',
195
 ]
154
 ]
196
 
155
 
197
-# Session parameters
156
+WHOOSH_PATH = os.path.join(BASE_DIR, 'data', 'whoosh_index')
157
+
158
+LOGIN_URL = 'users-login'
159
+
160
+# Default primary key field type
161
+# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
162
+
163
+DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
164
+
165
+
166
+# Check permission of config.py
167
+#
168
+if sys.platform == 'linux' or sys.platform == 'linux2':
169
+    st = os.stat(os.path.join(BASE_DIR, 'config.py'))
170
+    if st.st_mode & stat.S_IRGRP or st.st_mode & stat.S_IROTH:
171
+        raise PermissionError("conig.py is readable by group or others.")
172
+
173
+# Default values, if not defined in config.py
174
+#
175
+USER_CONFIG_DEFAULTS = {
176
+    'DEBUG': False,
177
+    'SECRET_KEY': None,
178
+    'DEFAULT_THEME': 'clear-green',
179
+    'ALLOWED_HOSTS': ['127.0.0.1', 'localhost', ],
180
+    'CSRF_TRUSTED_ORIGINS': [],
181
+}
182
+
183
+# Set configuration parameters
184
+#
185
+thismodule = sys.modules[__name__]
186
+for property_name in USER_CONFIG_DEFAULTS:
187
+    try:
188
+        value = getattr(config, property_name)
189
+    except AttributeError:
190
+        value = USER_CONFIG_DEFAULTS[property_name]
191
+    setattr(thismodule, property_name, value)
192
+
193
+# SECURITY WARNING: keep the secret key used in production secret!
198
 #
194
 #
199
-PERSISTENT_SESSION_VARIABLES = []
195
+if SECRET_KEY is None:
196
+    chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
197
+    s_key = ''.join([random.choice(chars) for n in range(50)])
198
+    secret_key_warning = "You need to create a config.py file including at least a SECRET_KEY definition (e.g.: --> %s <--)." % repr(s_key)
199
+    raise KeyError(secret_key_warning)
200
 
200
 
201
 
201
 
202
 # Logging Configuration
202
 # Logging Configuration
203
 #
203
 #
204
+ROOT_LOGGER_NAME = os.path.basename(os.path.dirname(__file__))
205
+default_handler = ['socket'] if DEBUG else ['console']
206
+
207
+
204
 class DjangoSocketHandler(_SocketHandler):
208
 class DjangoSocketHandler(_SocketHandler):
205
     def emit(self, record):
209
     def emit(self, record):
206
         if hasattr(record, 'request'):
210
         if hasattr(record, 'request'):
208
         return super().emit(record)
212
         return super().emit(record)
209
 
213
 
210
 
214
 
211
-default_handler = ['socket'] if DEBUG else ['console']
212
-#
213
 LOGGING = {
215
 LOGGING = {
214
     'version': 1,
216
     'version': 1,
215
     'disable_existing_loggers': False,
217
     'disable_existing_loggers': False,
233
         },
235
         },
234
         'socket': {
236
         'socket': {
235
             'level': 'DEBUG',
237
             'level': 'DEBUG',
236
-            'class': 'main.settings.DjangoSocketHandler',
238
+            'class': f'{ROOT_LOGGER_NAME}.settings.DjangoSocketHandler',
237
             'host': '127.0.0.1',
239
             'host': '127.0.0.1',
238
             'port': 19996,
240
             'port': 19996,
239
         },
241
         },
251
         },
253
         },
252
     },
254
     },
253
 }
255
 }
254
-
255
-
256
-# Other Configuration issues
257
-#
258
-LOGIN_URL = 'users-login'
259
-
260
-# Default Auto Filed
261
-#
262
-DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'

+ 1
- 1
mycreole

1
-Subproject commit 057388e3b44b5fe42b133fe030c41aa6a254de58
1
+Subproject commit 997594e37149b55e598f7dedfefed3c2998a2c87

+ 1
- 1
patt

1
-Subproject commit be03b653ebce2dadb5bfb314e597966751fb9cf7
1
+Subproject commit 577956248e382ff47c5d0c668ee8ffbfe2f4cbd8

+ 1
- 1
themes

1
-Subproject commit 13a8d8ebc4c82d2000af4464b863cf3b38a7a1fe
1
+Subproject commit 261ef5048efb4bd204a4ddbe56a90f96cd767ba1

+ 1
- 1
users

1
-Subproject commit 0827a5311fdbbef689365c6db5762881e048ba9c
1
+Subproject commit c9532aaf37cc785583d7ffc89d1d2f738985171d

Loading…
Cancel
Save