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
fa63062e
Commit
fa63062e
authored
Sep 26, 2012
by
Serge S. Koval
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed #67. Do not use getattr to inspect properties
parent
81b54bcd
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
4 deletions
+22
-4
form.html
examples/auth/templates/form.html
+0
-1
simple.py
examples/sqla/simple.py
+0
-2
actions.py
flask_admin/actions.py
+4
-1
tools.py
flask_admin/tools.py
+18
-0
No files found.
examples/auth/templates/form.html
View file @
fa63062e
...
...
@@ -3,7 +3,6 @@
<form
method=
"POST"
action=
""
>
{{ form.hidden_tag() }}
{% for f in form if f.type != 'CSRFTokenField' %}
{{ f.type }}
<div>
{{ f.label }}
{{ f }}
...
...
examples/sqla/simple.py
View file @
fa63062e
...
...
@@ -88,8 +88,6 @@ class PostAdmin(sqlamodel.ModelView):
#list_columns = ('title', 'user')
excluded_list_columns
=
[
'text'
]
list_display_all_relations
=
True
# List of columns that can be sorted. For 'user' column, use User.username as
# a column.
sortable_columns
=
(
'title'
,
(
'user'
,
User
.
username
),
'date'
)
...
...
flask_admin/actions.py
View file @
fa63062e
from
flask
import
request
,
url_for
,
redirect
from
flask.ext.admin.tools
import
get_dict_attr
def
action
(
name
,
text
,
confirmation
=
None
):
"""
Use this decorator to expose actions that span more than one
...
...
@@ -50,7 +53,7 @@ class ActionsMixin(object):
self
.
_actions_data
=
{}
for
p
in
dir
(
self
):
attr
=
getattr
(
self
,
p
)
attr
=
get
_dict_
attr
(
self
,
p
)
if
hasattr
(
attr
,
'_action'
):
name
,
text
,
desc
=
attr
.
_action
...
...
flask_admin/tools.py
View file @
fa63062e
...
...
@@ -75,3 +75,21 @@ def rec_getattr(obj, attr, default=None):
return
reduce
(
getattr
,
attr
.
split
(
'.'
),
obj
)
except
AttributeError
:
return
default
def
get_dict_attr
(
obj
,
attr
,
default
=
None
):
"""
Get attibute of the object without triggering its __getattr__.
:param obj:
Object
:param attr:
Attribute name
:param default:
Default value if attribute was not found
"""
for
obj
in
[
obj
]
+
obj
.
__class__
.
mro
():
if
attr
in
obj
.
__dict__
:
return
obj
.
__dict__
[
attr
]
return
default
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