From 4b60411766a3a33ae3841f8d4466777ddd03f182 Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Tue, 22 Oct 2024 17:53:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dlicense=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/common/util/common.py | 12 +++++++----- apps/setting/serializers/valid_serializers.py | 3 ++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/apps/common/util/common.py b/apps/common/util/common.py index 182a18a8f9f..f1586bb954b 100644 --- a/apps/common/util/common.py +++ b/apps/common/util/common.py @@ -77,11 +77,13 @@ def valid_license(model=None, count=None, message=None): def inner(func): def run(*args, **kwargs): xpack_cache = DBModelManage.get_model('xpack_cache') - if ((not False if xpack_cache is None else xpack_cache.get('XPACK_LICENSE_IS_VALID', False)) - and QuerySet( - model).count() >= count): - error = message or f'超出限制{count},请联系我们(https://fit2cloud.com/)。' - raise AppApiException(400, error) + is_license_valid = xpack_cache.get('XPACK_LICENSE_IS_VALID', False) if xpack_cache is not None else False + record_count = QuerySet(model).count() + + if not is_license_valid and record_count >= count: + error_message = message or f'超出限制{count}, 请联系我们(https://fit2cloud.com/)。' + raise AppApiException(400, error_message) + return func(*args, **kwargs) return run diff --git a/apps/setting/serializers/valid_serializers.py b/apps/setting/serializers/valid_serializers.py index e36f07dfa69..ee731520693 100644 --- a/apps/setting/serializers/valid_serializers.py +++ b/apps/setting/serializers/valid_serializers.py @@ -41,7 +41,8 @@ def valid(self, is_valid=True): self.is_valid(raise_exception=True) model_value = model_message_dict.get(self.data.get('valid_type')) xpack_cache = DBModelManage.get_model('xpack_cache') - if not False if xpack_cache is None else xpack_cache.get('XPACK_LICENSE_IS_VALID', False): + is_license_valid = xpack_cache.get('XPACK_LICENSE_IS_VALID', False) if xpack_cache is not None else False + if not is_license_valid: if self.data.get('valid_count') != model_value.get('count'): raise AppApiException(400, model_value.get('message')) if QuerySet(