make keytable field and widget fully operable
This commit is contained in:
parent
2d5b4e5603
commit
3bc258a428
3 changed files with 30 additions and 4 deletions
|
@ -126,6 +126,9 @@ class GridFieldInstance(ListFieldInstance):
|
||||||
|
|
||||||
class RecordsFieldInstance(GridFieldInstance):
|
class RecordsFieldInstance(GridFieldInstance):
|
||||||
|
|
||||||
|
def getRenderer(self, name):
|
||||||
|
return grid_macros.macros[name]
|
||||||
|
|
||||||
def marshall(self, value):
|
def marshall(self, value):
|
||||||
result = []
|
result = []
|
||||||
for row in value or []:
|
for row in value or []:
|
||||||
|
@ -156,6 +159,16 @@ class KeyTableFieldInstance(RecordsFieldInstance):
|
||||||
def dataNames(self):
|
def dataNames(self):
|
||||||
return [f.name for f in self.columnTypes[1:]]
|
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):
|
def marshall(self, value):
|
||||||
result = []
|
result = []
|
||||||
if not value:
|
if not value:
|
||||||
|
|
|
@ -39,16 +39,14 @@
|
||||||
|
|
||||||
|
|
||||||
<metal:input define-macro="input_records"
|
<metal:input define-macro="input_records"
|
||||||
tal:define="fieldInstance python: field.getFieldInstance(item.instance);
|
tal:define="fieldInstance python: field.getFieldInstance(view.instance);
|
||||||
columns fieldInstance/columnTypes;
|
columns fieldInstance/columnTypes;
|
||||||
rows data/?name">
|
rows data/?name">
|
||||||
<table class="records">
|
<table class="records">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<tal:header repeat="column columns">
|
<tal:header repeat="column columns">
|
||||||
<th width="auto" editable="true"
|
<th tal:attributes="field column/name;"
|
||||||
tal:attributes="field column/name;
|
|
||||||
style string:width: ${column/baseField/width|string:auto};"
|
|
||||||
tal:content="column/title">Column Title</th>
|
tal:content="column/title">Column Title</th>
|
||||||
</tal:header>
|
</tal:header>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -92,5 +90,18 @@
|
||||||
</metal:input>
|
</metal:input>
|
||||||
|
|
||||||
|
|
||||||
|
<metal:display define-macro="display_records"
|
||||||
|
tal:define="value data/?fieldName">
|
||||||
|
<table class="listing">
|
||||||
|
<tr>
|
||||||
|
<th tal:repeat="header value/headers"
|
||||||
|
tal:content="header">Column Title</th></tr>
|
||||||
|
<tr tal:repeat="row value/rows">
|
||||||
|
<td tal:repeat="cell row"
|
||||||
|
tal:content="cell" /></tr>
|
||||||
|
</table>
|
||||||
|
</metal:display>
|
||||||
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -55,5 +55,7 @@ class KeyTable(Grid):
|
||||||
FieldType('keytable', 'keytable',
|
FieldType('keytable', 'keytable',
|
||||||
u'A dictionary of records or rows the first '
|
u'A dictionary of records or rows the first '
|
||||||
u'column of which represents the key.',
|
u'column of which represents the key.',
|
||||||
|
displayRenderer='display_records',
|
||||||
|
inputRenderer='input_records',
|
||||||
instanceName='keytable',))
|
instanceName='keytable',))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue