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
84a1b088
Commit
84a1b088
authored
Sep 30, 2012
by
Serge S. Koval
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed #73. Added _template_args property which value will be contributed to template when rendering
parent
87566626
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
1 deletion
+35
-1
base.py
flask_admin/base.py
+35
-1
No files found.
flask_admin/base.py
View file @
84a1b088
from
functools
import
wraps
from
re
import
sub
from
flask
import
Blueprint
,
render_template
,
url_for
,
abort
from
flask
import
Blueprint
,
render_template
,
url_for
,
abort
,
g
from
flask.ext.admin
import
babel
...
...
@@ -86,6 +86,37 @@ class BaseView(object):
"""
__metaclass__
=
AdminViewMeta
@
property
def
_template_args
(
self
):
"""
Extra template arguments.
If you need to pass some extra parameters to the template,
you can override particular view function, contribute
arguments you want to pass to the template and call parent view.
These arguments are local for this request and will be discarded
in next request.
Any value passed through ``_template_args`` will override whatever
parent view function passed to the template.
For example::
class MyAdmin(ModelView):
@expose('/')
def index(self):
self._template_args['name'] = 'foobar'
self._template_args['code'] = '12345'
super(MyAdmin, self).index()
"""
args
=
getattr
(
g
,
'_admin_template_args'
,
None
)
if
args
is
None
:
args
=
g
.
_admin_template_args
=
dict
()
return
args
def
__init__
(
self
,
name
=
None
,
category
=
None
,
endpoint
=
None
,
url
=
None
,
static_folder
=
None
):
"""
Constructor.
...
...
@@ -180,6 +211,9 @@ class BaseView(object):
kwargs
[
'_gettext'
]
=
babel
.
gettext
kwargs
[
'_ngettext'
]
=
babel
.
ngettext
# Contribute extra arguments
kwargs
.
update
(
self
.
_template_args
)
return
render_template
(
template
,
**
kwargs
)
def
_prettify_name
(
self
,
name
):
...
...
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