标签:_id rbo 中间 html sel value 中间件 mode har
class Permission(models.Model): """ 权限表 """ title = models.CharField(verbose_name=‘标题‘, max_length=32) url = models.CharField(verbose_name=‘含正则的URL‘, max_length=128) menu = models.ForeignKey(verbose_name=‘所属菜单‘, null=True, blank=True, to=‘Menu‘, on_delete=models.CASCADE) pid = models.ForeignKey(verbose_name="关联的权限",to=‘Permission‘,null=True,blank=True,related_name=‘parents‘,on_delete=models.CASCADE) name = models.CharField(verbose_name="url别名",max_length=32,unique=True) ######################
def __str__(self):
return self.title
permission_queryset = current_user.roles.all().filter(permissions__isnull=False).values(‘permissions__id‘, ‘permissions__title‘, ‘permissions__name‘, ‘permissions__menu_id‘, ‘permissions__menu__title‘, ‘permissions__menu__icon‘, ‘permissions__pid‘, "permissions__pid__url", "permissions__pid__title", ‘permissions__url‘).distinct() permission_dict = {}#######改字典 键为name for item in permission_queryset: permission_dict[item[‘permissions__name‘]] = { ‘id‘:item[‘permissions__id‘], ‘url‘:item[‘permissions__url‘], ‘pid‘:item[‘permissions__pid‘], ‘title‘:item[‘permissions__title‘], ‘p_title‘:item[‘permissions__pid__title‘], ‘p_url‘:item[‘permissions__pid__url‘] }
###################filter##############
逻辑判断用 filter
@register.filter def has_permission(request,name): if name in request.session[settings.PERMISSION_SESSION_KEY]: return True
{% for row in data_list %} <tr> <td>{{ row.id }}</td> <td>{{ row.name }}</td> <td>{{ row.age }}</td> <td>{{ row.email }}</td> <td>{{ row.company }}</td> {% if request|has_permission:‘customer_edit‘ or request|has_permission:‘customer_del‘ %}########## <td> {% if request|has_permission:‘customer_edit‘ %}#### <a style="color: #333333;" href="/customer/edit/{{ row.id }}/"> <i class="fa fa-edit" aria-hidden="true"></i></a> {% endif %} |####### {% if request|has_permission:‘customer_del‘ %}############# <a style="color: #d9534f;" href="/customer/del/{{ row.id }}/"><i class="fa fa-trash-o"></i></a> {% endif %}###### </td> {% endif %}########### </tr> {% endfor %}
标签:_id rbo 中间 html sel value 中间件 mode har
原文地址:https://www.cnblogs.com/Jnhnsnow/p/11669127.html