Views

class keg_auth.views.AuthRespondedView

Base for views which will refer out to the login authenticator for responders

URL gets calculated from the responder class and must be a class attribute there.

Note: if the login authenticator doesn’t have the referenced key, the view will 404.

classmethod calc_url(**kwargs)

Leans on login authenticator’s responders to provide a URL.

on_missing_responder()

Handler for requests that do not match a responder in authenticator.

By default, aborts with 404 response.

responder(*args, **kwargs)

Refer all requests to the responder and return the response.

If no responder, call on_missing_responder.

class keg_auth.views.Bundle(*args, **kwargs)

Default Bundle CRUD view. Uses auth-manage permission for all targets.

create_form(obj)

Create an instance of form_cls. Must return a form if overloaded.

obj is an instance of orm_cls (edit) or None (add).

static form_cls(endpoint)

Returns a form for Bundle CRUD.

update_obj(obj, form)

Update an existing object instance from form data. Does not explicitly flush or commit.

class keg_auth.views.CrudView(*args, **kwargs)

Base CRUD view class providing add/edit/delete/list functionality.

Basic subclass setup involves: - set the grid_cls, form_cls, and orm_cls attributes - set object_name to be the human readable label. - assign object_name_plural only if necessary - assign base permissions for reach of the four endpoints

Grid is assumed to be WebGrid. Form is assumed to be WTForms. ORM is assumed to be SQLAlchemy. Default templates are provided with keg-auth.

Permissions are set for each endpoint under the permissions dict attribute. Note that it is usually helpful to put a general @requires_permissions on the class itself, as that will aid in conditionally displaying navigation links based on a user’s access level.

add()

View method for add. Enforce permissions and call add_edit.

add_edit(meth, obj=None)

Handle form-related requests for add/edit.

Form instance comes from create_form. Valid form updates the object via update_obj. If post successful, returns result of on_add_edit_success. If post failure, runs on_add_edit_failure and renders the form via render_form. If get, renders the form via render_form.

add_orm_obj()

Generate a blank object instance and add it to the session.

add_url_with_session(session_key)

Return add url with the session_key from the request, to support webgrid sessions.

cancel_url()

Return list url with the session_key from the request, to support webgrid sessions.

create_form(obj)

Create an instance of form_cls. Must return a form if overloaded.

obj is an instance of orm_cls (edit) or None (add).

delete(objid)

View method for delete. Enforce permissions, load the record, run ORM delete.

If delete succeeds, return result of on_delete_success. If delete fails, return result of on_delete_failure.

edit(objid)

View method for edit. Enforce permissions, load the record, and call add_edit.

classmethod endpoint_for_action(action)

Compute the flask endpoint for the given CRUD action.

flash_success(verb)

Add a flask flash message for success with the given verb.

form_page_heading(action)

Allows customization of add/edit heading. Defaults to page_title.

form_template_args(arg_dict)

Allows customization of jinja template args for add/edit views.

arg_dict contains the default arguments, including anything set with self.assign.

Must return a dict of template args.

grid_page_heading

Allows customization of grid heading. Defaults to page_title.

grid_template_args(arg_dict)

Allows customization of jinja template args for list view.

arg_dict contains the default arguments, including anything set with self.assign.

Must return a dict of template args.

init_object(obj_id, action=None)

Load record from ORM for edit/delete cases.

Forces 404 response if the record does not exist.

Additional object-loading customization can be provided on action-specific hooks init_object_edit and init_object_delete. These methods will take no parameters, but they may assume self.objinst refers to the requested entity.

classmethod init_routes()

Creates the standard set of routes from methods (add, edit, delete, list).

To extend to further action routes:
cls.map_method_route(method_name, url, HTTP methods) ex. cls.map_method_route(‘read’, ‘/foo’, (‘GET’, ))
list()

View method for list. Enforce permissions, then render grid via render_grid.

list_url_with_session

Return list url with the session_key from the request, to support webgrid sessions.

make_grid()

Create an instance of grid_cls and initialize from request.

Returns a grid instance.

object_name_plural

Plural version of object_name. Uses the inflect library for a default value.

on_add_edit_failure(entity, is_edit)

Flash an add/edit message. No redirect in this case.

on_add_edit_success(entity, is_edit)

Flash an add/edit success message, and redirect to list view.

on_delete_failure()

Flash a delete failure message, and redirect to list view.

on_delete_success()

Flash a delete success message, and redirect to list view.

on_render_limit_exceeded(grid)

Flash a message for webgrid limit exceeded case.

This gets run in export cases where more records are in the set than the file format can support.

page_title(action)

Generates a heading title based on the page action.

action should be a string. Values “Create” and “Edit” are handled, with a fall-through to return object_name_plural (for the list case).

post_args_grid_setup(grid)

Apply changes to grid instance after QS args/session are loaded.

render_form(obj, action, form, action_button_text='Save Changes')

Renders the form template.

Template arguments may be customized with the form_template_args method.

render_grid()

Renders the grid template.

Grid instance comes from make_grid. Grid instance may be customized via post_args_grid_setup. If grid is set to export, give that response or handle the limit exceeded error. Otherwise, render grid_template with grid_template_args.

update_obj(obj, form)

Update an existing object instance from form data. Does not explicitly flush or commit.

class keg_auth.views.ForgotPassword

Forgot Password view that uses the login authenticator’s responders.

class keg_auth.views.Group(*args, **kwargs)

Default Group CRUD view. Uses auth-manage permission for all targets.

create_form(obj)

Create an instance of form_cls. Must return a form if overloaded.

obj is an instance of orm_cls (edit) or None (add).

static form_cls(endpoint)

Returns a form for Group CRUD.

update_obj(obj, form)

Update an existing object instance from form data. Does not explicitly flush or commit.

class keg_auth.views.Login

Login view that uses the login authenticator’s responders.

class keg_auth.views.Logout

Logout view that uses the login authenticator’s responders.

class keg_auth.views.OAuthAuthorize

Authorization view that uses the OAuth authenticator’s responders.

Completes the OAuth login flow.

class keg_auth.views.OAuthLogin

Login view that uses the OAuth authenticator’s responders.

class keg_auth.views.Permission(responding_method=None)

Default Permission view. Uses auth-manage permission.

class keg_auth.views.ResetPassword

Reset Password view that uses the login authenticator’s responders.

class keg_auth.views.User(*args, **kwargs)

Default User CRUD view. Uses auth-manage permission for all targets.

create_form(obj)

Create an instance of form_cls. Must return a form if overloaded.

obj is an instance of orm_cls (edit) or None (add).

delete(objid)

View method for delete. Enforce permissions, load the record, run ORM delete.

If delete succeeds, return result of on_delete_success. If delete fails, return result of on_delete_failure.

static form_cls(config=None, allow_superuser=False, endpoint='', fields=['is_enabled', 'disabled_utc'])

Returns a form for User CRUD.

Form is customized depending on the fields and superuser setting passed in.

update_obj(obj, form)

Update an existing object instance from form data. Does not explicitly flush or commit.

class keg_auth.views.VerifyAccount

Verification view that uses the login authenticator’s responders.

keg_auth.views.make_blueprint(import_name, _auth_manager, bp_name='auth', login_cls=<class 'keg_auth.views.Login'>, forgot_cls=<class 'keg_auth.views.ForgotPassword'>, reset_cls=<class 'keg_auth.views.ResetPassword'>, logout_cls=<class 'keg_auth.views.Logout'>, verify_cls=<class 'keg_auth.views.VerifyAccount'>, user_crud_cls=<class 'keg_auth.views.User'>, group_crud_cls=<class 'keg_auth.views.Group'>, bundle_crud_cls=<class 'keg_auth.views.Bundle'>, permission_cls=<class 'keg_auth.views.Permission'>, oauth_login_cls=<class 'keg_auth.views.OAuthLogin'>, oauth_auth_cls=<class 'keg_auth.views.OAuthAuthorize'>, blueprint_class=<class 'flask.blueprints.Blueprint'>, **kwargs)

Blueprint factory for keg-auth views

Most params are assumed to be view classes. _auth_manager is the extension instance meant for the app on which this blueprint will be used: it is necessary in order to apply url routes for user functions.

blueprint_class is the class to be instantiated as the Flask blueprint for auth views. The default is flask.blueprint, but a custom blueprint may be provided.