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
1c16ba98
Commit
1c16ba98
authored
Sep 13, 2012
by
Serge S. Koval
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added jinja2 context to the list formatting callback.
Example here:
https://gist.github.com/3714266
parent
7cd9efdf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
2 deletions
+23
-2
base.py
flask_admin/model/base.py
+7
-2
template.py
flask_admin/model/template.py
+16
-0
No files found.
flask_admin/model/base.py
View file @
1c16ba98
from
flask
import
request
,
url_for
,
redirect
,
flash
from
flask
import
request
,
url_for
,
redirect
,
flash
from
jinja2
import
contextfunction
from
flask.ext.admin.babel
import
gettext
from
flask.ext.admin.babel
import
gettext
from
flask.ext.admin.base
import
BaseView
,
expose
from
flask.ext.admin.base
import
BaseView
,
expose
...
@@ -665,17 +667,20 @@ class BaseModelView(BaseView, ActionsMixin):
...
@@ -665,17 +667,20 @@ class BaseModelView(BaseView, ActionsMixin):
"""
"""
return
name
not
in
self
.
disallowed_actions
return
name
not
in
self
.
disallowed_actions
def
get_list_value
(
self
,
model
,
name
):
@
contextfunction
def
get_list_value
(
self
,
context
,
model
,
name
):
"""
"""
Returns value to be displayed in list view
Returns value to be displayed in list view
:param context:
Jinja2 context
:param model:
:param model:
Model instance
Model instance
:param name:
:param name:
Field name
Field name
"""
"""
if
name
in
self
.
list_formatters
:
if
name
in
self
.
list_formatters
:
return
self
.
list_formatters
[
name
](
model
,
name
)
return
self
.
list_formatters
[
name
](
context
,
model
,
name
)
return
rec_getattr
(
model
,
name
)
return
rec_getattr
(
model
,
name
)
...
...
flask_admin/model/template.py
0 → 100644
View file @
1c16ba98
def
macro
(
name
):
'''
Jinja2 macro list column formatter.
:param name:
Macro name in the current template
'''
def
inner
(
context
,
model
,
column
):
m
=
context
.
resolve
(
name
)
if
not
m
:
return
m
return
m
(
model
=
model
,
column
=
column
)
return
inner
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