Logger creation simplified

This commit is contained in:
Dirk Alders 2024-10-08 22:46:18 +02:00
parent 154896f948
commit 77f8f61aab
6 changed files with 93 additions and 84 deletions

View File

@ -1,27 +1,37 @@
#######################################################################
# Configuration of your django application
#######################################################################
#
# Piki Setting
#
STARTPAGE = "startpage"
#
# Users library
#
# This enables or disables the self registration
USERS_SELF_REGISTRATION = False
#
# Themes library
#
# This defines the default theme, if no theme is set in the django parameters
DEFAULT_THEME = 'clear-blue'
#
# General settings
# Django
#
# APP_NAME is used for logging
APP_NAME = 'piki'
# This defines the mode of the running server
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
# SECURITY WARNING: don't run with a dummy secret in production!
# This a the secret key for your application.
# SECURITY WARNING: don't run with a dummy secret in production! And don't let others read this key!
SECRET_KEY = None
# This defines the listener hostnames for your django server
# SECURITY WARNING: don't run with '0.0.0.0' in in production, unless you know what you are doing!
ALLOWED_HOSTS = ['127.0.0.1', 'localhost', ]
# ALLOWED_HOSTS = ['<YOUR_SERVER_HOSTNAME>', ]
#
# Style settings
#
DEFAULT_THEME = 'clear-blue'
# This might be needed for usage in a docker environment
# CSRF_TRUSTED_ORIGINS = ['<YOUR_SERVER_URL>', ]

@ -1 +1 @@
Subproject commit e093c48e91aa378ac87bb32e90bc391a81024acb
Subproject commit 997594e37149b55e598f7dedfefed3c2998a2c87

View File

@ -2,9 +2,9 @@ import inspect
import logging
import os
from django.conf import settings
from django.utils.translation import gettext as _
from pages import access
from .help import actionbar as actionbar_add_help
import mycreole
@ -12,11 +12,7 @@ import pages
from themes import empty_entry_parameters, gray_icon_url, color_icon_url
from users.context import menubar as menubar_users
try:
from config import APP_NAME as ROOT_LOGGER_NAME
except ImportError:
ROOT_LOGGER_NAME = 'root'
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
logger = logging.getLogger(settings.ROOT_LOGGER_NAME).getChild(__name__)
ATTACHMENT_UID = 'attachment'
BACK_UID = 'back'

View File

@ -1,3 +1,4 @@
from django.conf import settings
from django.shortcuts import render
from django.http import HttpResponse, HttpResponseRedirect
from django.utils.translation import gettext as _
@ -15,11 +16,7 @@ import mycreole
from .page import creol_page
from themes import Context
try:
from config import APP_NAME as ROOT_LOGGER_NAME
except ImportError:
ROOT_LOGGER_NAME = 'root'
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
logger = logging.getLogger(settings.ROOT_LOGGER_NAME).getChild(__name__)
def root(request):

View File

@ -10,10 +10,10 @@ For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.1/ref/settings/
"""
import config
from config import APP_NAME as ROOT_LOGGER_NAME
import os
from pathlib import Path
import config
import os
import random
import stat
import sys
@ -21,40 +21,6 @@ import sys
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Check permission of config.py
#
if sys.platform == 'linux' or sys.platform == 'linux2':
st = os.stat(os.path.join(BASE_DIR, 'config.py'))
if st.st_mode & stat.S_IRGRP or st.st_mode & stat.S_IROTH:
raise PermissionError("conig.py is readable by group or others.")
# Default values, if not defined in config.py
#
USER_CONFIG_DEFAULTS = {
'DEBUG': False,
'SECRET_KEY': None,
'DEFAULT_THEME': 'clear-blue',
'ALLOWED_HOSTS': ['127.0.0.1', 'localhost', ],
'CSRF_TRUSTED_ORIGINS': [],
}
# Set configuration parameters
#
thismodule = sys.modules[__name__]
for property_name in USER_CONFIG_DEFAULTS:
try:
value = getattr(config, property_name)
except AttributeError:
value = USER_CONFIG_DEFAULTS[property_name]
setattr(thismodule, property_name, value)
# SECURITY WARNING: keep the secret key used in production secret!
#
if SECRET_KEY is None:
chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
s_key = ''.join([random.choice(chars) for n in range(50)])
secret_key_warning = "You need to create a config.py file including at least a SECRET_KEY definition (e.g.: --> %s <--). " % repr(s_key)
raise KeyError(secret_key_warning)
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/
@ -148,8 +114,72 @@ USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.1/howto/static-files/
STATIC_ROOT = os.path.join(BASE_DIR, 'data', 'static')
STATIC_URL = 'static/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'data', 'media')
MEDIA_URL = '/media/'
MYCREOLE_ROOT = os.path.join(BASE_DIR, 'data', 'pages')
MYCREOLE_ATTACHMENT_ACCESS = {
'read': 'pages.access.read_attachment',
'modify': 'pages.access.modify_attachment',
}
MYCREOLE_BAR = {
'navibar': 'pages.context.navigationbar',
'menubar': 'pages.context.menubar',
}
PAGES_ROOT = os.path.join(BASE_DIR, 'data', 'pages')
# Default primary key field type
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
# Check permission of config.py
#
if sys.platform == 'linux' or sys.platform == 'linux2':
st = os.stat(os.path.join(BASE_DIR, 'config.py'))
if st.st_mode & stat.S_IRGRP or st.st_mode & stat.S_IROTH:
raise PermissionError("conig.py is readable by group or others.")
# Default values, if not defined in config.py
#
USER_CONFIG_DEFAULTS = {
'DEBUG': False,
'SECRET_KEY': None,
'DEFAULT_THEME': 'clear-blue',
'ALLOWED_HOSTS': ['127.0.0.1', 'localhost', ],
'CSRF_TRUSTED_ORIGINS': [],
}
# Set configuration parameters
#
thismodule = sys.modules[__name__]
for property_name in USER_CONFIG_DEFAULTS:
try:
value = getattr(config, property_name)
except AttributeError:
value = USER_CONFIG_DEFAULTS[property_name]
setattr(thismodule, property_name, value)
# SECURITY WARNING: keep the secret key used in production secret!
#
if SECRET_KEY is None:
chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
s_key = ''.join([random.choice(chars) for n in range(50)])
secret_key_warning = "You need to create a config.py file including at least a SECRET_KEY definition (e.g.: --> %s <--). " % repr(s_key)
raise KeyError(secret_key_warning)
# Logging Configuration
#
ROOT_LOGGER_NAME = 'apps'
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
@ -186,27 +216,3 @@ File "%(pathname)s", line %(lineno)d, in %(funcName)s
},
}
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.1/howto/static-files/
STATIC_ROOT = os.path.join(BASE_DIR, 'data', 'static')
STATIC_URL = 'static/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'data', 'media')
MEDIA_URL = '/media/'
PAGES_ROOT = os.path.join(BASE_DIR, 'data', 'pages')
MYCREOLE_ROOT = os.path.join(BASE_DIR, 'data', 'pages')
MYCREOLE_ATTACHMENT_ACCESS = {
'read': 'pages.access.read_attachment',
'modify': 'pages.access.modify_attachment',
}
MYCREOLE_BAR = {
'navibar': 'pages.context.navigationbar',
'menubar': 'pages.context.menubar',
}
# Default primary key field type
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

2
users

@ -1 +1 @@
Subproject commit 6b55e81816ace1583051c8c62298c8a7281e2fcb
Subproject commit c9532aaf37cc785583d7ffc89d1d2f738985171d