refactor: delete dbmodelManage
This commit is contained in:
parent
643200cc06
commit
927b12a5ca
@ -1,35 +0,0 @@
|
||||
# coding=utf-8
|
||||
"""
|
||||
@project: MaxKB
|
||||
@Author:虎
|
||||
@file: db_model_manage.py
|
||||
@date:2024/7/22 17:00
|
||||
@desc:
|
||||
"""
|
||||
from importlib import import_module
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
def new_instance_by_class_path(class_path: str):
|
||||
parts = class_path.rpartition('.')
|
||||
package_path = parts[0]
|
||||
class_name = parts[2]
|
||||
module = import_module(package_path)
|
||||
HandlerClass = getattr(module, class_name)
|
||||
return HandlerClass()
|
||||
|
||||
|
||||
class DBModelManage:
|
||||
model_dict = {}
|
||||
|
||||
@staticmethod
|
||||
def get_model(model_name):
|
||||
return DBModelManage.model_dict.get(model_name)
|
||||
|
||||
@staticmethod
|
||||
def init():
|
||||
handles = [new_instance_by_class_path(class_path) for class_path in
|
||||
(settings.MODEL_HANDLES if hasattr(settings, 'MODEL_HANDLES') else [])]
|
||||
for h in handles:
|
||||
model_dict = h.get_model_dict()
|
||||
DBModelManage.model_dict = {**DBModelManage.model_dict, **model_dict}
|
||||
@ -1,15 +0,0 @@
|
||||
# coding=utf-8
|
||||
"""
|
||||
@project: MaxKB
|
||||
@Author:虎
|
||||
@file: base_handle.py
|
||||
@date:2024/7/22 17:02
|
||||
@desc:
|
||||
"""
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class IBaseModelHandle(ABC):
|
||||
@abstractmethod
|
||||
def get_model_dict(self):
|
||||
pass
|
||||
@ -1,14 +0,0 @@
|
||||
# coding=utf-8
|
||||
"""
|
||||
@project: MaxKB
|
||||
@Author:虎
|
||||
@file: default_base_model_handle.py
|
||||
@date:2024/7/22 17:06
|
||||
@desc:
|
||||
"""
|
||||
from common.models.handle.base_handle import IBaseModelHandle
|
||||
|
||||
|
||||
class DefaultBaseModelHandle(IBaseModelHandle):
|
||||
def get_model_dict(self):
|
||||
return {}
|
||||
@ -21,9 +21,8 @@ from django.db.models import QuerySet
|
||||
from django.utils.translation import gettext as _
|
||||
from pydub import AudioSegment
|
||||
|
||||
from ..database_model_manage.database_model_manage import DatabaseModelManage
|
||||
from ..exception.app_exception import AppApiException
|
||||
from ..models.db_model_manage import DBModelManage
|
||||
|
||||
|
||||
def password_encrypt(row_password):
|
||||
"""
|
||||
@ -237,7 +236,7 @@ def query_params_to_single_dict(query_params: Dict):
|
||||
def valid_license(model=None, count=None, message=None):
|
||||
def inner(func):
|
||||
def run(*args, **kwargs):
|
||||
xpack_cache = DBModelManage.get_model('xpack_cache')
|
||||
xpack_cache = DatabaseModelManage.get_model('xpack_cache')
|
||||
is_license_valid = xpack_cache.get('XPACK_LICENSE_IS_VALID', False) if xpack_cache is not None else False
|
||||
record_count = QuerySet(model).count()
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user