Commit fa63062e authored by Serge S. Koval's avatar Serge S. Koval

Fixed #67. Do not use getattr to inspect properties

parent 81b54bcd
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
<form method="POST" action=""> <form method="POST" action="">
{{ form.hidden_tag() }} {{ form.hidden_tag() }}
{% for f in form if f.type != 'CSRFTokenField' %} {% for f in form if f.type != 'CSRFTokenField' %}
{{ f.type }}
<div> <div>
{{ f.label }} {{ f.label }}
{{ f }} {{ f }}
......
...@@ -88,8 +88,6 @@ class PostAdmin(sqlamodel.ModelView): ...@@ -88,8 +88,6 @@ class PostAdmin(sqlamodel.ModelView):
#list_columns = ('title', 'user') #list_columns = ('title', 'user')
excluded_list_columns = ['text'] excluded_list_columns = ['text']
list_display_all_relations = True
# List of columns that can be sorted. For 'user' column, use User.username as # List of columns that can be sorted. For 'user' column, use User.username as
# a column. # a column.
sortable_columns = ('title', ('user', User.username), 'date') sortable_columns = ('title', ('user', User.username), 'date')
......
from flask import request, url_for, redirect from flask import request, url_for, redirect
from flask.ext.admin.tools import get_dict_attr
def action(name, text, confirmation=None): def action(name, text, confirmation=None):
""" """
Use this decorator to expose actions that span more than one Use this decorator to expose actions that span more than one
...@@ -50,7 +53,7 @@ class ActionsMixin(object): ...@@ -50,7 +53,7 @@ class ActionsMixin(object):
self._actions_data = {} self._actions_data = {}
for p in dir(self): for p in dir(self):
attr = getattr(self, p) attr = get_dict_attr(self, p)
if hasattr(attr, '_action'): if hasattr(attr, '_action'):
name, text, desc = attr._action name, text, desc = attr._action
......
...@@ -75,3 +75,21 @@ def rec_getattr(obj, attr, default=None): ...@@ -75,3 +75,21 @@ def rec_getattr(obj, attr, default=None):
return reduce(getattr, attr.split('.'), obj) return reduce(getattr, attr.split('.'), obj)
except AttributeError: except AttributeError:
return default 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment