initialization and setup of the request object (the dispatching itself has
to be handled by the subclasses)
- :param request: a wrapped werkzeug Request object
- :type request: :class:`werkzeug.wrappers.BaseRequest`
+ :param httprequest: a wrapped werkzeug Request object
+ :type httprequest: :class:`werkzeug.wrappers.BaseRequest`
.. attribute:: httprequest
.. deprecated:: 8.0
- Use ``self.session`` instead.
+ Use :attr:`session` instead.
.. attribute:: params
.. attribute:: session_id
- opaque identifier for the :class:`session.OpenERPSession` instance of
+ opaque identifier for the :class:`OpenERPSession` instance of
the current request
.. attribute:: session
.. attribute:: context
- :class:`~collections.Mapping` of context values for the current request
+ :class:`~collections.Mapping` of context values for the current
+ request
.. attribute:: db
- ``str``, the name of the database linked to the current request. Can be ``None``
- if the current request uses the ``none`` authentication.
+ ``str``, the name of the database linked to the current request. Can
+ be ``None`` if the current request uses the ``none`` authentication.
.. attribute:: uid
- ``int``, the id of the user related to the current request. Can be ``None``
- if the current request uses the ``none`` authenticatoin.
+ ``int``, the id of the user related to the current request. Can be
+ ``None`` if the current request uses the ``none`` authentication.
"""
def __init__(self, httprequest):
self.httprequest = httprequest
@property
def registry(self):
"""
- The registry to the database linked to this request. Can be ``None`` if the current request uses the
- ``none'' authentication.
+ The registry to the database linked to this request. Can be ``None``
+ if the current request uses the ``none`` authentication.
"""
return openerp.modules.registry.RegistryManager.get(self.db) if self.db else None
@property
def db(self):
"""
- The registry to the database linked to this request. Can be ``None`` if the current request uses the
- ``none'' authentication.
+ The registry to the database linked to this request. Can be ``None``
+ if the current request uses the ``none`` authentication.
"""
return self.session.db if not self.disable_db else None
@property
def cr(self):
"""
- The cursor initialized for the current method call. If the current request uses the ``none`` authentication
- trying to access this property will raise an exception.
+ The cursor initialized for the current method call. If the current
+ request uses the ``none`` authentication trying to access this
+ property will raise an exception.
"""
# some magic to lazy create the cr
if not self._cr:
def 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``.
-
- :param 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/ ).
+ Decorator marking the decorated method as being a handler for
+ requests. The method must be part of a subclass of ``Controller``.
+
+ :param 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/ ).
:param type: The type of request, can be ``'http'`` or ``'json'``.
:param 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.
- * ``admin``: The user may not be authenticated and the current request will perform using the admin 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.
- :param methods: A sequence of http methods this route applies to. If not specified, all methods are allowed.
+ * ``user``: The user must be authenticated and the current request
+ will perform using the rights of the user.
+ * ``admin``: The user may not be authenticated and the current request
+ will perform using the admin 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.
+
+ :param methods: A sequence of http methods this route applies to. If not
+ specified, all methods are allowed.
:param cors: The Access-Control-Allow-Origin cors directive value.
"""
routing = kw.copy()
response = {
'jsonrpc': '2.0',
'id': self.jsonrequest.get('id')
- }
+ }
if error is not None:
response['error'] = error
if result is not None:
def jsonrequest(f):
"""
.. deprecated:: 8.0
-
- Use the ``route()`` decorator instead.
+ Use the :func:`~openerp.http.route` decorator instead.
"""
base = f.__name__.lstrip('/')
if f.__name__ == "index":
"""
.. deprecated:: 8.0
- Use the ``route()`` decorator instead.
+ Use the :func:`~openerp.http.route` decorator instead.
"""
base = f.__name__.lstrip('/')
if f.__name__ == "index":
class Service(object):
"""
.. deprecated:: 8.0
- Use ``dispatch_rpc()`` instead.
+ Use :func:`dispatch_rpc` instead.
"""
def __init__(self, session, service_name):
self.session = session
class Model(object):
"""
.. deprecated:: 8.0
- Use the resistry and cursor in ``openerp.http.request`` instead.
+ Use the registry and cursor in :data:`request` instead.
"""
def __init__(self, session, model):
self.session = session
def authenticate(self, db, login=None, password=None, uid=None):
"""
- Authenticate the current user with the given db, login and password. If successful, store
- the authentication parameters in the current session and request.
+ Authenticate the current user with the given db, login and
+ password. If successful, store the authentication parameters in the
+ current session and request.
- :param uid: If not None, that user id will be used instead the login to authenticate the user.
+ :param uid: If not None, that user id will be used instead the login
+ to authenticate the user.
"""
if uid is None:
def check_security(self):
"""
- Chech the current authentication parameters to know if those are still valid. This method
- should be called at each request. If the authentication fails, a ``SessionExpiredException``
- is raised.
+ Check the current authentication parameters to know if those are still
+ valid. This method should be called at each request. If the
+ authentication fails, a :exc:`SessionExpiredException` is raised.
"""
if not self.db or not self.uid:
raise SessionExpiredException("Session expired")
def get_context(self):
"""
- Re-initializes the current user's session context (based on
- his preferences) by calling res.users.get_context() with the old
- context.
+ Re-initializes the current user's session context (based on his
+ preferences) by calling res.users.get_context() with the old context.
:returns: the new context
"""
# Deprecated to be removed in 9
"""
- Damn properties for retro-compatibility. All of that is deprecated, all
- of that.
+ Damn properties for retro-compatibility. All of that is deprecated,
+ all of that.
"""
@property
def _db(self):
def send(self, service_name, method, *args):
"""
.. deprecated:: 8.0
- Use ``dispatch_rpc()`` instead.
+ Use :func:`dispatch_rpc` instead.
"""
return dispatch_rpc(service_name, method, args)
def proxy(self, service):
"""
.. deprecated:: 8.0
- Use ``dispatch_rpc()`` instead.
+ Use :func:`dispatch_rpc` instead.
"""
return Service(self, service)
def assert_valid(self, force=False):
"""
.. deprecated:: 8.0
- Use ``check_security()`` instead.
+ Use :meth:`check_security` instead.
Ensures this session is valid (logged into the openerp server)
"""
def ensure_valid(self):
"""
.. deprecated:: 8.0
- Use ``check_security()`` instead.
+ Use :meth:`check_security` instead.
"""
if self.uid:
try:
def execute(self, model, func, *l, **d):
"""
.. deprecated:: 8.0
- Use the resistry and cursor in ``openerp.addons.web.http.request`` instead.
+ Use the registry and cursor in :data:`request` instead.
"""
model = self.model(model)
r = getattr(model, func)(*l, **d)
def exec_workflow(self, model, id, signal):
"""
.. deprecated:: 8.0
- Use the resistry and cursor in ``openerp.addons.web.http.request`` instead.
+ Use the registry and cursor in :data:`request` instead.
"""
self.assert_valid()
r = self.proxy('object').exec_workflow(self.db, self.uid, self.password, model, signal, id)
def model(self, model):
"""
.. deprecated:: 8.0
- Use the resistry and cursor in ``openerp.addons.web.http.request`` instead.
+ Use the registry and cursor in :data:`request` instead.
Get an RPC proxy for the object ``model``, bound to this session.
if statics:
_logger.info("HTTP Configuring static files")
- app = werkzeug.wsgi.SharedDataMiddleware(self.dispatch, statics)
- self.dispatch = DisableCacheMiddleware(app)
+ app = werkzeug.wsgi.SharedDataMiddleware(self.dispatch, statics)
+ self.dispatch = DisableCacheMiddleware(app)
def setup_session(self, httprequest):
# recover or create session