websauna.system.crud.sqlalchemy module

SQLAlchemy form support.

class websauna.system.crud.sqlalchemy.CRUD(request, model=None)[source]

Bases: websauna.system.crud.CRUD

SQLAlchemy CRUD controller.

A traversing endpoint which maps listing, add, edit and delete views for an SQLAlchemy model.

delete_object(obj)[source]

Delete one item in the CRUD.

Called by delete view if no alternative logic is implemented. :param obj: Raw object, e.g. SQLAlchemy instance.

fetch_object(id)[source]

Pull a raw object from the database.

Use the get_query() to get the query base and then return the object with matching id.

First check for legal ids and raise KeyError to signal that the traversed id might be actually a view name.

get_dbsession()[source]

Override to use a different database session.

Default to request.dbsession.

Return type

Session

Returns

A database session.

get_model()[source]

Get the SQLAlchemy model instance we are managing.

Returns

SQLAlchemy model instance.

get_query()[source]

Get SQLAlchemy Query object which we use to populate this listing.

Views can specify their own queries - e.g. filter by user. This is just the default for everything.

Return type

Query

Returns

SQLAlchemy query.

class websauna.system.crud.sqlalchemy.Resource(request, obj)[source]

Bases: websauna.system.crud.Resource

Maps one SQLAlchemy model instance to a traversable URL path.

Describe how to display SQLAlchemy objects in breadcrumbs.

get_title()[source]

Title on show / edit / delete pages.

websauna.system.crud.sqlalchemy.sqlalchemy_deleter(view, context, request)[source]

A view callback to delete item in SQLAlchemy CRUD.

Parameters
  • view (object) – View object.

  • context (Resource) – Traversal context

  • request (Request) – Current HTTP Request.