Permalink
Browse files

Fixed #67. Do not use getattr to inspect properties

  • Loading branch information...
mrjoes committed Sep 26, 2012
1 parent 81b54bc commit fa63062e88c7f4e576762b8223a8d6e89e9d7218
Showing with 22 additions and 4 deletions.
  1. +0 −1 examples/auth/templates/form.html
  2. +0 −2 examples/sqla/simple.py
  3. +4 −1 flask_admin/actions.py
  4. +18 −0 flask_admin/tools.py
@@ -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 }}
View
@@ -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')
View
@@ -1,6 +1,9 @@
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 @@ def init_actions(self):
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
View
@@ -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

0 comments on commit fa63062

Please sign in to comment.