Skip to content

Commit

Permalink
docs for actions
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgaspar committed Sep 27, 2014
1 parent 2c76443 commit def3f2e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 17 deletions.
1 change: 1 addition & 0 deletions README.rst
Expand Up @@ -58,6 +58,7 @@ Includes:
- Views and Widgets
- Automatic menu generation.
- Automatic CRUD generation.
- Multiple actions on db records.
- Big variety of filters for your lists.
- Various view widgets: lists, master-detail, list of thumbnails etc
- Select2, Datepicker, DateTimePicker
Expand Down
41 changes: 36 additions & 5 deletions docs/actions.rst
Expand Up @@ -4,7 +4,11 @@ Actions
Define your view
----------------

You can setup your actions for records on the show page. Just use the @action decorator on your own functions
You can setup your actions on records on the show or list views.
This is a powerful feature, you can easily add custom functionality to your db records,
like mass delete, sending emails with record information, special mass update etc.

Just use the @action decorator on your own functions. Here's an example

::

Expand All @@ -14,13 +18,40 @@ You can setup your actions for records on the show page. Just use the @action de
datamodel = SQLAModel(Group)
related_views = [ContactModelView]
@action("myaction","Do something on this record","","fa-rocket")
@action("myaction","Do something on this record","Do you really want to?","fa-rocket")
def myaction(self, item):
"""
do something with the item record
"""
return redirect(url_for('.'))
return redirect(self.get_redirect())
This will create the necessary permissions for the item, so that you can include them or remove them from a particular role.
This will create the necessary permissions for the item,
so that you can include or remove them from a particular role.

You can easily implement a massive delete option on list's. Just add the following code
to your view. This example will tell F.A.B. to implement the action just for list views and not
show the option on the show view. You can do this by disabling the *single* or *multiple*
parameters on the **@action** decorator.

::

@action("muldelete", "Delete", "Delete all Really?", "fa-rocket", single=False)
def muldelete(self, items):
self.datamodel.delete_all(items)
self.update_redirect()
return redirect(self.get_redirect())


F.A.B will call your function with a list of record items if called from a list view.
Or a single item if called from a show view. By default an action will be implemented on
list views and show views so your method's should be prepared to handle a list of records or
a single record::

It will render a button for each action you define on the show page of *ModelView*
@action("muldelete", "Delete", "Delete all Really?", "fa-rocket")
def muldelete(self, items):
if isinstance(items, list):
self.datamodel.delete_all(items)
self.update_redirect()
else:
self.datamodel.delete(items)
return redirect(self.get_redirect())
1 change: 1 addition & 0 deletions docs/intro.rst
Expand Up @@ -36,6 +36,7 @@ Includes:
- Views and Widgets
- Automatic menu generation.
- Automatic CRUD generation.
- Multiple actions on db records.
- Big variety of filters for your lists.
- Various view widgets: lists, master-detail, list of thumbnails etc
- Select2, Datepicker, DateTimePicker
Expand Down
5 changes: 2 additions & 3 deletions docs/versions.rst
Expand Up @@ -4,9 +4,8 @@ Versions
Improvements and Bug fixes on 0.10.6
------------------------------------

- (TODO) New, Support for multiple actions, included mass delete.
- (TODO) New, PluginModule implementation.
- (TODO) New, extra_args property, for injecting extra arguments to templates.
- New, Support for multiple actions.
- New, extra_args property, for injecting extra arguments to templates.

Improvements and Bug fixes on 0.10.5
------------------------------------
Expand Down
9 changes: 0 additions & 9 deletions flask_appbuilder/views.py
Expand Up @@ -233,15 +233,6 @@ def delete(self, pk):
return redirect(self.get_redirect())


@action("muldelete", "Delete", "Delete all Really?", "fa-rocket", single=False)
def muldelete(self, items):
if isinstance(items, list):
self.datamodel.delete_all(items)
self.update_redirect()
else:
self.datamodel.delete(items)
return redirect(self.get_redirect())

@has_access
@permission_name('list')
@expose('/json')
Expand Down

0 comments on commit def3f2e

Please sign in to comment.