def get_context_data(self, **kwargs): nodes_remain = Node.objects.exclude(id__in=self.object.nodes.all( ).values_list('id', flat=True)).only('key') util = NodeUtil() nodes_remain = util.get_nodes_by_queryset(nodes_remain) context = { 'app': _('Perms'), 'action': _('Asset permission asset list'), 'nodes_remain': nodes_remain, } kwargs.update(context) return super().get_context_data(**kwargs)
def __init__(self, obj, cache_policy='0'): self.object = obj self.obj_id = str(obj.id) self._permissions = None self._permissions_id = None # 标记_permission的唯一值 self._assets = None self._filter_id = 'None' # 当通过filter更改 permission是标记 self.cache_policy = cache_policy self.tree = GenerateTree() self.change_org_if_need() self.nodes = None self._nodes = None self._assets_direct = None self._nodes_direct = None self.node_util = NodeUtil() self.tree._node_util = self.node_util
def get_nodes_family_and_system_users(self, nodes_with_system_users): """ 返回所有nodes_with_system_users中的node的家族节点的信息, 并子会继承祖先的系统用户和actions信息 :param nodes_with_system_users: {node.key: {system_user.id: actions,}, } :return: {node.key: {system_user.id: actions,}, } """ node_util = NodeUtil() _nodes_keys = nodes_with_system_users.keys() family_keys = node_util.get_some_nodes_family_keys_by_keys(_nodes_keys) nodes_items = [] for i in family_keys: system_users = nodes_with_system_users.get(i, defaultdict(int)) item = {"key": i, "system_users": system_users} nodes_items.append(item) # 按照父子关系排序 nodes_items.sort(key=self.sorted_by) nodes_items.append({"key": "", "system_users": defaultdict(int)}) self.stack = Stack() for item in nodes_items: self.debug("准备: {} 栈顶: {}".format( item['key'], self.stack.top["key"] if self.stack.top else None)) # 入栈之前检查,该节点是不是栈顶节点的子节点 # 如果不是,则栈顶出栈 while self.stack.top and not self.is_children( self.stack.top, item): # 出栈 self.pop_from_stack_system_users() # 入栈 self.push_to_stack_system_users(item) # 出栈最后一个 self.debug("剩余: {}".format(', '.join([n["key"] for n in self.stack]))) return self._nodes
def node_util(self): if not self._node_util: self._node_util = NodeUtil() return self._node_util