dav_base: cosmetics
Run tests / Execute tox to run the test suite (push) Successful in 3m29s

This commit is contained in:
2026-05-28 14:51:49 +02:00
parent efd2305b35
commit d9cfffb8c2
8 changed files with 63 additions and 41 deletions
+13 -8
View File
@@ -4,6 +4,8 @@ import re
from django.apps import AppConfig as _AppConfig
from django.core.exceptions import ImproperlyConfigured
from ..constants import DJANGO_MAIN_MODULE, MODULE_APP_SETTINGS_PREFIX
logger = logging.getLogger(__name__)
@@ -18,18 +20,21 @@ class DefaultSetting: # pylint: disable=too-few-public-methods
self.validator = validator
def validate(self, value):
if hasattr(self, 'validator') and self.validator is not None:
if callable(self.validator):
if not self.validator(value):
raise ImproperlyConfigured('Validator callback {clb} returned False'.format(clb=self.validator))
else:
if not re.search(self.validator, value):
raise ImproperlyConfigured('Does not match /{re}/'.format(re=self.validator))
if self.validator is None:
return
if callable(self.validator):
if not self.validator(value):
raise ImproperlyConfigured('Validator callback {clb} returned False'.format(clb=self.validator))
else:
if not re.search(self.validator, value):
raise ImproperlyConfigured('Does not match /{re}/'.format(re=self.validator))
class AppSettings: # pylint: disable=too-few-public-methods
def __init__(self, app_name, defaults):
settings_name = 'main.settings-' + app_name
settings_name = '{main_module}.{prefix}{app_name}'.format(main_module=DJANGO_MAIN_MODULE,
prefix=MODULE_APP_SETTINGS_PREFIX,
app_name=app_name)
try:
settings_module = importlib.import_module(settings_name)
+8 -3
View File
@@ -5,8 +5,7 @@ from importlib.resources import files as resource_files
from django.conf import settings
from django.urls import re_path, include
DJANGO_MAIN_MODULE = 'main'
MODULE_CONFIG_FILE_NAME = 'module_config.json'
from ..constants import DJANGO_MAIN_MODULE, MODULES_CONFIG_FILE_NAME
class ModuleConfigError(Exception):
@@ -64,6 +63,12 @@ class ModuleMeta:
url_conf = self._package_name + '.urls'
return re_path(url_pattern, include(url_conf, self.url_namespace))
@property
def root_url_name(self):
if self.url_namespace:
return '{}:{}'.format(self.url_namespace, self._root_url_name)
return self._root_url_name
def _load_from_package(self):
package_name = self._package_name
json_text = resource_files(package_name).joinpath(self._json_file).read_bytes()
@@ -97,7 +102,7 @@ class ModuleConfig:
if config_file_path is None:
if django_base_dir is None:
django_base_dir = settings.BASE_DIR
config_file_path = os.path.join(django_base_dir, DJANGO_MAIN_MODULE, MODULE_CONFIG_FILE_NAME)
config_file_path = os.path.join(django_base_dir, DJANGO_MAIN_MODULE, MODULES_CONFIG_FILE_NAME)
self._config_file_path = config_file_path
self._modules = {}