websauna.system.crud.views module

Default CRUD views.

class websauna.system.crud.views.Add(context, request)[source]

Bases: websauna.system.crud.views.FormView

Create a new item in CRUD.

add()[source]

View for showing an individual object.

add_object(obj)[source]

Add objects to transaction lifecycle and flush newly created object to persist storage to give them id.

bind_schema(schema)[source]
build_object(form, appstruct)[source]

Builds a new object.

The default behavior is to call create_object() to construct a new object, then populate it with initialize_object() and finally include the created object in the transaction lifecycle with add_object().

Return type:object
create_object()[source]

Factory method to create a new empty object to be populated from the form.

do_cancel()[source]

Called when user presses the cancel button.

Return type:Response
Returns:HTTPResponse
do_success(resource)[source]

Finish action after saving new object.

Usually returns HTTP redirect to the next view.

Return type:Response
get_buttons()[source]
Return type:List[Button]
get_crud()[source]

Get CRUD manager object for this view.

Return type:CRUD
get_form()[source]

Create the form object for a view.

Subclasses most override this, call create_form() and pass correct edit mode and buttons.

Return type:object
get_model()[source]

Get SQLAlchemy model we are managing.

Return type:type
get_title()[source]

Get human-readable title for for template page title.

initialize_object(form, appstruct, obj)[source]

Record values from the form on a freshly created object.

class websauna.system.crud.views.CRUDView[source]

Bases: object

Base class for different CRUD views.

This includes views having context as the listing and having context as the individual item.

base_template = 'crud/base.html'

base_template may point into a template providing crud_content block where the contents of the view is rendered. This allows you to decorate your CRUD which a specific page frame.

get_resource_buttons()[source]

Get the context-sensitive button options presented on this page.

These are usually links to “Show”, “Edit”, “Delete” of the formm context, but you are free to add your own buttons here. The buttons are usually placed on the top right corner of the form.

Unless you want to dynamically generate buttons depending on the page, it is enough to set resource_buttons attribute on the view class.

Return type:List[~T]
Returns:OrderedDict instance where key is button id and value is the link to where the button points.
resource_buttons = []

Instance of ResourceButtons which appear on the top right corner of this view

class websauna.system.crud.views.CSVListing(context, request)[source]

Bases: websauna.system.crud.views.Listing

A listing view that exports the listing table as CSV.

CSVListing users the same Table structure to define the listing as the listing HTML page. For columns, we use only id and websauna.system.crud.listing.Column.get_value() to stringify entries from SQLAlchemy model attributes to CSV writer stream.

For example usage see websauna.system.user.adminviews.UserCSVListing.

Note

This is TODO, having pyramid_tm issue open https://github.com/Pylons/pyramid_tm/issues/56

Original implementation in https://github.com/nandoflorestan/bag/blob/master/bag/spreadsheet/csv.py by Nando Florestan.

buffered_rows = 100

How many rows we buffer in a chunk before writing into a response

listing()[source]

Listing core.

class websauna.system.crud.views.Delete(context, request)[source]

Bases: object

Delete one item within a CRUD with a confirmation screen.

This is an abstract item delete implementation; you must either set deleter callback or override yes().

base_template = 'crud/base.html'
cancel_delete()[source]

Permanent data destruction is bad.

Redirect user back to the show view.

delete()[source]

Delete view endpoint.

delete_object()[source]

User picked YEAH LET’S DO IT.

First try to call delete callback if one is set. If not then fallback to websauna.system.crud.CRUD.delete_object().

http://opensourcehacker.com/wp-content/uploads/2013/04/koala.gif

deleter = None

callback deleter(request, context) which is called to perform the actual model specific delete operation.

get_crud()[source]
Return type:CRUD
get_model()[source]
Return type:object
get_object()[source]

Get underlying SQLAlchemy model instance from current Pyramid traversing context.

class websauna.system.crud.views.Edit(context, request)[source]

Bases: websauna.system.crud.views.FormView

Edit model instance using Deform form..

The call order of functions

  • edit()
  • save_changes()
  • do_success()
bind_schema(schema)[source]
do_cancel()[source]

Called when user presses the cancel button.

Return type:Response
Returns:HTTPResponse
do_success()[source]

Called after the save (objectify) has succeeded.

Return type:Response
edit()[source]

View for showing an individual object.

get_appstruct(form, obj)[source]

Turn the object to form editable format.

Return type:dict
get_buttons()[source]
Return type:Iterable[Button]
get_form()[source]

Get a form used to edit this item.

Return type:Form
get_title()[source]

Get human-readable title for for template page title.

resource_buttons = [<websauna.system.crud.views.TraverseLinkButton object>]
save_changes(form, appstruct, obj)[source]

Store the data from the form on the object.

class websauna.system.crud.views.FormView(context, request)[source]

Bases: websauna.system.crud.views.CRUDView

An abstract base class for form-based CRUD views.

Use Deform form library. This views is abstract and it does not have dependency to any underlying model system like SQLAlchemy.

base_template = 'crud/base.html'

If the child class is not overriding the rendering loop, point this to a template which provides the page frame and crud_content block. For example use see websauna.system.user.adminviews.UserAdd.

create_form(mode, buttons=(), nested=None)[source]
Return type:Form
customize_schema(schema)[source]

After Colander schema is automatically generated from the SQLAlchemy model, edit it in-place for fine-tuning.

Override this in your view subclass for schema customizations.

form_generator = None

This is an instance of websauna.system.crud.formgenerator.FormGenerator. For SQLAlchemy models it is websauna.system.crud.formgenerator.SQLAlchemyFormGenerator. Form generator describers how a CRUD model is turned to a Deform form. It is called by create_form(). For example use cases see e.g. websauna.system.user.adminviews.UserAdd.

get_crud()[source]

Get CRUD manager object for this view.

Return type:CRUD
get_form()[source]

Create the form object for a view.

Subclasses most override this, call create_form() and pass correct edit mode and buttons.

Return type:Form
get_model()[source]

Get SQLAlchemy model we are managing.

Return type:type
get_object()[source]

Get underlying SQLAlchemy model instance from current Pyramid traversing context.

get_title()[source]

Get human-readable title for for template page title.

pull_in_widget_resources(form)[source]

Include widget JS and CSS on the page.

Call this as the last thing before returning template context variables from your view.

class websauna.system.crud.views.Listing(context, request)[source]

Bases: websauna.system.crud.views.CRUDView

List items in CRUD.

get_count(query)[source]

Calculate total item count based on query.

get_crud()[source]
Return type:CRUD
get_model()[source]
Return type:Any
get_query()[source]

Get SQLAlchemy query used in this CRUD listing.

This can include filtering e.g. request user, crud parameters, so on.

Return type:Query
get_title()[source]

Get the user-readable name of the listing view (breadcrumbs, etc.)

Return type:str
listing()[source]

View for listing model contents in CRUD.

order_query(query)[source]

Sort the query.

paginate(template_context)[source]

Create template variables for paginatoin results.

paginator = <websauna.system.crud.paginator.DefaultPaginator object>

How the result of this list should be split to pages

resource_buttons = [<websauna.system.crud.views.TraverseLinkButton object>]
table = None

Describe what columns our listing should contain

class websauna.system.crud.views.ResourceButton(id=None, name=None, template=None, permission=None, tooltip=None, feature=None)[source]

Bases: object

Present a button on the top right corner of CRUD views.

These buttons, with breadcrumbs, form the basic navigation inside the CRUD management interface.

Buttons are permission-aware, so they are rendered only when the user has required permission.

The default button templates include

Generate a link where this button is pointing at.

Parameters:
  • context (Resource) – Traversal context
  • request (Request) – Current HTTP Request.
Return type:

str

Returns:

Link.

is_visible(context, request)[source]

Determine if we should render this button.

Parameters:
  • context (Resource) – Traversal context
  • request (Request) – Current HTTP Request.
Return type:

bool

Returns:

Boolean indicating if button is visible or not.

render(context, request)[source]

Return HTML code for this button.

Parameters:
  • context (Resource) – Traversal context
  • request (Request) – Current HTTP Request.
Return type:

str

Returns:

Rendered template.

template = 'crud/resource_button.html'

The template used to render this button. Also overridable through the constructor.

class websauna.system.crud.views.Show(context, request)[source]

Bases: websauna.system.crud.views.FormView

Show one instance of a model.

get_appstruct(form, form_context)[source]

Get the dictionary that populates the form.

Return type:dict
get_form()[source]

Create the form object for a view.

Subclasses most override this, call create_form() and pass correct edit mode and buttons.

get_form_context()[source]

Get the item that populates the form.

Return type:object
get_title()[source]

Get human-readable title for for template page title.

resource_buttons = [<websauna.system.crud.views.TraverseLinkButton object>]
show()[source]

View for showing an individual object.

class websauna.system.crud.views.TraverseLinkButton(view_name, **kwargs)[source]

Bases: websauna.system.crud.views.ResourceButton

A button which is a link to another page on this resource.

Generate a link where this button is pointing at.

Parameters:
  • context (Resource) – Traversal context
  • request (Request) – Current HTTP Request.
Return type:

str

Returns:

Link.