You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
2.9 KiB
Python
90 lines
2.9 KiB
Python
5 years ago
|
# 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/>.
|
||
4 years ago
|
import typing as t
|
||
|
|
||
4 years ago
|
from django.utils.functional import cached_property
|
||
5 years ago
|
|
||
|
|
||
|
class AppSettings:
|
||
|
def __init__(self, prefix):
|
||
|
self.prefix = prefix
|
||
|
|
||
|
def import_from_str(self, name):
|
||
|
from importlib import import_module
|
||
|
|
||
4 years ago
|
path, prop = name.rsplit(".", 1)
|
||
5 years ago
|
|
||
5 years ago
|
mod = import_module(path)
|
||
|
return getattr(mod, prop)
|
||
5 years ago
|
|
||
|
def _setting(self, name, dflt):
|
||
|
from django.conf import settings
|
||
4 years ago
|
|
||
5 years ago
|
return getattr(settings, self.prefix + name, dflt)
|
||
|
|
||
4 years ago
|
@cached_property
|
||
|
def REDIS_URI(self) -> t.Optional[str]: # pylint: disable=invalid-name
|
||
|
return self._setting("REDIS_URI", None)
|
||
|
|
||
4 years ago
|
@cached_property
|
||
|
def API_PERMISSIONS_READ(self): # pylint: disable=invalid-name
|
||
|
perms = self._setting("API_PERMISSIONS_READ", tuple())
|
||
|
ret = []
|
||
|
for perm in perms:
|
||
|
ret.append(self.import_from_str(perm))
|
||
|
return ret
|
||
|
|
||
|
@cached_property
|
||
|
def API_PERMISSIONS_WRITE(self): # pylint: disable=invalid-name
|
||
|
perms = self._setting("API_PERMISSIONS_WRITE", tuple())
|
||
|
ret = []
|
||
|
for perm in perms:
|
||
|
ret.append(self.import_from_str(perm))
|
||
|
return ret
|
||
|
|
||
4 years ago
|
@cached_property
|
||
4 years ago
|
def GET_USER_QUERYSET_FUNC(self): # pylint: disable=invalid-name
|
||
|
get_user_queryset = self._setting("GET_USER_QUERYSET_FUNC", None)
|
||
4 years ago
|
if get_user_queryset is not None:
|
||
|
return self.import_from_str(get_user_queryset)
|
||
|
return None
|
||
|
|
||
4 years ago
|
@cached_property
|
||
|
def CREATE_USER_FUNC(self): # pylint: disable=invalid-name
|
||
|
func = self._setting("CREATE_USER_FUNC", None)
|
||
|
if func is not None:
|
||
|
return self.import_from_str(func)
|
||
|
return None
|
||
|
|
||
4 years ago
|
@cached_property
|
||
|
def DASHBOARD_URL_FUNC(self): # pylint: disable=invalid-name
|
||
|
func = self._setting("DASHBOARD_URL_FUNC", None)
|
||
|
if func is not None:
|
||
|
return self.import_from_str(func)
|
||
|
return None
|
||
|
|
||
4 years ago
|
@cached_property
|
||
|
def CHUNK_PATH_FUNC(self): # pylint: disable=invalid-name
|
||
|
func = self._setting("CHUNK_PATH_FUNC", None)
|
||
|
if func is not None:
|
||
|
return self.import_from_str(func)
|
||
|
return None
|
||
|
|
||
4 years ago
|
@cached_property
|
||
5 years ago
|
def CHALLENGE_VALID_SECONDS(self): # pylint: disable=invalid-name
|
||
|
return self._setting("CHALLENGE_VALID_SECONDS", 60)
|
||
|
|
||
5 years ago
|
|
||
4 years ago
|
app_settings = AppSettings("ETEBASE_")
|