provide field instance with context and request information, e.g. for use in persistent vocabularies
This commit is contained in:
parent
5fc606bbd3
commit
8c3118e333
2 changed files with 7 additions and 4 deletions
|
@ -157,12 +157,14 @@ class Field(Component):
|
||||||
def getFieldTypeInfo(self):
|
def getFieldTypeInfo(self):
|
||||||
return self.fieldTypeInfo or fieldTypes.getTerm(self.fieldType)
|
return self.fieldTypeInfo or fieldTypes.getTerm(self.fieldType)
|
||||||
|
|
||||||
def getFieldInstance(self, clientInstance=None):
|
def getFieldInstance(self, clientInstance=None, context=None, request=None):
|
||||||
instanceName = self.instance_name or self.getFieldTypeInfo().instanceName
|
instanceName = self.instance_name or self.getFieldTypeInfo().instanceName
|
||||||
fi = component.queryAdapter(self, IFieldInstance, name=instanceName)
|
fi = component.queryAdapter(self, IFieldInstance, name=instanceName)
|
||||||
if fi is None:
|
if fi is None:
|
||||||
fi = component.getAdapter(self, IFieldInstance, name='')
|
fi = component.getAdapter(self, IFieldInstance, name='')
|
||||||
fi.clientInstance = clientInstance
|
fi.clientInstance = clientInstance
|
||||||
|
fi.clientContext = context
|
||||||
|
fi.request = request
|
||||||
return fi
|
return fi
|
||||||
|
|
||||||
def getContextProperties(self):
|
def getContextProperties(self):
|
||||||
|
@ -174,7 +176,7 @@ class FieldInstance(object):
|
||||||
implements(IFieldInstance)
|
implements(IFieldInstance)
|
||||||
adapts(IField)
|
adapts(IField)
|
||||||
|
|
||||||
clientInstance = None
|
clientInstance = clientContext = request = None
|
||||||
value = undefined
|
value = undefined
|
||||||
|
|
||||||
def __init__(self, context):
|
def __init__(self, context):
|
||||||
|
@ -388,7 +390,7 @@ class CheckBoxesFieldInstance(ListFieldInstance):
|
||||||
class DropdownFieldInstance(FieldInstance):
|
class DropdownFieldInstance(FieldInstance):
|
||||||
|
|
||||||
def display(self, value):
|
def display(self, value):
|
||||||
items = self.context.getVocabularyItems()
|
items = self.context.getVocabularyItems(self.clientContext, self.request)
|
||||||
for item in items:
|
for item in items:
|
||||||
if item['token'] == value:
|
if item['token'] == value:
|
||||||
return item['title']
|
return item['title']
|
||||||
|
|
|
@ -52,7 +52,8 @@ class Instance(BaseInstance):
|
||||||
if not f.storeData:
|
if not f.storeData:
|
||||||
# a dummy field, e.g. a spacer
|
# a dummy field, e.g. a spacer
|
||||||
continue
|
continue
|
||||||
fi = f.getFieldInstance(self)
|
fi = f.getFieldInstance(self, context=kw.get('context'),
|
||||||
|
request=kw.get('request'))
|
||||||
name = f.name
|
name = f.name
|
||||||
value = getattr(self.context, name) or fi.default
|
value = getattr(self.context, name) or fi.default
|
||||||
if mode in ('view', 'preview'):
|
if mode in ('view', 'preview'):
|
||||||
|
|
Loading…
Add table
Reference in a new issue