odoo web controller
2021-06-07 16:03
标签:change poco request control rip session short default sse Decorator marking the decorated method as being a handler for requests. The method must be part of a subclass of The type of authentication method, can on of the following: The request object is automatically set on 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) the original The a Accessing the cursor when the current request uses the Indicates whether the current request is in "debug" mode opaque identifier for the Deprecated since version 8.0:Use the The registry to the database linked to this request. Can be Deprecated since version 8.0:use The database linked to this request. Can be HTTP session data Deprecated since version 8.0:Use Handler for the 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: 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. Shortcut for a HTTP 404 (Not Found) response 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. Request handler for JSON-RPC 2 over HTTP Sucessful request: Request producing a error: Response object passed through controller route chain. In addition to the 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 Renders the Response‘s template, returns the result Forces the rendering of the response‘s template, sets the result as response body and unsets Controllers need to provide extensibility, much like Controllers thus provide their own extension mechanism, separate from that of models: Controllers are created by inheriting from and defining methods decorated with To override a controller, inherit from its class and override relevant methods, re-exposing them if necessary: 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.: will change odoo web controller 标签:change poco request control rip session short default sse 原文地址:http://www.cnblogs.com/dancesir/p/7324936.htmlRouting
openerp.http.route(route=None, **kw)
Controller
.
‘http‘
or ‘json‘
.
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.Request
openerp.http.request
at the start of the requestclass openerp.http.WebRequest(httprequest)
werkzeug.wrappers.BaseRequest
) -- a wrapped werkzeug Request objecthttprequest
werkzeug.wrappers.Request
object provided to the requestparams
Mapping
of request parameters, not generally useful as they‘re provided directly to the handler method as keyword argumentsenv
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 requestsession
OpenERPSession
holding the HTTP session data for the current http sessioncr
Cursor
initialized for the current method call.none
authentication will raise an exception.debug
session_id
OpenERPSession
instance of the current requestsid
attribute on session
registry
None
if the current request uses the none
authentication.env
db
None
if the current request uses the none
authentication.httpsession
session
instead.class openerp.http.HttpRequest(*args)
http
request type.
str
or unicode
, will be wrapped in a Response object and interpreted as HTMLmake_response(data, headers=None, cookies=None)
basestring
) -- response body[(name, value)]
) -- HTTP headers to set on the responsecollections.Mapping
) -- cookies to set on the clientnot_found(description=None)
render(template, qcontext=None, lazy=True, **kw)
basestring
) -- template to renderdict
) -- Rendering context to usebool
) -- whether the template rendering should be deferred until the last possible momentclass openerp.http.JsonRequest(*args)
method
is ignoredparams
must be a JSON object (not an array) and is passed as keyword arguments to the handler methodresult
and wrapped in the JSON-RPC Response--> {"jsonrpc": "2.0",
"method": "call",
"params": {"context": {},
"arg1": "val1" },
"id": null}
--> {"jsonrpc": "2.0",
"method": "call",
"params": {"context": {},
"arg1": "val1" },
"id": null}
Response
class openerp.http.Response(*args, **kw)
werkzeug.wrappers.Response
parameters, this class‘s constructor can take the following additional parameters for QWeb Lazy Rendering.
basestring
) -- template to renderdict
) -- Rendering context to useint
) -- User id to use for the ir.ui.view render call, None
to use the request‘s user (the default)werkzeug.wrappers.Response
.render()
flatten()
template
Controllers
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).class openerp.http.Controller
route()
:class MyController(openerp.http.Controller):
@route(‘/some_url‘, auth=‘public‘)
def handler(self):
return stuff()
class Extension(MyController):
@route()
def handler(self):
do_before()
return super(Extension, self).handler()
route()
is necessary to keep the method (and route) visible: if the method is redefined without decorating, it will be "unpublished"class Restrict(MyController):
@route(auth=‘user‘)
def handler(self):
return super(Restrict, self).handler()
/some_url
from public authentication to user (requiring a log-in)