diff --git a/backend/system/management/commands/gen_menu_json.py b/backend/system/management/commands/gen_menu_json.py index 634b911..bde3b36 100644 --- a/backend/system/management/commands/gen_menu_json.py +++ b/backend/system/management/commands/gen_menu_json.py @@ -1,8 +1,9 @@ -import json from datetime import datetime from django.core.management.base import BaseCommand from system.models import Menu, MenuMeta -import re + +from utils.string_utils import camel_to_snake + """ 自动生成 菜单 代码的 Django 管理命令 使用方法: python manage.py gen_menu_json @@ -11,10 +12,6 @@ system 是 app 名称, Config 是 model 名称, System 是上级菜单名称 """ # gen_menu_json --app system --model Config --parent 系统管理 -def camel_to_snake(name): - s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name) - return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower() - def gen_menu(app_name, model_name, parent_menu_name, creator='admin'): print(parent_menu_name, 'parent') now = datetime.now().strftime('%Y-%m-%d %H:%M:%S') diff --git a/backend/system/management/commands/generate_crud.py b/backend/system/management/commands/generate_crud.py index 10131d5..409be34 100644 --- a/backend/system/management/commands/generate_crud.py +++ b/backend/system/management/commands/generate_crud.py @@ -8,12 +8,12 @@ """ import os -import re from string import Template from django.core.management.base import BaseCommand, CommandError from django.apps import apps from django.db import models -from django.conf import settings + +from utils.string_utils import camel_to_snake TPL_DIR = os.path.join(os.path.dirname(__file__), 'tpl') @@ -23,9 +23,6 @@ def render_tpl(tpl_name, context): tpl = Template(f.read()) return tpl.substitute(context) -def camel_to_snake(name): - s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name) - return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower() def ensure_view_dirs(app_name, model_name_snake): base_dir = f'../web/apps/web-antd/src/views/{app_name.lower()}' diff --git a/backend/system/tasks.py b/backend/system/tasks.py index a4daed9..261372d 100644 --- a/backend/system/tasks.py +++ b/backend/system/tasks.py @@ -20,7 +20,8 @@ def update_user_login_info(user_id, client_ip, user_agent): user.save(update_fields=['login_ip', 'last_login']) # 获取地理位置信息 - location_info = get_location_from_ip(client_ip) + # location_info = get_location_from_ip(client_ip) + location_info = None # 记录登录日录 LoginLog.objects.create( diff --git a/backend/utils/permissions.py b/backend/utils/permissions.py index 8f6ab38..9eafe88 100644 --- a/backend/utils/permissions.py +++ b/backend/utils/permissions.py @@ -1,6 +1,8 @@ from rest_framework import permissions from rest_framework.permissions import BasePermission from system.models import Menu +from utils.string_utils import camel_to_snake + class IsSuperUserOrReadOnly(BasePermission): """超级用户可读写,普通用户只读""" @@ -21,7 +23,7 @@ class HasButtonPermission(BasePermission): if not required_code: # 可自动推断权限编码逻辑 app_label = view.queryset.model._meta.app_label - model_name = view.queryset.model._meta.model_name + model_name = camel_to_snake(view.queryset.model._meta.model_name) action = getattr(view, 'action', None) action_map = { 'create': 'create', diff --git a/backend/utils/string_utils.py b/backend/utils/string_utils.py new file mode 100644 index 0000000..5b491d4 --- /dev/null +++ b/backend/utils/string_utils.py @@ -0,0 +1,5 @@ +import re + +def camel_to_snake(name): + s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name) + return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()