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
Relax NG 在Odoo中的应用的更多相关文章
- 利用Python的三元表达式解决Odoo中工资条中城镇、农村保险的问题
Python中没有像C#中有三元表达式 A?B:C 但在python中可以通过 A if condition else B 的方式来达到同样的效果. 例如 : 1 if True else 0 输出 ...
- (19)odoo中的javascript
-----------更新日期15:17 2016-02-16 星期二-----------* 用到的js库 我们可以打开 addons/web/views/webclient_template. ...
- 我在 B 站学机器学习(Machine Learning)- 吴恩达(Andrew Ng)【中英双语】
我在 B 站学机器学习(Machine Learning)- 吴恩达(Andrew Ng)[中英双语] 视频地址:https://www.bilibili.com/video/av9912938/ t ...
- Odoo 中使用 celery 实现高性能异步任务队列
详见:http://www.oejia.net/blog/2018/07/09/odoo_task_queue.html 概述 在 odoo 中可以用自带的cron实现异步任务,这个cron基于多线程 ...
- odoo中def init(self):
# -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. f ...
- odoo中self的使用
一:self是什么 目前新版的Odoo中使用到的self,是对 游标cr.用户ID.模型.上下文.记录集.缓存 的封装. 我们可以通过 self.XX 获取到这些封装的东西,比如:self.cr. ...
- odoo中的ORM操作
ORM方法简介 OpenERP的关键组件, ORM是一个完整的对象关系映射层,是开发人员不必编写基本的SQL管道. 业务对象被声明继承字models.Models的python类. 这让业务对象在OR ...
- Odoo中连接mysql数据库
how to integrate Odoo with MySQL - Stack Overflowhttps://stackoverflow.com/questions/31959919/how-to ...
- Odoo中使用的数据模型
Odoo中使用的部分表如下, res_users 用户 res_groups 用户组(角色) res_lang 语言 res_partner 供应商/客户/联系人 res_font 字体 res_co ...
随机推荐
- Waiting Processed Cancelable ShowDialog (Release 2)
namespace Test { using System; using System.Windows.Forms; static class Program { /// <summary> ...
- xcrun: error: active developer path ("/XX") does not exist
MAC OS 10.9下执行命令 svn --version 报出如下错误: xcrun: error: active developer path ("/Users/username/Do ...
- 在Asp.Net MVC中实现RequiredIf标签对Model中的属性进行验证
在Asp.Net MVC中可以用继承ValidationAttribute的方式,自定制实现RequiredIf标签对Model中的属性进行验证 具体场景为:某一属性是否允许为null的验证,要根据另 ...
- HDU 5876 Sparse Graph BFS 最短路
Sparse Graph Problem Description In graph theory, the complement of a graph G is a graph H on the ...
- python web编程-CGI帮助web服务器处理客户端编程
这几篇博客均来自python核心编程 如果你有任何疑问,欢迎联系我或者仔细查看这本书的地20章 另外推荐下这本书,希望对学习python的同学有所帮助 概念预热 eb客户端通过url请求web服务器里 ...
- linux下SVN忽略文件/文件夹的方法
linux下SVN忽略文件/文件夹的方法 假设想忽略文件temp 1. cd到temp所在的目录下: 2. svn propedit svn:ignore . 注意:请别漏掉最后的点(.表示当前目录) ...
- PE文件的执行顺序
当一个PE文件被执行时,PE装载器首先检查DOS MZ header里的PE header的偏移量.如果找到,则直接跳转到PE header的位置. 当PE装载器跳转到PE header后,第二步要做 ...
- flex_宽度补全
宽度40px,另一个的补全宽度: <!DOCTYPE html> <html lang="en"> <head> <meta charse ...
- html php 重定向 跳转 刷新
1秒后跳转 法一: <!DOCTYPE HTML> <html> <head> <meta http-equiv="refresh" ...
- 7.Android常用第三方支付
移动支付 用户使用移动的终端完成对所购买商品或者服务的支付功能;分为近场支付(蓝牙支付,刷卡,滴卡),和远程支付(网上支付,短信支付) app支付模块 常见的支付厂商-->常见的支付方式 支付宝 ...