flask_velox.mixins.sqla.forms

Mixin classes for helping build forms with WTForms populating SQLAlchemy objects.

Note

The following packages must be installed:

  • Flask-WTF
  • Flask-SQLAlchemy
class flask_velox.mixins.sqla.forms.BaseCreateUpdateMixin

Bases: object

Base Mixin for Creating or Updating a object with SQLAlchemy.

Warning

This mixin cannot be used on it’s own and should be used inconjunction with others, such as ModelFormMixin.

success_callback()

Overrides success_callback creating new model objects. This method is called on successful form validations. It first obtains the current db session and the instantiated form. A blank object is obtained from the model and then populated with the form data.

        session = self.get_session()
        form = self.get_form()
        obj = self.get_object()

        form.populate_obj(obj)

        session.add(obj)
        session.commit()
Returns:Redirects request to somewhere else
Return type:werkzeug.wrappers.Response
class flask_velox.mixins.sqla.forms.CreateModelFormMixin(*args, **kwargs)

Bases: flask_velox.mixins.sqla.object.SingleObjectMixin, flask_velox.mixins.sqla.forms.BaseCreateUpdateMixin, flask_velox.mixins.forms.FormMixin

Handles creating objects after form validation has completed and was successful.

flash()

Flash created message to user.

class flask_velox.mixins.sqla.forms.UpdateModelFormMixin(*args, **kwargs)

Bases: flask_velox.mixins.sqla.object.SingleObjectMixin, flask_velox.mixins.sqla.forms.BaseCreateUpdateMixin, flask_velox.mixins.forms.FormMixin

Handels updating a single existing object after form validation has completed and was successful.

flash()

Flash updated message to user.

instantiate_form(**kwargs)

Overrides form instantiation so object instance can be passed to the form.

        obj = self.get_object()

        return super(UpdateModelFormMixin, self).instantiate_form(
            obj=obj,
            **kwargs)
Returns:Instantiated form
Return type:object
class flask_velox.mixins.sqla.forms.UpdateModelMultiFormMixin(*args, **kwargs)

Bases: flask_velox.mixins.sqla.object.SingleObjectMixin, flask_velox.mixins.sqla.forms.BaseCreateUpdateMixin, flask_velox.mixins.forms.MultiFormMixin

Mixin for building mutli forms with a single SQAlachemy object

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
from flask.ext.velox.mixins.sqla.forms import ModelFormMixin
from yourapp.forms import MyForm1, MyForm2
from yourapp.models import MyModel

class MyView(UpdateModelMultiFormMixin):
    model = MyModel
    forms = [
        'Form 1': MyForm1
        'Form 2': MyForm2
    ]

http://thisissoon.com

Related Topics

This Page