Odoo Qweb页面调用python方法

Qweb 需要执行后台execute_code 方法:


    
    
    
    
        
    

在control 中增加 参数 'execute_code': self.execute_code, 传在前台。前台就可以调用了

def usercenter(self, **kwargs):
    usercenter_menu = request.env['usercenter.menu'].sudo().search([], order='display_Position,sequence')
    usercenter_menu_used = usercenter_menu
    no_footer = request.params.get('no_footer')
    no_footer = False if no_footer else True
    no_affix_top_menu = request.params.get('no_affix_top_menu')
    no_affix_top_menu = False if no_affix_top_menu else True
    values = {
        'no_footer': no_footer,
        'no_affix_top_menu': no_affix_top_menu,
        'usercenter_menu': usercenter_menu_used,
        'execute_code': self.execute_code,
        'urllib': urllib,
        'centerjscss': True
    }
    return request.render("web_user_center.miancenter", values)

@api.model
def execute_code(self, code_exec):
    localdict = {
        'cr': request.env.cr,
        'uid': request.env.uid,
        'request': request,  # 请求
        'result': None,  # 用于存储返回结果
        '_': _,
    }
    safe_eval(code_exec, localdict, mode="exec", nocopy=True)
    result = localdict['result']
    return result

 

你可能感兴趣的:(odoo)