preserve information on client context and - for records/grid - row index in field instances
This commit is contained in:
parent
707d7abf6d
commit
2c09a682db
3 changed files with 20 additions and 12 deletions
|
@ -1,5 +1,5 @@
|
|||
#
|
||||
# Copyright (c) 2011 Helmut Merz helmutm@cy55.de
|
||||
# Copyright (c) 2013 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
|
||||
|
@ -185,8 +185,10 @@ class FieldInstance(object):
|
|||
adapts(IField)
|
||||
|
||||
clientInstance = None
|
||||
clientContext = None
|
||||
value = undefined
|
||||
request = None
|
||||
index = None
|
||||
|
||||
def __init__(self, context):
|
||||
self.context = context
|
||||
|
|
|
@ -50,8 +50,11 @@ class GridFieldInstance(ListFieldInstance):
|
|||
for f in self.columnTypes:
|
||||
instanceName = (f.instance_name or
|
||||
f.getFieldTypeInfo().instanceName)
|
||||
result.append(component.getAdapter(f, IFieldInstance,
|
||||
name=instanceName))
|
||||
fi = component.getAdapter(f, IFieldInstance, name=instanceName)
|
||||
fi.clientInstance = self.clientInstance
|
||||
fi.clientContext = self.clientContext
|
||||
fi.request = self.request
|
||||
result.append(fi)
|
||||
return result
|
||||
|
||||
def marshall(self, value):
|
||||
|
@ -89,8 +92,8 @@ class GridFieldInstance(ListFieldInstance):
|
|||
return []
|
||||
result = []
|
||||
rows = json.loads(value)['items']
|
||||
for row in rows:
|
||||
item = self.unmarshallRow(row)
|
||||
for idx, row in enumerate(rows):
|
||||
item = self.unmarshallRow(row, idx)
|
||||
if item:
|
||||
result.append(item)
|
||||
return result
|
||||
|
@ -111,9 +114,11 @@ class GridFieldInstance(ListFieldInstance):
|
|||
result.append(item)
|
||||
return result
|
||||
|
||||
def unmarshallRow(self, row):
|
||||
def unmarshallRow(self, row, idx=None):
|
||||
item = {}
|
||||
for fi in self.columnFieldInstances:
|
||||
if idx is not None:
|
||||
fi.index = idx
|
||||
value = fi.unmarshall(row.get(fi.name) or u'')
|
||||
if isinstance(value, basestring):
|
||||
value = value.strip()
|
||||
|
@ -143,8 +148,8 @@ class RecordsFieldInstance(GridFieldInstance):
|
|||
if not value:
|
||||
value = []
|
||||
result = []
|
||||
for row in value:
|
||||
item = self.unmarshallRow(row)
|
||||
for idx, row in enumerate(value):
|
||||
item = self.unmarshallRow(row, idx)
|
||||
if item:
|
||||
result.append(item)
|
||||
return result
|
||||
|
@ -187,8 +192,8 @@ class KeyTableFieldInstance(RecordsFieldInstance):
|
|||
if not value:
|
||||
value = {}
|
||||
result = {}
|
||||
for row in value:
|
||||
item = self.unmarshallRow(row)
|
||||
for idx, row in enumerate(value):
|
||||
item = self.unmarshallRow(row, idx)
|
||||
if item:
|
||||
result[item.pop(self.keyName)] = [item.get(name) or u''
|
||||
for name in self.dataNames]
|
||||
|
|
|
@ -68,7 +68,8 @@ class Instance(BaseInstance):
|
|||
template = self.template
|
||||
if template is not None:
|
||||
for f in template.components:
|
||||
fieldInstances[f.name] = f.getFieldInstance(self)
|
||||
fieldInstances[f.name] = f.getFieldInstance(self,
|
||||
context=self.context)
|
||||
return fieldInstances
|
||||
|
||||
@Lazy
|
||||
|
@ -122,7 +123,7 @@ class Editor(BaseInstance):
|
|||
for f in self.template.components:
|
||||
if f.readonly:
|
||||
continue
|
||||
fi = f.getFieldInstance(self)
|
||||
fi = f.getFieldInstance(self, context=self.context)
|
||||
#value = data.get(f.name)
|
||||
value = fi.getRawValue(data, f.name)
|
||||
fi.validate(value, data)
|
||||
|
|
Loading…
Add table
Reference in a new issue