Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
flask-admin
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Python-Dev
flask-admin
Commits
737eeaba
Commit
737eeaba
authored
Aug 19, 2012
by
Serge S. Koval
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated docs
parent
602828c2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
3 deletions
+37
-3
actions.py
flask_admin/actions.py
+37
-3
No files found.
flask_admin/actions.py
View file @
737eeaba
...
@@ -3,17 +3,16 @@ from flask import request, url_for, redirect
...
@@ -3,17 +3,16 @@ from flask import request, url_for, redirect
def
action
(
name
,
text
,
confirmation
=
None
):
def
action
(
name
,
text
,
confirmation
=
None
):
"""
"""
Use this decorator to expose mass-model actions
Use this decorator to expose actions that span more than one
entity (model, file, etc)
`name`
`name`
Action name
Action name
`text`
`text`
Action text.
Action text.
Will be passed through gettext() before rendering.
`confirmation`
`confirmation`
Confirmation text. If not provided, action will be executed
Confirmation text. If not provided, action will be executed
unconditionally.
unconditionally.
Will be passed through gettext() before rendering.
"""
"""
def
wrap
(
f
):
def
wrap
(
f
):
f
.
_action
=
(
name
,
text
,
confirmation
)
f
.
_action
=
(
name
,
text
,
confirmation
)
...
@@ -23,11 +22,30 @@ def action(name, text, confirmation=None):
...
@@ -23,11 +22,30 @@ def action(name, text, confirmation=None):
class
ActionsMixin
(
object
):
class
ActionsMixin
(
object
):
"""
Actions mixin.
In some cases, you might work with more than one "entity" (model, file, etc) in
your admin view and will want to perform actions on group of entities at once.
In this case, you can add this functionality by doing this:
1. Add mixin to your administrative view class
2. Call `init_actions` in your class constructor
3. Expose actions view
4. Import `actions.html` library and add call library macros in your template
"""
def
__init__
(
self
):
def
__init__
(
self
):
"""
Default constructor.
"""
self
.
_actions
=
[]
self
.
_actions
=
[]
self
.
_actions_data
=
{}
self
.
_actions_data
=
{}
def
init_actions
(
self
):
def
init_actions
(
self
):
"""
Initialize list of actions for the current administrative view.
"""
self
.
_actions
=
[]
self
.
_actions
=
[]
self
.
_actions_data
=
{}
self
.
_actions_data
=
{}
...
@@ -43,9 +61,18 @@ class ActionsMixin(object):
...
@@ -43,9 +61,18 @@ class ActionsMixin(object):
self
.
_actions_data
[
name
]
=
(
attr
,
text
,
desc
)
self
.
_actions_data
[
name
]
=
(
attr
,
text
,
desc
)
def
is_action_allowed
(
self
,
name
):
def
is_action_allowed
(
self
,
name
):
"""
Verify if action with `name` is allowed.
`name`
Action name
"""
return
True
return
True
def
get_actions_list
(
self
):
def
get_actions_list
(
self
):
"""
Return list and a dictionary of allowed actions.
"""
actions
=
[]
actions
=
[]
actions_confirmation
=
{}
actions_confirmation
=
{}
...
@@ -61,6 +88,13 @@ class ActionsMixin(object):
...
@@ -61,6 +88,13 @@ class ActionsMixin(object):
return
actions
,
actions_confirmation
return
actions
,
actions_confirmation
def
handle_action
(
self
,
return_view
=
None
):
def
handle_action
(
self
,
return_view
=
None
):
"""
Handle action request.
`return_view`
Name of the view to return to after the request.
If not provided, will return user to the index view.
"""
action
=
request
.
form
.
get
(
'action'
)
action
=
request
.
form
.
get
(
'action'
)
ids
=
request
.
form
.
getlist
(
'rowid'
)
ids
=
request
.
form
.
getlist
(
'rowid'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment