You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
import logging
|
|
|
|
|
|
|
|
|
|
from celery import shared_task
|
|
|
|
|
from ERP_5.utils.tasks_hook import HookTask
|
|
|
|
|
from erp_system.models import PermissionsModel, Menu
|
|
|
|
|
|
|
|
|
|
# 默认情况下,每一个功能菜单的接口的请求方法数量
|
|
|
|
|
methods = {'POST': '新增', 'GET': '查询', 'PUT': '修改', 'DELETE': '删除', 'PATCH': '局部修改'}
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger('my')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 在装饰器中,指定一个任务钩子
|
|
|
|
|
@shared_task(base=HookTask)
|
|
|
|
|
def create_menus_permissions(menu_id): # 定义了一个任务
|
|
|
|
|
logger.info('Menu对象已经新增完成了!')
|
|
|
|
|
instance = Menu.objects.get(pk=menu_id)
|
|
|
|
|
|
|
|
|
|
if not instance.parent: # 表示是一个顶级菜单,没有请求URL地址,不是一个接口
|
|
|
|
|
permission = PermissionsModel.objects.create(
|
|
|
|
|
name=instance.name + "的权限",
|
|
|
|
|
is_menu=True,
|
|
|
|
|
menu=instance
|
|
|
|
|
)
|
|
|
|
|
else: # 表示是接口:有父菜单,有请求的url地址
|
|
|
|
|
for method in methods:
|
|
|
|
|
permission = PermissionsModel.objects.create(
|
|
|
|
|
name=methods.get(method) + "的权限",
|
|
|
|
|
is_menu=False,
|
|
|
|
|
menu=instance,
|
|
|
|
|
method=method,
|
|
|
|
|
path=instance.url,
|
|
|
|
|
desc=f'{instance.name}的{methods.get(method)}的权限'
|
|
|
|
|
)
|
|
|
|
|
|