Column names with character "." don't work
Issue #75
new
Event though it is strange, it’s indeed possible to have a table column with a name that contains the characther “.” (e.g. “N. ROWS”). Now if a column has the character “.” the code raises an Exception due to how module notation is handled in function _render_column:
parts = column.split(“.”)
for part in parts[:-1]:
if obj is None:
break
obj = getattr(obj, part)
I think it would be best to first see if the row has already an attribute matching the column name and proceed (which in many cases will be the path taken), if that attribute is not present proceed with the “module notation”.
def _render_column(self, row, column):
""" Renders a column on a row. column can be given in a module notation eg. document.invoice.type
"""
obj = row
if hasattr(obj, column):
col_name = column
else:
parts = column.split('.')
for part in parts[:-1]:
if obj is None:
break
obj = getattr(obj, part)
col_name = parts[-1]
# try using get_OBJECT_display for choice fields
if hasattr(obj, 'get_%s_display' % col_name):
value = getattr(obj, 'get_%s_display' % col_name)()
else:
value = self._column_value(obj, col_name)
if value is None:
value = self.none_string
if self.escape_values:
value = escape(value)
return value
I don’t know if I am missing something, but this fix works for me.