Browse Source

fix: 修复平台自动化翻译 (#12078)

Co-authored-by: feng <1304903146@qq.com>
pull/12081/head
fit2bot 1 year ago committed by GitHub
parent
commit
69c0eb2f50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      apps/assets/const/types.py
  2. 22
      apps/jumpserver/middleware.py
  3. 1
      apps/jumpserver/settings/base.py

4
apps/assets/const/types.py

@ -61,8 +61,8 @@ class AllTypes(ChoicesMixin):
@classmethod
def get_automation_methods(cls):
from assets.automations import platform_automation_methods as asset_methods
from accounts.automations import platform_automation_methods as account_methods
from assets.automations.methods import platform_automation_methods as asset_methods
from accounts.automations.methods import platform_automation_methods as account_methods
return asset_methods + account_methods
@classmethod

22
apps/jumpserver/middleware.py

@ -142,3 +142,25 @@ class EndMiddleware:
response = self.get_response(request)
request._e_time_end = time.time()
return response
class TranslatePatchMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
from assets.automations import methods as assets
from accounts.automations import methods as accounts
language = request.LANGUAGE_CODE
if language != settings.LANGUAGE_CODE:
settings.LANGUAGE_CODE = language
assets.platform_automation_methods = \
assets.get_platform_automation_methods(
assets.BASE_DIR
)
accounts.platform_automation_methods = \
accounts.get_platform_automation_methods(
accounts.BASE_DIR
)
response = self.get_response(request)
return response

1
apps/jumpserver/settings/base.py

@ -160,6 +160,7 @@ MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'jumpserver.middleware.TranslatePatchMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',

Loading…
Cancel
Save