summaryrefslogtreecommitdiff
path: root/horizon/tables
diff options
context:
space:
mode:
authorGabriel Hurley <gabriel@strikeawe.com>2012-03-24 23:01:19 -0700
committerGabriel Hurley <gabriel@strikeawe.com>2012-03-24 23:04:07 -0700
commit52b9e1982b73ca8773e9be8801909969a5b27f0a (patch)
treeafe09458b9d9573b382afb7f90b5df4f4f08b5eb /horizon/tables
parent28defb5ca98dea7aecca7dcb337dfa7c41879ef3 (diff)
downloadhorizon-52b9e1982b73ca8773e9be8801909969a5b27f0a.tar.gz
Copies column instances to be unique per table instance.
Fixes bug 964345. Incidentally fixes bug 964351 as well by wrapping the dropdown actions template code in a spaceless tag. Change-Id: I672cb517d230db235c90a403e9b8ac0740e8732d
Diffstat (limited to 'horizon/tables')
-rw-r--r--horizon/tables/base.py25
-rw-r--r--horizon/tables/views.py2
2 files changed, 17 insertions, 10 deletions
diff --git a/horizon/tables/base.py b/horizon/tables/base.py
index ea14b1234..fc39f362d 100644
--- a/horizon/tables/base.py
+++ b/horizon/tables/base.py
@@ -617,13 +617,14 @@ class DataTableMetaclass(type):
# Gather columns; this prevents the column from being an attribute
# on the DataTable class and avoids naming conflicts.
- columns = [(column_name, attrs.pop(column_name)) for
- column_name, obj in attrs.items()
- if issubclass(type(obj), (opts.column_class, Column))]
- # add a name attribute to each column
- for column_name, column in columns:
- column.name = column_name
+ columns = []
+ for name, obj in attrs.items():
+ if issubclass(type(obj), (opts.column_class, Column)):
+ column_instance = attrs.pop(name)
+ column_instance.name = name
+ columns.append((name, column_instance))
columns.sort(key=lambda x: x[1].creation_counter)
+
# Iterate in reverse to preserve final order
for base in bases[::-1]:
if hasattr(base, 'base_columns'):
@@ -651,7 +652,8 @@ class DataTableMetaclass(type):
actions_column.classes.append('actions_column')
actions_column.auto = "actions"
columns.append(("actions", actions_column))
- attrs['columns'] = SortedDict(columns)
+ # Store this set of columns internally so we can copy them per-instance
+ attrs['_columns'] = SortedDict(columns)
# Gather and register actions for later access since we only want
# to instantiate them once.
@@ -698,11 +700,16 @@ class DataTable(object):
def __init__(self, request, data=None, **kwargs):
self._meta.request = request
self._meta.data = data
- self._populate_data_cache()
self.kwargs = kwargs
- for column in self.columns.values():
+ # Create a new set
+ columns = []
+ for key, _column in self._columns.items():
+ column = copy.copy(_column)
column.table = self
+ columns.append((key, column))
+ self.columns = SortedDict(columns)
+ self._populate_data_cache()
# Associate these actions with this table
for action in self.base_actions.values():
diff --git a/horizon/tables/views.py b/horizon/tables/views.py
index 810118105..612afcac2 100644
--- a/horizon/tables/views.py
+++ b/horizon/tables/views.py
@@ -39,7 +39,7 @@ class MultiTableMixin(object):
def get_tables(self):
if not self.table_classes:
- raise AttributeError('You must specify a one or more DataTable '
+ raise AttributeError('You must specify one or more DataTable '
'classes for the "table_classes" attribute '
'on %s.' % self.__class__.__name__)
if not self._tables: