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.

46 lines
1.8 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 django.dispatch import receiver
# from django.db.models.signals import post_save
#
# from erp_system.models import Menu, PermissionsModel
#
# # 默认情况下,每一个功能菜单的接口的请求方法数量
# methods = {'POST': '新增', 'GET': '查询', 'PUT': '修改', 'DELETE': '删除', 'PATCH': '局部修改'}
#
# logger = logging.getLogger('my')
#
#
# @receiver(post_save, sender=Menu)
# def create_menus_permissions(sender, instance, created, **kwargs):
# """
# 当有人新增一个功能菜单Menu)之后, 需要把该功能菜单对应的权限也插入到数据库
# :param sender:
# :param instance:
# :param created:
# :param kwargs:
# :return:
# """
#
# if created:
# logger.info('Menu对象已经新增完成了')
# if isinstance(instance, Menu):
# 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)}的权限'
# )
# else:
# logger.info('instance不是Menu类型所以不需要任何处理')