zoukankan      html  css  js  c++  java
  • Relax NG 在Odoo中的应用

    想必有些同学一定会奇怪,Odoo是如何将模块中的XML中的诸如record、menuitem是如何被组织和定义的,以及各种field的各种属性究竟有哪些,今天,我们就来一探究竟。

    Relax NG:可扩展标记语言的下一代正规语言”是一种基于语法的可扩展标记语言模式语言,可用于描述、定义和限制 可扩展标记语言标准通用标记语言的子集)词汇表。简单地说 Relax NG是解释XML如何被定义的一套XML。Odoo就是通过定义了一套rng文件定义了自己一套xml框架结构,在模块被安装或者升级的时候将其解析成与之相对应的内置对象,存储在数据库中。关于Relax NG的语法规则,可以参考Relax NG的官网。

    解析XML文件的代码在convert.py的convert_xml_import方法中:

    def convert_xml_import(cr, module, xmlfile, idref=None, mode='init', noupdate=False, report=None):
        doc = etree.parse(xmlfile)
        relaxng = etree.RelaxNG(
            etree.parse(os.path.join(config['root_path'],'import_xml.rng' )))
        try:
            relaxng.assert_(doc)
        except Exception:
            _logger.error('The XML file does not fit the required schema !')
            _logger.error(misc.ustr(relaxng.error_log.last_error))
            raise
    
        if idref is None:
            idref={}
        obj = xml_import(cr, module, idref, mode, report=report, noupdate=noupdate)
        obj.parse(doc.getroot(), mode=mode)
        return True

    而在xml_import方法中,处理了我们常见的各种节点:menuitem,record,template,url等等。

    通过对rng文件的解读,我们可以总结Odoo xml的架构如下:

    顶级节点:openerp

    二级节点:元素(可多个):data

         属性 (可选): noupdate、context

    三级节点:元素(可多个):menuitem、record、template、delete、act_window、url、assert、report、workflow、function、ir_set

    常见节点属性:

    menuitem:id(必填),name,parent,action,sequence,groups,icon,web_icon,web_icon_hover,string

    record:id(可选),forcecreate(可选),model,context(可选),

                子节点:field(可多个)

    template:id,t-name,name,forecreate,context,priority,inherit_id,primary,groups,active,customzie_show,page

    delete:model,id,search

    act_window:id,name,res_model,domain,src_model,context,view_id,view_type,view_mode,multi,target,key2,groups,limit,usage,auto_refresh

    url:id,name,url,target

    assert:model,search,count,string,id,context,severity,test

    report:id,string,model,name,report_type,multi,menu,keyword,rml,file,sxw,xml,xsl,parser,auto,header,webkit_header,attachment,attachment_use,groups,usage

    workflow:model,action,uid,context,ref,value

    function:model,name,id,context,eval

    ir_set:子节点:field

    同样地,在View中也同样用到了Relax NG组织定义了View的架构,具体参见我的另一篇文章:

    http://www.cnblogs.com/kfx2007/p/5478375.html

  • 相关阅读:
    tcp流协议产生的粘包问题和解决方案
    使用fork并发处理多个client的请求和对等通信p2p
    最简单的回射客户/服务器程序、time_wait 状态
    C/S程序的一般流程和基本socket函数
    socket概述和字节序、地址转换函数
    IP数据报格式和IP地址路由
    利用ARP和ICMP协议解释ping命令
    TCP/IP协议栈与数据报封装
    从汇编角度来理解linux下多层函数调用堆栈运行状态
    read/write函数与(非)阻塞I/O的概念
  • 原文地址:https://www.cnblogs.com/kfx2007/p/5478338.html
Copyright © 2011-2022 走看看