odoo web controller
Routing
openerp.http.route(route=None, **kw)
Decorator marking the decorated method as being a handler for requests. The method must be part of a subclass of Controller
.
装饰器可以将对应方法装饰为处理对应的http请求,该方法须是Controller的子类。
- route -- string or array. The route part that will determine which http requests will match the decorated method. Can be a single string or an array of strings. See werkzeug's routing documentation for the format of route expression ( http://werkzeug.pocoo.org/docs/routing/ ).
- 字符串或数组,决定哪个http请求匹配所装饰的方法,可以是单个字符串、或多个字符串的数组
- type -- The type of request, can be
'http'
or'json'
.- 请求的类型,可以是http或json
- auth --
The type of authentication method, can on of the following:
user
: The user must be authenticated and the current request will perform using the rights of the user.- 必须是认证的用户,该请求基于已认证的用户
public
: The user may or may not be authenticated. If she isn't, the current request will perform using the shared Public user.- 当不通过认证访问时使用公用的认证
none
: The method is always active, even if there is no database. Mainly used by the framework and authentication modules. There request code will not have any facilities to access the database nor have any configuration indicating the current database nor the current user.- 相应的方法总是可用,一般用于框架和认证模块,对应请求没有办法访问数据库或指向数据库的设置
- methods -- A sequence of http methods this route applies to. If not specified, all methods are allowed.
- 这个请求所应用的一系列http方法,如果没指定则是所有方法
- cors -- The Access-Control-Allow-Origin cors directive value.
- 跨域资源cors参数
Request
The request object is automatically set on openerp.http.request
at the start of the request
请求对象在收到请求时自动设置到openerp.http.request。
class openerp.http.WebRequest(httprequest)
Parent class for all Odoo Web request types, mostly deals with initialization and setup of the request object (the dispatching itself has to be handled by the subclasses)
所有odoo WEB请求的父类,一般用于进行请求对象的初始化
- httprequest
- params 请求参数的映射
- cr
- context
- env
- session
- debug
- db
- csrf_token(time_limit=3600) 为该请求生成并返回一个token(参数以秒计算,默认1小时,如果传None表示与当前用户session时间相同)
werkzeug.wrappers.BaseRequest
) -- a wrapped werkzeug Request objecthttprequest
the original werkzeug.wrappers.Request
object provided to the request
- 原始的werkzeug.wrappers.Request对象
params
Mapping
of request parameters, not generally useful as they're provided directly to the handler method as keyword arguments
- 请求参数的映射
env
The Environment
bound to current request. Raises a RuntimeError
if the current requests is not bound to a database.
- 绑定到当前请求的环境
context
Mapping
of context values for the current request
- 当前请求的上下文键值映射
session
a OpenERPSession
holding the HTTP session data for the current http session
- 储存当前请求session数据的OpenERPSession
cr
Cursor
initialized for the current method call.
Accessing the cursor when the current request uses the none
authentication will raise an exception.
- 当前方法调用的初始游标,当使用none的认证方式时读取游标会报错
debug
Indicates whether the current request is in "debug" mode
- 指定当前请求是否是debug模式
session_id
opaque identifier for the OpenERPSession
instance of the current request
Deprecated since version 8.0:Use the sid
attribute on session
registry
The registry to the database linked to this request. Can be None
if the current request uses the none
authentication.
Deprecated since version 8.0:use env
db
The database linked to this request. Can be None
if the current request uses the none
authentication.
- 当前请求所关联的数据库,当使用none认证时为None
httpsession
HTTP session data
Deprecated since version 8.0:Use session
instead.
class openerp.http.HttpRequest(*args)
Handler for the http
request type.
matched routing parameters, query string parameters, form parameters and files are passed to the handler method as keyword arguments.
In case of name conflict, routing parameters have priority.
The handler method's result can be:
- a falsy value, in which case the HTTP response will be an HTTP 204 (No Content)
- a werkzeug Response object, which is returned as-is
- a
str
orunicode
, will be wrapped in a Response object and interpreted as HTML
make_response(data, headers=None, cookies=None)
Helper for non-HTML responses, or HTML responses with custom response headers or cookies.
While handlers can just return the HTML markup of a page they want to send as a string if non-HTML data is returned they need to create a complete response object, or the returned data will not be correctly interpreted by the clients.
- data (
basestring
) -- response body - headers (
[(name, value)]
) -- HTTP headers to set on the response - cookies (
collections.Mapping
) -- cookies to set on the client
not_found(description=None)
Shortcut for a HTTP 404 (Not Found) response
render(template, qcontext=None, lazy=True, **kw)
Lazy render of a QWeb template.
The actual rendering of the given template will occur at then end of the dispatching. Meanwhile, the template and/or qcontext can be altered or even replaced by a static response.
- template (
basestring
) -- template to render - qcontext (
dict
) -- Rendering context to use - lazy (
bool
) -- whether the template rendering should be deferred until the last possible moment - kw -- forwarded to werkzeug's Response object
class openerp.http.JsonRequest(*args)
Request handler for JSON-RPC 2 over HTTP
method
is ignoredparams
must be a JSON object (not an array) and is passed as keyword arguments to the handler method- the handler method's result is returned as JSON-RPC
result
and wrapped in the JSON-RPC Response
Sucessful request:
- --> {"jsonrpc": "2.0",
- "method": "call",
- "params": {"context": {},
- "arg1": "val1" },
- "id": null}
- <-- {"jsonrpc": "2.0",
- "result": { "res1": "val1" },
- "id": null}
Request producing a error:
- --> {"jsonrpc": "2.0",
- "method": "call",
- "params": {"context": {},
- "arg1": "val1" },
- "id": null}
- <-- {"jsonrpc": "2.0",
- "error": {"code": 1,
- "message": "End user error message.",
- "data": {"code": "codestring",
- "debug": "traceback" } },
- "id": null}
Response
class openerp.http.Response(*args, **kw)
Response object passed through controller route chain.
In addition to the werkzeug.wrappers.Response
parameters, this class's constructor can take the following additional parameters for QWeb Lazy Rendering.
- template (
basestring
) -- template to render - qcontext (
dict
) -- Rendering context to use - uid (
int
) -- User id to use for the ir.ui.view render call,None
to use the request's user (the default)
these attributes are available as parameters on the Response object and can be altered at any time before rendering
Also exposes all the attributes and methods of werkzeug.wrappers.Response
.
render()
Renders the Response's template, returns the result
flatten()
Forces the rendering of the response's template, sets the result as response body and unsets template
Controllers
Controllers need to provide extensibility, much like Model
, but can't use the same mechanism as the pre-requisites (a database with loaded modules) may not be available yet (e.g. no database created, or no database selected).
Controllers thus provide their own extension mechanism, separate from that of models:
Controllers are created by inheriting from
class openerp.http.Controller
and defining methods decorated with route()
:
- class MyController(openerp.http.Controller):
- @route('/some_url', auth='public')
- def handler(self):
- return stuff()
To override a controller, inherit from its class and override relevant methods, re-exposing them if necessary:
- class Extension(MyController):
- @route()
- def handler(self):
- do_before()
- return super(Extension, self).handler()
- decorating with
route()
is necessary to keep the method (and route) visible: if the method is redefined without decorating, it will be "unpublished" the decorators of all methods are combined, if the overriding method's decorator has no argument all previous ones will be kept, any provided argument will override previously defined ones e.g.:
- class Restrict(MyController):
- @route(auth='user')
- def handler(self):
- return super(Restrict, self).handler()
will change
/some_url
from public authentication to user (requiring a log-in)- class Restrict(MyController):
odoo web controller的更多相关文章
- Odoo Web Service API
来自 Odoo Web服务暴露出相关的服务,路由分别是 /xmlrpc/ /xmlrpc/2/ /jsonrpc 根据 services 调用 后端对应服务的 方法method [定义 openerp ...
- odoo10学习笔记十二:web controller
转载请注明原文地址:https://www.cnblogs.com/ygj0930/p/11189332.html 一:路由 odoo.http.route(route=None, **kw) 装饰器 ...
- odoo中Controller
一:Controller 一般通过继承的形式来创建controller类,继承自odoo.http.Controller. 以route装饰器来装饰定义的方法,提供url路由访问路径: class M ...
- Spring Cloud Ribbon负载均衡配置类放在Spring boot主类同级增加Exclude过滤后报Field config in com.cloud.web.controller.RibbonConfiguration required a bean of type 'com.netflix.client.config.IClientConfig' that could not b
环境: Spring Cloud:Finchley.M8 Spring Boot:2.0.0.RELEASE 目录结构: 可以看到代码第13行的注释,我已经在@ComponentScan注解中添加了E ...
- 【odoo14】第十六章、odoo web库(OWL)
odoo14引入了名为OWL(Odoo Web Library)的JavaScript框架.OWL是以组件为基础的UI框架,通过QWeb模板作为架构.OWL与传统的组件系统相比更快,并引入了一些新的特 ...
- OpenERP|odoo Web开发
在OpenERP 7 和 Odoo 8下测试均可. 1.相关库/框架 主要:jQuery(使用1.8.3,如果使用新版本,其他jQuery插件也要升级或修改).Underscore.Qweb 其他:都 ...
- 记一次odoo创建新的模块时,但是在odoo web界面找不到应用的案例
原因就是在odoo.conf配置文件中没有说明 模块查找的路径
- odoo14--odoo前端框架owl【odoo web library】
原文链接:https://www.alanhou.org/odoo-14-owl-todolist/ 1.组件树 Root / \ A B / \ ...
- odoo开发笔记 -- odoo web机制浅析
http://blog.csdn.net/M0relia/article/details/39025947
随机推荐
- AM历史消息及文件记录删除
1.下载 folderclear.bat 文件 2.用编辑方式打开这个文件 3.对里面的参数做修改 4.这个批处理文件,保留了 完整的一个月的消息记录 (如 今天是 2017.3.15 ,那么 清除数 ...
- css - 常见知识点
1. 盒模型 页面渲染时,dom 元素所采用的 布局模型.可通过box-sizing进行设置.根据计算宽高的区域可分为: content-box (W3C 标准盒模型) border-box (IE ...
- 菜鸟nginx源码剖析数据结构篇(二) 双向链表ngx_queue_t[转]
nginx源码剖析数据结构篇(二) 双向链表ngx_queue_t Author:Echo Chen(陈斌) Email:chenb19870707@gmail.com Blog:Blog.csdn. ...
- Android之TableLayout表格布局
1.相关属性 1.1.常用属性 android:collapseColumns 设置需要被隐藏的列的序列号 android:shrinkColumns 设置允许被收缩的列的序列号 android:st ...
- iOS开发之IMP和SEL(方法和类的反射)
1.SEL:类方法的指针,相当于一种编号,区别与IMP! IMP:函数指针,保存了方法的地址! SEL是通过表取对应关系的IMP,进行方法的调用! 2.获取SEL和IMP方法和调用: SEL meth ...
- linux 最新化安装后安卓 KDE 桌面
yum -y install epel-releaseyum -y groupinstall "X Window System"yum -y groupinstall " ...
- MyBatis - Mapper动态代理开发
Mapper接口开发方法编写Mapper接口(相当于Dao接口),由Mybatis框架根据接口定义创建接口的动态代理对象. Mapper接口开发方式是基于入门程序的基础上,对 控制程序 进行分层开发, ...
- Struts2OGNL
OGNL: 什么是OGNL Object Graph Navigation Language 开源项目,取代页面中Java脚本,简化数据访问 和EL同属于表达式语言,但功能更为强大 OGNL在St ...
- 使用HTTP代理
HTTP代理服务器可以比作客户端与Web服务器网站之间的一个信息中转站,客户端发送的HTTP请求和Web服务器返回的HTTP响应通过代理服务器转发给对方, 爬虫程序在爬取某些网站的时候也需要使用代理, ...
- Mkdir- Linux必学的60个命令
1.作用 mkdir命令的作用是建立名称为dirname的子目录,与MS DOS下的md命令类似,它的使用权限是所有用户. 2.格式 mkdir [options] 目录名 3.[options]主要 ...