flask_velox.mixins.sqla.delete

Mixin classes for deleting SQLAlchemy objects from the Database.

Note

The following packages must be installed:

  • Flask-SQLAlchemy
class flask_velox.mixins.sqla.delete.DeleteObjectMixin(*args, **kwargs)

Bases: flask_velox.mixins.sqla.object.SingleObjectMixin, flask_velox.mixins.context.ContextMixin, flask_velox.mixins.template.TemplateMixin

Deletes a single SQLAlchemy object from the Database.

Example

1
2
3
4
5
6
7
8
form flask.ext.velox.mixins.sqla.delete import DeleteObjectMixin
from yourapp import db
from yourapp.models import MyModel

class DeleteMyModel(DeleteObjectMixin):
    template = 'delete.html'
    model = MyModel
    session = db.sesion
confirm bool, optional

Ensure a confirmed flag is required when processing the view, defaults to True

can_delete

Propery function which returns a bool. If confirm attribute is set to False on the class this will return True else it will only return True if the confirmed query string is present.

Returns:Ok to delete the object or not
Return type:bool
delete()

Deletes the object, only if can_delete() returns True.

flash()

Flashes a success message to the user.

set_context()

Adds extra context variables to be used in delete view templates.

See also

  • from flask_velox.mixins.context.ContextMixin.set_context()

Note

Adds the following context variables:

  • object: The object to be deleted
  • cancel_url: Function for retrieving cancel url in template
success_callback()

Success callback called after object has been deleted. Override this to customise what happens after an object is delted

Raises:werkzeug.routing.RequestRedirect – When object is deleted to force a redirect to another View
class flask_velox.mixins.sqla.delete.MultiDeleteObjectMixin(*args, **kwargs)

Bases: flask_velox.mixins.sqla.delete.DeleteObjectMixin

Mixin provides functionality to delete mutliple objects of the same model.

delete()

Override default delete functionality adding the ability to delete multiple objects of the same model but only if can_delete() is True.

flash()

Flashes a success message to the user.

get_objects()

Returns a set of objects set for deletion. List of objects is retrived from a HTTP POST list called objects.

Returns:Set of objects to delete
Return type:set
methods = ['GET', 'POST']

Allowed HTTP Methods

post(*args, **kwargs)

Handle HTTP POST requests rendering a template.

set_context()

Override context to add objects rather than object to the context.

http://thisissoon.com

Related Topics

This Page