A request instance is created when an HTTP request is sent to the web server. It contains informations such as form parameters, authenticated user, etc. It is a very prevalent object and is used throughout all of the framework and applications, as you’ll access to almost every resources through it.
A request represents a user query, either through HTTP or not (we also talk about RQL queries on the server side for example).
Here is a non-exhaustive list of attributes and methods available on request objects (grouped by category):
- get_cookie(), returns a dictionary containing the value of the header HTTP ‘Cookie’
- set_cookie(cookie, key, maxage=300), adds a header HTTP Set-Cookie, with a minimal 5 minutes length of duration by default (maxage = None returns a session cookie which will expire when the user closes the browser window)
- remove_cookie(cookie, key), forces a value to expire
Please note that this class is abstract and that a concrete implementation will be provided by the frontend web used (in particular twisted as of today). For the views or others that are executed on the server side, most of the interface of Request is defined in the session associated to the client.
The elements we gave in overview for above are built in three layers, from cubicweb.req.RequestSessionBase, cubicweb.repoapi.ClientConnection and cubicweb.web.ConnectionCubicWebRequestBase.
base class containing stuff shared by server session and web request
request/session is the main resources accessor, mainly through it’s vreg attribute:
Attribute vreg: | the instance’s registry |
---|---|
Attribute vreg.schema: | |
the instance’s schema | |
Attribute vreg.config: | |
the instance’s configuration |
return the root url of the instance
return an absolute URL using params dictionary key/values as URL parameters. Values are automatically URL quoted, and the publishing method to use may be specified or will be guessed.
if __secure__ argument is True, the request will try to build a https url.
raises ValueError if None is found in arguments
return encoded params to incorporate them in an URL
add a new entity of the given type
Example (in a shell session):
>>> c = create_entity('Company', name=u'Logilab')
>>> create_entity('Person', firstname=u'John', surname=u'Doe',
... works_for=c)
return a tuple (type, sourceuri, extid) for the entity with id <eid>
return a result set for the given eid without doing actual query (we have the eid, we can suppose it exists and user has access to the entity)
return a guaranteed empty result
raise an exception if the given rql is not a select query
return an entity instance for the given eid. No query is done
return a fake result set for a particular entity type
find entities of the given type and attribute values.
Returns: | A ResultSet |
---|
>>> users = find('CWGroup', name=u"users").one()
>>> groups = find('CWGroup').entities()
return a string for a date time according to instance’s configuration
return a string for floating point number according to instance’s configuration
return a string for a time according to instance’s configuration
cachename should be dotted names as in :
get a datetime or time from a string (according to etype) Datetime formatted as Date are accepted
return a displayablye value (i.e. unicode string)
return value of the property with the given key, giving priority to user specific value if any, else using site value
return the given url with newparams inserted. If any new params is already specified in the url, it’s overriden by the new value
newparams may only be mono-valued.
install i18n configuration for lang translation.
Raises KeyError if translation doesn’t exist.
return a list of (key, val) found in the url quoted query string
urllib.quote is not unicode safe, use this method to do the necessary encoding / decoding. Also it’s designed to quote each part of a url path and so the ‘/’ character will be encoded as well.
returns a unicode unquoted string
decoding is based on self.encoding which is the encoding used in url_quote
returns a dictionary with this user’s information
Select object with the given id (__oid) then render it. If the object isn’t selectable, try to select fallback object if __fallback_oid is specified.
If specified initargs is expected to be a dictionary containing arguments that should be given to selection (hence to object’s __init__ as well), but not to render(). Other arbitrary keyword arguments will be given to selection and to render(), and so should be handled by object’s call or cell_call method..
A Connection object to be used Client side.
This object is aimed to be used client side (so potential communication with the repo through RPC) and aims to offer some compatibility with the cubicweb.dbapi.Connection interface.
The autoclose_session parameter informs the connection that this session has been opened explicitly and only for this client connection. The connection will close the session on exit.
Exception raised for errors that are related to the database’s operation and not necessarily under the control of the programmer, e.g. an unexpected disconnect occurs, the data source name is not found, a transaction could not be processed, a memory allocation error occurred during processing, etc.
Return the value for option in the configuration.
Return the schema currently used by the repository.
Return the definition of sources used by the repository.
Return an ordered list of action effectued during that transaction.
If public is true, return only ‘public’ actions, eg not ones triggered under the cover by hooks, else return all actions.
raise NoSuchTransaction if the transaction is not found or if session’s user is not allowed (eg not in managers group and the transaction doesn’t belong to him).
Return transaction object for the given uid.
raise NoSuchTransaction if not found or if session’s user is not allowed (eg not in managers group and the transaction doesn’t belong to him).
Undo the given transaction. Return potential restoration errors.
raise NoSuchTransaction if not found or if session’s user is not allowed (eg not in managers group and the transaction doesn’t belong to him).
Return a list of undoable transaction objects by the connection’s user, ordered by descendant transaction time.
Managers may filter according to user (eid) who has done the transaction using the ueid argument. Others will only see their own transactions.
Additional filtering capabilities is provided by using the following named arguments: