provide new RecordsField; add a method to the ActionsRegistry for overwriting settings

git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@3221 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2009-02-09 16:29:14 +00:00
parent 357ab008e5
commit 7eddce81ac
4 changed files with 74 additions and 2 deletions

View file

@ -86,6 +86,11 @@ class ActionRegistry(object):
catItem = self.actionsByCategory.setdefault(category, [])
catItem.append(action)
def getAction(self, name, category):
for a in self.actionsByName[name]:
if a.category == category:
return a
def get(self, category=None, names=[], view=None, **kw):
if view is None:
raise ValueError("The 'view' argument is missing.")

View file

@ -1,5 +1,5 @@
#
# Copyright (c) 2008 Helmut Merz helmutm@cy55.de
# Copyright (c) 2009 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -61,7 +61,6 @@ class GridFieldInstance(ListFieldInstance):
return value
v = value or []
for row in v:
#for k, vr in row.items():
for fi in self.columnFieldInstances:
vr = fi.marshall(row[fi.name])
if isinstance(vr, basestring):
@ -106,3 +105,34 @@ class GridFieldInstance(ListFieldInstance):
if not empty:
result.append(item)
return result
class RecordsFieldInstance(GridFieldInstance):
def marshall(self, value):
result = []
for row in value or []:
item = {}
for fi in self.columnFieldInstances:
item[fi.name] = fi.marshall(row[fi.name])
result.append(item)
return result
def unmarshall(self, value):
if not value:
value = []
result = []
for row in value:
item = {}
empty = True
for fi in self.columnFieldInstances:
value = fi.unmarshall(row[fi.name].strip())
item[fi.name] = value
if fi.default is not None:
if value and value != fi.default:
empty = False
elif value:
empty = False
if not empty:
result.append(item)
return result

View file

@ -38,5 +38,33 @@
</metal:input>
<metal:input define-macro="input_records"
tal:define="fieldInstance python: field.getFieldInstance(view.instance);
columns fieldInstance/columnTypes">
<table>
<tr>
<tal:header repeat="column columns">
<th width="auto" editable="true"
tal:attributes="field column/name"
tal:content="column/title">Column Title</th>
</tal:header>
</tr>
<tr tal:repeat="row data/?name">
<td tal:repeat="column columns">
<input type="text" size="14"
tal:define="cname column/name"
tal:attributes="value row/?cname;
name string:$name.$cname:records" /></td>
</tr>
<tr tal:attributes="id string:$name.empty">
<td tal:repeat="column columns">
<input type="text" size="14"
tal:define="cname column/name"
tal:attributes="name string:$name.$cname:records" /></td>
</tr>
</table><br />
</metal:input>
</body>
</html>

View file

@ -40,3 +40,12 @@ class Grid(schema.List):
instanceName='grid'))
column_types = []
class Records(Grid):
__typeInfo__ = ('records',
FieldType('records', 'records',
u'A series of records or rows.',
instanceName='records',))