Views¶
- class keg_elements.views.FormMixin¶
Mixin supporting simple form view setup
- flash_failure = ('Form errors detected, see below for details.', 'error')¶
flash message to show on post when form data has failed validation
- flash_success = ('Form submitted successfully.', 'success')¶
flash message to show on post when form data has passed validation
- form_cls = None¶
form class to construct, or callable returning a form instance.
- form_create()¶
Create the form instance with default object (if any).
- form_default()¶
Returns default object to load in form during init.
- form_init()¶
Assign a form instance to the template.
- form_on_invalid()¶
Action method for form that has failed validation.
- form_on_valid()¶
Action method for form that has passed validation.
This is usually where things like database transactions will go.
- get()¶
GET method responder. By default, inits form to template.
- post()¶
POST method responder.
Initializes the form and attempts to validate POSTed data. Flashes messages if those attributes are set, then directs to on_form_[in]valid as needed for additional workflow.
- title = None¶
Page title, will be assigned as title for the template.
- class keg_elements.views.FormView(responding_method=None)¶
Base view for simple form pages.
- methods: t.ClassVar[t.Optional[t.Collection[str]]] = {'GET', 'POST'}¶
The methods this view is registered for. Uses the same default (
["GET", "HEAD", "OPTIONS"]
) asroute
andadd_url_rule
by default.
- class keg_elements.views.GridMixin¶
Mixin supporting simple grid view setup
- allow_post(grid)¶
Inspects the grid manager’s arg loads to determine if post should be allowed.
- get()¶
GET method responder. By default, fully processes and renders grid to template.
- get_grid_template_args(arg_dict)¶
Return any template arguments needed for render.
By default, grid and title arguments are passed in.
- grid_cls = None¶
Grid class to construct, or callable returning a grid instance.
- init_grid()¶
Create an instance of grid_cls
- on_render_limit_exceeded(grid)¶
Handles export limit exceeded case. By default, shows a flash message.
- post()¶
POST method responder.
For session-enabled grids (the default), process the args, which will save any form args into the grid’s session store. Then, redirect to a GET request on the same URL.
If the grid is not session-enabled, render to the template.
Note: for request form args to be processed, the grid’s manager must be set up with an args loader that uses them.
- post_args_grid_setup(grid)¶
Apply changes to grid instance after QS args/session are loaded
- process_grid()¶
Create grid instance and run args collection/processing for grid state.
- render_grid()¶
Build grid, handle loading args and conditional export, and render result.
- template = 'keg-elements/grid-view.html'¶
Template to render. Defaults to keg-elements/grid-view.html
- title = None¶
Page title, will be assigned as title for the template.