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:
|
style python:
|
||||||
'width: %s' % (width and str(width)+'px' or '');">
|
'width: %s' % (width and str(width)+'px' or '');">
|
||||||
<option tal:repeat="item python:
|
<option tal:repeat="item python:
|
||||||
field.getVocabularyItems(instance.context, request)"
|
field.getVocabularyItems(instance, request)"
|
||||||
tal:content="item/title"
|
tal:content="item/title"
|
||||||
tal:attributes="value item/token;
|
tal:attributes="value item/token;
|
||||||
selected python:
|
selected python:
|
||||||
|
|
|
@ -129,7 +129,10 @@ class Field(Component):
|
||||||
def getTitleValue(self):
|
def getTitleValue(self):
|
||||||
return self.title or self.name
|
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 '')
|
voc = (self.vocabulary or '')
|
||||||
if isinstance(voc, basestring):
|
if isinstance(voc, basestring):
|
||||||
terms = self.getVocabularyTerms(voc, context, request)
|
terms = self.getVocabularyTerms(voc, context, request)
|
||||||
|
@ -138,7 +141,7 @@ class Field(Component):
|
||||||
voc = voc.splitlines()
|
voc = voc.splitlines()
|
||||||
return [dict(token=t, title=t) for t in voc if t.strip()]
|
return [dict(token=t, title=t) for t in voc if t.strip()]
|
||||||
elif IContextSourceBinder.providedBy(voc):
|
elif IContextSourceBinder.providedBy(voc):
|
||||||
source = voc(context)
|
source = voc(instance)
|
||||||
terms = component.queryMultiAdapter((source, request), ITerms)
|
terms = component.queryMultiAdapter((source, request), ITerms)
|
||||||
if terms is not None:
|
if terms is not None:
|
||||||
termsList = [terms.getTerm(value) for value in source]
|
termsList = [terms.getTerm(value) for value in source]
|
||||||
|
@ -395,7 +398,7 @@ class CheckBoxesFieldInstance(ListFieldInstance):
|
||||||
class DropdownFieldInstance(FieldInstance):
|
class DropdownFieldInstance(FieldInstance):
|
||||||
|
|
||||||
def display(self, value):
|
def display(self, value):
|
||||||
items = self.context.getVocabularyItems(self.clientContext, self.request)
|
items = self.context.getVocabularyItems(self.clientInstance, self.request)
|
||||||
for item in items:
|
for item in items:
|
||||||
if item['token'] == value:
|
if item['token'] == value:
|
||||||
return item['title']
|
return item['title']
|
||||||
|
|
Loading…
Add table
Reference in a new issue