diff --git a/composer/schema/grid/field.py b/composer/schema/grid/field.py index d67f33a..e5c8152 100644 --- a/composer/schema/grid/field.py +++ b/composer/schema/grid/field.py @@ -126,6 +126,9 @@ class GridFieldInstance(ListFieldInstance): class RecordsFieldInstance(GridFieldInstance): + def getRenderer(self, name): + return grid_macros.macros[name] + def marshall(self, value): result = [] for row in value or []: @@ -156,6 +159,16 @@ class KeyTableFieldInstance(RecordsFieldInstance): def dataNames(self): return [f.name for f in self.columnTypes[1:]] + def display(self, value): + headers = [fi.context.title for fi in self.columnFieldInstances] + rows = [] + for k, v in value.items(): + row = [k] + for idx, fi in enumerate(self.columnFieldInstances[1:]): + row.append(fi.display(v[idx])) + rows.append(row) + return dict(headers=headers, rows=rows) + def marshall(self, value): result = [] if not value: diff --git a/composer/schema/grid/grid_macros.pt b/composer/schema/grid/grid_macros.pt index 903be12..751e627 100755 --- a/composer/schema/grid/grid_macros.pt +++ b/composer/schema/grid/grid_macros.pt @@ -39,16 +39,14 @@ - @@ -92,5 +90,18 @@ + +
Column Title
+ + + + +
Column Title
+ + + diff --git a/composer/schema/grid/interfaces.py b/composer/schema/grid/interfaces.py index f6ca57a..b653d42 100644 --- a/composer/schema/grid/interfaces.py +++ b/composer/schema/grid/interfaces.py @@ -55,5 +55,7 @@ class KeyTable(Grid): FieldType('keytable', 'keytable', u'A dictionary of records or rows the first ' u'column of which represents the key.', + displayRenderer='display_records', + inputRenderer='input_records', instanceName='keytable',))