tree field 属性中 为什么获取不到uid 和 domain_force 为何可以写 python

1、tree field 属性中 为什么获取不到uid 

根据之前分析的代码。知道 load_view 里面会解析field属性的

def transfer_node_to_modifiers(node, modifiers, context=None, in_tree_view=False): 
if node.get('attrs'): 
    #If you want, add more conditions here 
    if ', uid' in node.get('attrs'): 
#这里的uid 是自己加的。这样才可以处理
     user_id = str(context.get('uid', 1)) 
     user_id = ', ' + user_id 
     attrs = node.get('attrs') 
     attrs = attrs.replace(', uid', user_id) 
     node.set('attrs', attrs) 
    modifiers.update(eval(node.get('attrs'))) 

if node.get('states'): 
    if 'invisible' in modifiers and isinstance(modifiers['invisible'], list): 
     # TODO combine with AND or OR, use implicit AND for now. 
     modifiers['invisible'].append(('state', 'not in', node.get('states').split(','))) 
    else: 
     modifiers['invisible'] = [('state', 'not in', node.get('states').split(','))] 

for a in ('invisible', 'readonly', 'required'): 
    if node.get(a): 
     v = bool(eval(node.get(a), {'context': context or {}})) 
     if in_tree_view and a == 'invisible': 
      # Invisible in a tree view has a specific meaning, make it a 
      # new key in the modifiers attribute. 
      modifiers['tree_invisible'] = v 
     elif v or (a not in modifiers or not isinstance(modifiers[a], list)): 
      # Don't set the attribute to False if a dynamic value was 
      # provided (i.e. a domain from attrs or states). 
      modifiers[a] = v 

因为 attrs 中根本没处理 uid

2、domain_force 为何可以用 user  而 domain中不可以写

因为 domain_force 是rule中的字段。

    def _eval_context(self):
        """Returns a dictionary to use as evaluation context for
           ir.rule domains."""
        # use an empty context for 'user' to make the domain evaluation
        # independent from the context
        return {'user': self.env.user.with_context({}), 'time': time}
eval_context 就是 {'user':obj} ,作为参数传入,肯定就可以用user了
dom = safe_eval(rule.domain_force, eval_context) if rule.domain_force else []
dom = expression.normalize_domain(dom)

而domain 是用  self.env.context  只有uid 做参数

可不可以 用 什么属性。主要看eval 后面给什么参数

上一篇:自定义View的简单实现


下一篇:一直滚动的TextView[跑马灯效果]