cubicweb.req
¶
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 -
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
-
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)
-
entity_from_eid
(eid, etype=None)[source]¶ return an entity instance for the given eid. No query is done
-
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
-
format_float
(num)[source]¶ return a string for floating point number 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)
-
property_value
(key)[source]¶ 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.
-
set_language
(lang)[source]¶ install i18n configuration for lang translation.
Raises
KeyError
if translation doesn’t exist.
-
url_parse_qsl
(querystring)[source]¶ 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.
-
url_unquote
(quoted)[source]¶ returns a unicode unquoted string
decoding is based on self.encoding which is the encoding used in url_quote
-
user_data
(**kwargs)¶ returns a dictionary with this user’s information.
The keys are :
- login
- The user login
- name
- The user name, returned by user.name()
- 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..
-