Commit 51ded02d authored by Tom Kedem's avatar Tom Kedem

- fixed hybrid properties support

- added hybrid properties filters support
parent 97cc3252
...@@ -484,7 +484,7 @@ class ModelView(BaseModelView): ...@@ -484,7 +484,7 @@ class ModelView(BaseModelView):
"Failed on: {0}".format(c)) "Failed on: {0}".format(c))
else: else:
# column is in same table, use only model attribute name # column is in same table, use only model attribute name
column_name = column.key column_name = column.key if hasattr(column, 'key') and column.key else text_type(c)
# column_name must match column_name used in `get_list_columns` # column_name must match column_name used in `get_list_columns`
result[column_name] = column result[column_name] = column
...@@ -517,7 +517,7 @@ class ModelView(BaseModelView): ...@@ -517,7 +517,7 @@ class ModelView(BaseModelView):
column_name = text_type(c) column_name = text_type(c)
else: else:
# column is in same table, use only model attribute name # column is in same table, use only model attribute name
column_name = column.key column_name = column.key if hasattr(column, 'key') and column.key else text_type(c)
visible_name = self.get_column_name(column_name) visible_name = self.get_column_name(column_name)
...@@ -558,11 +558,8 @@ class ModelView(BaseModelView): ...@@ -558,11 +558,8 @@ class ModelView(BaseModelView):
if attr is None: if attr is None:
raise Exception('Failed to find field for filter: %s' % name) raise Exception('Failed to find field for filter: %s' % name)
# Figure out filters for related column, unless it's a hybrid_property # Figure out filters for related column
if isinstance(attr, ColumnElement): if hasattr(attr, 'property') and hasattr(attr.property, 'direction'):
warnings.warn(('Unable to scaffold the filter for %s, scaffolding '
'for hybrid_property is not supported yet.') % name)
elif hasattr(attr, 'property') and hasattr(attr.property, 'direction'):
filters = [] filters = []
for p in self._get_model_iterator(attr.property.mapper.class_): for p in self._get_model_iterator(attr.property.mapper.class_):
...@@ -593,14 +590,19 @@ class ModelView(BaseModelView): ...@@ -593,14 +590,19 @@ class ModelView(BaseModelView):
return filters return filters
else: else:
columns = tools.get_columns_for_field(attr) is_hybrid_property = isinstance(attr, ColumnElement)
if is_hybrid_property:
column = attr
else:
columns = tools.get_columns_for_field(attr)
if len(columns) > 1: if len(columns) > 1:
raise Exception('Can not filter more than on one column for %s' % name) raise Exception('Can not filter more than on one column for %s' % name)
column = columns[0] column = columns[0]
if (tools.need_join(self.model, column.table) and # Join not needed for hybrid attributes
if (not is_hybrid_property and tools.need_join(self.model, column.table) and
name not in self.column_labels): name not in self.column_labels):
visible_name = '%s / %s' % ( visible_name = '%s / %s' % (
self.get_column_name(column.table.name), self.get_column_name(column.table.name),
...@@ -623,7 +625,7 @@ class ModelView(BaseModelView): ...@@ -623,7 +625,7 @@ class ModelView(BaseModelView):
if joins: if joins:
self._filter_joins[column] = joins self._filter_joins[column] = joins
elif tools.need_join(self.model, column.table): elif not is_hybrid_property and tools.need_join(self.model, column.table):
self._filter_joins[column] = [column.table] self._filter_joins[column] = [column.table]
return flt return flt
......
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