use instance (instead of context) for getting vocabulary items in order to avoid loss of information (e.g. access to view)
This commit is contained in:
parent
2f003cc447
commit
6815364dec
2 changed files with 7 additions and 4 deletions
|
@ -162,7 +162,7 @@
|
|||
style python:
|
||||
'width: %s' % (width and str(width)+'px' or '');">
|
||||
<option tal:repeat="item python:
|
||||
field.getVocabularyItems(instance.context, request)"
|
||||
field.getVocabularyItems(instance, request)"
|
||||
tal:content="item/title"
|
||||
tal:attributes="value item/token;
|
||||
selected python:
|
||||
|
|
|
@ -129,7 +129,10 @@ class Field(Component):
|
|||
def getTitleValue(self):
|
||||
return self.title or self.name
|
||||
|
||||
def getVocabularyItems(self, context=None, request=None):
|
||||
def getVocabularyItems(self, instance=None, request=None):
|
||||
context = None
|
||||
if instance is not None:
|
||||
context = instance.context
|
||||
voc = (self.vocabulary or '')
|
||||
if isinstance(voc, basestring):
|
||||
terms = self.getVocabularyTerms(voc, context, request)
|
||||
|
@ -138,7 +141,7 @@ class Field(Component):
|
|||
voc = voc.splitlines()
|
||||
return [dict(token=t, title=t) for t in voc if t.strip()]
|
||||
elif IContextSourceBinder.providedBy(voc):
|
||||
source = voc(context)
|
||||
source = voc(instance)
|
||||
terms = component.queryMultiAdapter((source, request), ITerms)
|
||||
if terms is not None:
|
||||
termsList = [terms.getTerm(value) for value in source]
|
||||
|
@ -395,7 +398,7 @@ class CheckBoxesFieldInstance(ListFieldInstance):
|
|||
class DropdownFieldInstance(FieldInstance):
|
||||
|
||||
def display(self, value):
|
||||
items = self.context.getVocabularyItems(self.clientContext, self.request)
|
||||
items = self.context.getVocabularyItems(self.clientInstance, self.request)
|
||||
for item in items:
|
||||
if item['token'] == value:
|
||||
return item['title']
|
||||
|
|
Loading…
Add table
Reference in a new issue