Base class for request/session

exception cubicweb.req.FindEntityError[source]

raised when find_one_entity() can not return one and only one entity

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.

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 a 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)
describe(eid, asdict=False)[source]

return a tuple (type, sourceuri, extid) for the entity with id <eid>

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

find(etype, **kwargs)[source]

find entities of the given type and attribute values.

Returns: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


cachename should be dotted names as in :

  • cubicweb.mycache
  • etc.
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={'Interval': <function print_timedelta at 0x7f5f5353fe60>, 'Decimal': <function print_float at 0x7f5f5353ff50>, 'TZTime': <function print_tztime at 0x7f5f5353fcf8>, 'Bytes': <function print_bytes at 0x7f5f5353faa0>, 'TZDatetime': <function print_tzdatetime at 0x7f5f5353fde8>, 'BigInt': <function print_int at 0x7f5f5353fb90>, 'Time': <function print_time at 0x7f5f5353fc80>, 'String': <function print_string at 0x7f5f5353fb18>, 'Int': <function print_int at 0x7f5f5353fb90>, 'Float': <function print_float at 0x7f5f5353ff50>, 'Datetime': <function print_datetime at 0x7f5f5353fd70>, 'Boolean': <function print_boolean at 0x7f5f5353fed8>, 'Date': <function print_date at 0x7f5f5353fc08>})[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

user_data(*args, **kwargs)[source]

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

Previous topic


Next topic