mirror of https://github.com/jumpserver/jumpserver
[Update] Move LOCAL_DYNAMIC_SETTINGS (#4113)
parent
220ccda04d
commit
8ad71b6dd9
|
@ -1,9 +1,40 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
from werkzeug.local import Local
|
||||
from jumpserver.const import DYNAMIC
|
||||
from werkzeug.local import Local, LocalProxy
|
||||
|
||||
thread_local = Local()
|
||||
|
||||
|
||||
def _find(attr):
|
||||
return getattr(thread_local, attr, None)
|
||||
|
||||
|
||||
class _Settings:
|
||||
pass
|
||||
|
||||
|
||||
def get_dynamic_cfg_from_thread_local():
|
||||
KEY = 'dynamic_config'
|
||||
|
||||
try:
|
||||
cfg = getattr(thread_local, KEY)
|
||||
except AttributeError:
|
||||
cfg = _Settings()
|
||||
setattr(thread_local, KEY, cfg)
|
||||
|
||||
return cfg
|
||||
|
||||
|
||||
class DynamicDefaultLocalProxy(LocalProxy):
|
||||
def __getattr__(self, item):
|
||||
try:
|
||||
value = super().__getattr__(item)
|
||||
except AttributeError:
|
||||
value = getattr(DYNAMIC, item)()
|
||||
setattr(self, item, value)
|
||||
|
||||
return value
|
||||
|
||||
|
||||
LOCAL_DYNAMIC_SETTINGS = DynamicDefaultLocalProxy(get_dynamic_cfg_from_thread_local)
|
||||
|
|
|
@ -2,12 +2,9 @@
|
|||
#
|
||||
import os
|
||||
|
||||
from werkzeug.local import LocalProxy
|
||||
|
||||
from .conf import ConfigManager
|
||||
from common.local import thread_local
|
||||
|
||||
__all__ = ['BASE_DIR', 'PROJECT_DIR', 'VERSION', 'CONFIG', 'DYNAMIC', 'LOCAL_DYNAMIC_SETTINGS']
|
||||
__all__ = ['BASE_DIR', 'PROJECT_DIR', 'VERSION', 'CONFIG', 'DYNAMIC']
|
||||
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
PROJECT_DIR = os.path.dirname(BASE_DIR)
|
||||
|
@ -16,31 +13,3 @@ CONFIG = ConfigManager.load_user_config()
|
|||
DYNAMIC = ConfigManager.get_dynamic_config(CONFIG)
|
||||
|
||||
|
||||
class _Settings:
|
||||
pass
|
||||
|
||||
|
||||
def get_dynamic_cfg_from_thread_local():
|
||||
KEY = 'dynamic_config'
|
||||
|
||||
try:
|
||||
cfg = getattr(thread_local, KEY)
|
||||
except AttributeError:
|
||||
cfg = _Settings()
|
||||
setattr(thread_local, KEY, cfg)
|
||||
|
||||
return cfg
|
||||
|
||||
|
||||
class DynamicDefaultLocalProxy(LocalProxy):
|
||||
def __getattr__(self, item):
|
||||
try:
|
||||
value = super().__getattr__(item)
|
||||
except AttributeError:
|
||||
value = getattr(DYNAMIC, item)()
|
||||
setattr(self, item, value)
|
||||
|
||||
return value
|
||||
|
||||
|
||||
LOCAL_DYNAMIC_SETTINGS = DynamicDefaultLocalProxy(get_dynamic_cfg_from_thread_local)
|
||||
|
|
|
@ -16,7 +16,7 @@ from django.utils.translation import ugettext_lazy as _
|
|||
from django.utils import timezone
|
||||
from django.shortcuts import reverse
|
||||
|
||||
from jumpserver.const import LOCAL_DYNAMIC_SETTINGS
|
||||
from common.local import LOCAL_DYNAMIC_SETTINGS
|
||||
from orgs.utils import current_org
|
||||
from common.utils import signer, date_expired_default, get_logger, lazyproperty
|
||||
from common import fields
|
||||
|
|
Loading…
Reference in New Issue