Base class for request/session

class cubicweb.req.RequestSessionBase(vreg)[source]#

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.

build_url(*args, **kwargs)[source]#

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.

raises ValueError if None is found in arguments


return encoded params to incorporate them in a URL

build_url_path(method, kwargs)[source]#

return the “path” part of an URL

create_entity(etype, **kwargs)[source]#

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)
eid_rset(eid, etype=None)[source]#

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

entity_from_eid(eid, etype=None)[source]#

return an entity instance for the given eid. No query is done

etype_rset(etype, size=1)[source]#

return a fake result set for a particular entity type

exists(etype, **kwargs)[source]#

return if it exists at least one entity of the given type and attribute values.

>>> is_stallman_there = cnx.exists('CWUser', login=u"rms")
>>> # more optimized than
>>> is_stallman_there = bool(cnx.find('CWUser', login=u"rms"))
>>> # it did a full scan table :-/
find(etype, limit=None, **kwargs)[source]#

find entities of the given type and attribute values.

  • etype – the type of entities to return.

  • limit – the max number of entities to return.


A ResultSet

>>> users = find('CWGroup', name=u"users").one()
>>> groups = find('CWGroup').entities()
format_date(date, date_format=None, time=False)[source]#

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

parse_datetime(value, etype='Datetime')[source]#

get a datetime or time from a string (according to etype) Datetime formatted as Date are accepted

printable_value(attrtype, value, props=None, displaytime=True, formatters={'BigInt': <function print_int>, 'Boolean': <function print_boolean>, 'Bytes': <function print_bytes>, 'Date': <function print_date>, 'Datetime': <function print_datetime>, 'Decimal': <function print_float>, 'Float': <function print_float>, 'Int': <function print_int>, 'Interval': <function print_timedelta>, 'String': <function print_string>, 'TZDatetime': <function print_tzdatetime>, 'TZTime': <function print_tztime>, 'Time': <function print_time>})[source]#

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

rebuild_url(url, **newparams)[source]#

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

url_quote(value, safe='')[source]#

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.

The keys are :


The user login


The user name, returned by


The user principal email

view(_RequestSessionBase__vid, rset=None, _RequestSessionBase__fallback_oid=None, _RequestSessionBase__registry='views', initargs=None, w=None, **kwargs)[source]#

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..