1
0
mirror of https://github.com/etesync/server synced 2024-11-25 18:28:46 +00:00
etesync-server/etebase_server/django/app_settings_inner.py

90 lines
2.8 KiB
Python
Raw Normal View History

2020-02-19 18:53:43 +00:00
# Copyright © 2017 Tom Hacohen
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, version 3.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import typing as t
from django.utils.functional import cached_property
2020-02-19 18:53:43 +00:00
class AppSettings:
def __init__(self, prefix):
self.prefix = prefix
def import_from_str(self, name):
from importlib import import_module
path, prop = name.rsplit(".", 1)
2020-02-19 18:53:43 +00:00
2020-02-26 12:32:25 +00:00
mod = import_module(path)
return getattr(mod, prop)
2020-02-19 18:53:43 +00:00
def _setting(self, name, dflt):
from django.conf import settings
2020-02-19 18:53:43 +00:00
return getattr(settings, self.prefix + name, dflt)
@cached_property
2024-06-08 21:56:36 +00:00
def REDIS_URI(self) -> t.Optional[str]: # noqa: N802
return self._setting("REDIS_URI", None)
@cached_property
2024-06-08 21:56:36 +00:00
def API_PERMISSIONS_READ(self): # noqa: N802
perms = self._setting("API_PERMISSIONS_READ", tuple())
ret = []
for perm in perms:
ret.append(self.import_from_str(perm))
return ret
@cached_property
2024-06-08 21:56:36 +00:00
def API_PERMISSIONS_WRITE(self): # noqa: N802
perms = self._setting("API_PERMISSIONS_WRITE", tuple())
ret = []
for perm in perms:
ret.append(self.import_from_str(perm))
return ret
@cached_property
2024-06-08 21:56:36 +00:00
def GET_USER_QUERYSET_FUNC(self): # noqa: N802
get_user_queryset = self._setting("GET_USER_QUERYSET_FUNC", None)
2020-07-13 11:30:18 +00:00
if get_user_queryset is not None:
return self.import_from_str(get_user_queryset)
return None
@cached_property
2024-06-08 21:56:36 +00:00
def CREATE_USER_FUNC(self): # noqa: N802
func = self._setting("CREATE_USER_FUNC", None)
if func is not None:
return self.import_from_str(func)
return None
@cached_property
2024-06-08 21:56:36 +00:00
def DASHBOARD_URL_FUNC(self): # noqa: N802
func = self._setting("DASHBOARD_URL_FUNC", None)
if func is not None:
return self.import_from_str(func)
return None
@cached_property
2024-06-08 21:56:36 +00:00
def CHUNK_PATH_FUNC(self): # noqa: N802
func = self._setting("CHUNK_PATH_FUNC", None)
if func is not None:
return self.import_from_str(func)
return None
@cached_property
2024-06-08 21:56:36 +00:00
def CHALLENGE_VALID_SECONDS(self): # noqa: N802
2020-05-14 10:43:49 +00:00
return self._setting("CHALLENGE_VALID_SECONDS", 60)
2020-02-19 18:53:43 +00:00
app_settings = AppSettings("ETEBASE_")