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.

36 lines
1.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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)}的权限'
)