cubicweb.pyramid.core

Binding of CubicWeb connection to Pyramid request.

cubicweb.pyramid.core.includeme(config)[source]

Enables the core features of Pyramid CubicWeb.

Automatically called by the ‘pyramid’ command, or via config.include('cubicweb.pyramid.code'). In the later case, the following registry entries must be defined first:

‘cubicweb.config’
A cubicweb ‘config’ instance.
‘cubicweb.repository’
The correponding cubicweb repository.
‘cubicweb.registry’
The vreg.
cubicweb.pyramid.core.cw_to_pyramid(*args, **kwds)[source]

Context manager to wrap a call to the cubicweb API.

All CW exceptions will be transformed into their pyramid equivalent. When needed, some CW reponse bits may be converted too (mainly headers)

cubicweb.pyramid.core.render_view(request, vid, **kwargs)[source]

Helper function to render a CubicWeb view.

Parameters:
  • request – A pyramid request
  • vid – A CubicWeb view id
  • kwargs – Keyword arguments to select and instanciate the view
Returns:

The rendered view content

cubicweb.pyramid.core.repo_connect(request, repo, eid)[source]

A lightweight version of cubicweb.server.repository.Repository.connect() that does not keep track of opened sessions, removing the need of closing them

cubicweb.pyramid.core.get_principals(login, request)[source]

Returns the group names of the authenticated user.

This function is meant to be used as an authentication policy callback.

It also pre-open the cubicweb session and put it in request._cw_cached_session for later usage by _cw_session().

Note

If the default authentication policy is not used, make sure this function gets called by the active authentication policy.

Parameters:
  • login – A cubicweb user eid
  • request – A pyramid request
Returns:

A list of group names

class cubicweb.pyramid.core.CubicWebPyramidRequest(request)[source]

Bases: cubicweb.web.request.ConnectionCubicWebRequestBase

A CubicWeb request that only wraps a pyramid request.

Parameters:request – A pyramid request
http_method()[source]

returns ‘POST’, ‘GET’, ‘HEAD’, etc.

message

Returns a ‘<br>’ joined list of the cubicweb current message and the default pyramid flash queue messages.

relative_path(includeparams=True)[source]

return the normalized path of the request (ie at least relative to the instance’s root, but some other normalization may be needed so that the returned path may be used to compare to generated urls

Parameters:includeparams – boolean indicating if GET form parameters should be kept in the path
setup_params(params)[source]

WARNING: we’re intentionally leaving INTERNAL_FIELD_VALUE here

subclasses should overrides to

cubicweb.pyramid.core._cw_session(request)[source]

Obtains a cw session from a pyramid request

Parameters:request – A pyramid request
Returns type:cubicweb.server.session.Session

Not meant for direct use, use request.cw_session instead.

cubicweb.pyramid.core._cw_cnx(request)[source]

Obtains a cw session from a pyramid request

The connection will be commited or rolled-back in a request finish callback (this is temporary, we should make use of the transaction manager in a later version).

Not meant for direct use, use request.cw_cnx instead.

Parameters:request – A pyramid request
Returns type:cubicweb.server.session.Connection
cubicweb.pyramid.core._cw_request(request)[source]

Obtains a CubicWeb request wrapper for the pyramid request.

Parameters:request – A pyramid request
Returns:A CubicWeb request
Returns type:CubicWebPyramidRequest

Not meant for direct use, use request.cw_request instead.