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_object
(obj)[source]¶ Add objects to transaction lifecycle and flush newly created object to persist storage to give them id.
-
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 withinitialize_object()
and finally include the created object in the transaction lifecycle withadd_object()
.- Return type
-
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
- Return type
List
[Button
]
-
-
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 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
- Returns
OrderedDict instance where key is button id and value is the link to where the button points.
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 andwebsauna.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
-
-
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 overrideyes()
.-
base_template
= 'crud/base.html'¶
-
delete_object
()[source]¶ User picked YEAH LET’S DO IT.
First try to call
delete
callback if one is set. If not then fallback towebsauna.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.
-
-
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()
-
do_cancel
()[source]¶ Called when user presses the cancel button.
- Return type
Response
- Returns
HTTPResponse
- Return type
Iterable
[Button
]
-
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 seewebsauna.system.user.adminviews.UserAdd
.
-
form_generator
= None¶ This is an instance of
websauna.system.crud.formgenerator.FormGenerator
. For SQLAlchemy models it iswebsauna.system.crud.formgenerator.SQLAlchemyFormGenerator
. Form generator describers how a CRUD model is turned to a Deform form. It is called bycreate_form()
. For example use cases see e.g.websauna.system.user.adminviews.UserAdd
.
-
abstract
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
-
-
class
websauna.system.crud.views.
Listing
(context, request)[source]¶ Bases:
websauna.system.crud.views.CRUDView
List items in CRUD.
-
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
-
paginator
= <websauna.system.crud.paginator.DefaultPaginator object>¶ How the result of this list should be split to pages
-
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
-
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_form
()[source]¶ Create the form object for a view.
Subclasses most override this, call
create_form()
and pass correct edit mode and buttons.
-
-
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.