added getlist
method to c3nav config parser
This commit is contained in:
parent
7dc718475e
commit
81cd6636d8
2 changed files with 19 additions and 12 deletions
|
@ -94,9 +94,9 @@ PUBLIC_EDITOR = config.getboolean('c3nav', 'editor', fallback=True)
|
||||||
PUBLIC_BASE_MAPDATA = config.getboolean('c3nav', 'public_base_mapdata', fallback=False)
|
PUBLIC_BASE_MAPDATA = config.getboolean('c3nav', 'public_base_mapdata', fallback=False)
|
||||||
AUTO_PROCESS_UPDATES = config.getboolean('c3nav', 'auto_process_updates', fallback=True)
|
AUTO_PROCESS_UPDATES = config.getboolean('c3nav', 'auto_process_updates', fallback=True)
|
||||||
|
|
||||||
RANDOM_LOCATION_GROUPS = config.get('c3nav', 'random_location_groups', fallback=None)
|
RANDOM_LOCATION_GROUPS = config.getlist('c3nav', 'random_location_groups', fallback=None)
|
||||||
if RANDOM_LOCATION_GROUPS:
|
if RANDOM_LOCATION_GROUPS:
|
||||||
RANDOM_LOCATION_GROUPS = tuple(int(i) for i in RANDOM_LOCATION_GROUPS.split(','))
|
RANDOM_LOCATION_GROUPS = tuple(int(i) for i in RANDOM_LOCATION_GROUPS)
|
||||||
|
|
||||||
SECRET_KEY = config.get('django', 'secret', fallback=None)
|
SECRET_KEY = config.get('django', 'secret', fallback=None)
|
||||||
if not SECRET_KEY:
|
if not SECRET_KEY:
|
||||||
|
@ -243,7 +243,7 @@ DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
|
||||||
STATIC_URL = config.get('django', 'static_url', fallback='/static/', env='C3NAV_STATIC_URL')
|
STATIC_URL = config.get('django', 'static_url', fallback='/static/', env='C3NAV_STATIC_URL')
|
||||||
MEDIA_URL = config.get('django', 'media_url', fallback='/media/', env='C3NAV_MEDIA_URL')
|
MEDIA_URL = config.get('django', 'media_url', fallback='/media/', env='C3NAV_MEDIA_URL')
|
||||||
|
|
||||||
ALLOWED_HOSTS = [n for n in config.get('django', 'allowed_hosts', fallback='*').split(',') if n]
|
ALLOWED_HOSTS = config.getlist('django', 'allowed_hosts', fallback='*')
|
||||||
|
|
||||||
if config.getboolean('django', 'reverse_proxy', fallback=False):
|
if config.getboolean('django', 'reverse_proxy', fallback=False):
|
||||||
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
|
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
|
||||||
|
@ -269,7 +269,7 @@ EMAIL_SUBJECT_PREFIX = ('[c3nav-%s] ' % INSTANCE_NAME) if INSTANCE_NAME else '[c
|
||||||
if config.has_section('mail'):
|
if config.has_section('mail'):
|
||||||
raise ImproperlyConfigured('mail config section got renamed to email. Please fix your config file.')
|
raise ImproperlyConfigured('mail config section got renamed to email. Please fix your config file.')
|
||||||
|
|
||||||
ADMINS = [('Admin', n) for n in config.get('mail', 'admins', fallback='').split(",") if n]
|
ADMINS = [('Admin', n) for n in config.getlist('mail', 'admins', fallback='')]
|
||||||
|
|
||||||
CACHES = {
|
CACHES = {
|
||||||
'default': {
|
'default': {
|
||||||
|
@ -299,7 +299,7 @@ REDIS_CONNECTION_POOL = None
|
||||||
if HAS_REDIS:
|
if HAS_REDIS:
|
||||||
import redis
|
import redis
|
||||||
HAS_REAL_CACHE = True
|
HAS_REAL_CACHE = True
|
||||||
REDIS_SERVERS = re.split("[;,]", config.get('redis', 'location', env='C3NAV_REDIS'))
|
REDIS_SERVERS = config.getlist('redis', 'location', env='C3NAV_REDIS')
|
||||||
CACHES['redis'] = {
|
CACHES['redis'] = {
|
||||||
"BACKEND": "django.core.cache.backends.redis.RedisCache",
|
"BACKEND": "django.core.cache.backends.redis.RedisCache",
|
||||||
"LOCATION": REDIS_SERVERS,
|
"LOCATION": REDIS_SERVERS,
|
||||||
|
@ -431,7 +431,7 @@ if HAS_REDIS:
|
||||||
'default': {
|
'default': {
|
||||||
'BACKEND': 'channels_redis.core.RedisChannelLayer',
|
'BACKEND': 'channels_redis.core.RedisChannelLayer',
|
||||||
'CONFIG': {
|
'CONFIG': {
|
||||||
"hosts": config.get('redis', 'location', env='C3NAV_REDIS').split(','),
|
"hosts": config.getlist('redis', 'location', env='C3NAV_REDIS'),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -465,7 +465,7 @@ EXTRA_LANG_INFO = {
|
||||||
LANG_INFO = dict(django.conf.locale.LANG_INFO, **EXTRA_LANG_INFO)
|
LANG_INFO = dict(django.conf.locale.LANG_INFO, **EXTRA_LANG_INFO)
|
||||||
django.conf.locale.LANG_INFO = LANG_INFO
|
django.conf.locale.LANG_INFO = LANG_INFO
|
||||||
|
|
||||||
SELECTED_LANGUAGES = frozenset(config.get('c3nav', 'languages', fallback='en,de').split(','))
|
SELECTED_LANGUAGES = frozenset(config.getlist('c3nav', 'languages', fallback='en,de'))
|
||||||
LANGUAGES = [(code, name) for code, name in [
|
LANGUAGES = [(code, name) for code, name in [
|
||||||
('en', _('English')),
|
('en', _('English')),
|
||||||
('en-UW', _('Engwish UwU')),
|
('en-UW', _('Engwish UwU')),
|
||||||
|
@ -631,7 +631,7 @@ BASE_THEME = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WIFI_SSIDS = [n for n in config.get('c3nav', 'wifi_ssids', fallback='').split(',') if n]
|
WIFI_SSIDS = config.getlist('c3nav', 'wifi_ssids', fallback='')
|
||||||
|
|
||||||
|
|
||||||
# Projection
|
# Projection
|
||||||
|
@ -796,10 +796,7 @@ if SSO_ENABLED:
|
||||||
# we need this despite our own strategy looking it up directly because the backends context processor of
|
# we need this despite our own strategy looking it up directly because the backends context processor of
|
||||||
# social_django directly uses the django setting without asking the normal config pipeline
|
# social_django directly uses the django setting without asking the normal config pipeline
|
||||||
AUTHENTICATION_BACKENDS = (
|
AUTHENTICATION_BACKENDS = (
|
||||||
* (
|
* config.getlist('sso', 'authentication_backends', fallback=''),
|
||||||
backend.strip()
|
|
||||||
for backend in config.get('sso', 'authentication_backends', fallback='').split(',')
|
|
||||||
),
|
|
||||||
*AUTHENTICATION_BACKENDS,
|
*AUTHENTICATION_BACKENDS,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
from configparser import _UNSET, NoOptionError, NoSectionError, RawConfigParser
|
from configparser import _UNSET, NoOptionError, NoSectionError, RawConfigParser
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
|
||||||
|
@ -8,6 +9,7 @@ from c3nav.utils.environ import Env
|
||||||
|
|
||||||
class C3navConfigParser(RawConfigParser):
|
class C3navConfigParser(RawConfigParser):
|
||||||
env: Env
|
env: Env
|
||||||
|
LIST_PATTERN = re.compile(r"[;,]")
|
||||||
|
|
||||||
def __init__(self, env: Env = None, **kwargs):
|
def __init__(self, env: Env = None, **kwargs):
|
||||||
if env is None:
|
if env is None:
|
||||||
|
@ -69,3 +71,11 @@ class C3navConfigParser(RawConfigParser):
|
||||||
return value
|
return value
|
||||||
with self._error_wrapper(section, option, env):
|
with self._error_wrapper(section, option, env):
|
||||||
return super().getboolean(section, option, raw=raw, vars=vars, fallback=fallback)
|
return super().getboolean(section, option, raw=raw, vars=vars, fallback=fallback)
|
||||||
|
|
||||||
|
def getlist(self, section: str, option: str, *, raw=False, vars=None, fallback=_UNSET,
|
||||||
|
env: bool | str = True, **kwargs) -> tuple[str] | None:
|
||||||
|
value = self.env.str(self.get_env_key(section, option, env), default=None) if env else None
|
||||||
|
if value is None:
|
||||||
|
with self._error_wrapper(section, option, env):
|
||||||
|
value = super().get(section, option, raw=raw, vars=vars, fallback=fallback)
|
||||||
|
return tuple(i.strip() for i in self.LIST_PATTERN.split(value) if i) if value is not None else value
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue