Search screen now supports String fields with Selection instances as validators.

This commit is contained in:
Gaetan Delannay 2010-01-09 19:09:13 +01:00
parent c37fa93858
commit 2ecd2d7ef1
3 changed files with 27 additions and 5 deletions

View file

@ -1,6 +1,6 @@
# ------------------------------------------------------------------------------
import re, os, os.path, Cookie
from appy.gen import Type, Search
from appy.gen import Type, Search, Selection
from appy.gen.utils import FieldDescr, SomeObjects, sequenceTypes
from appy.gen.plone25.mixins import AbstractMixin
from appy.gen.plone25.mixins.FlavourMixin import FlavourMixin
@ -683,4 +683,20 @@ class ToolMixin(AbstractMixin):
def getMonthName(self, monthNumber):
'''Gets the translated month name of month numbered p_monthNumber.'''
return self.translate(self.monthsIds[int(monthNumber)], domain='plone')
def getSelectValues(self, appyType):
'''Return the possible values (with their translation) of String type
p_appyType (dict version) which is a string whose validator limits
the possible values, either statically (validator is simply a list
of values) or dynamically (validator is a Selection instance).'''
validator = appyType['validator']
if isinstance(validator, Selection):
vocab = self._appy_getDynamicDisplayList(validator.methodName)
return vocab.items()
else:
res = []
for v in validator:
text = self.translate('%s_list_%s' % (appyType['label'], v))
res.append((v, self.truncate(text, 70)))
return res
# ------------------------------------------------------------------------------

View file

@ -1014,10 +1014,16 @@ class AbstractMixin:
args = elems[1:]
else:
args = ()
# On what object must be call the method that will produce the values?
obj = self
if methodName.startswith('tool:'):
obj = self.getTool()
methodName = methodName[5:]
# Do we need to call the method on the object or on the wrapper?
if methodName.startswith('_appy_'):
exec 'res = self.%s(*args)' % methodName
exec 'res = obj.%s(*args)' % methodName
else:
exec 'res = self.appy().%s(*args)' % methodName
exec 'res = obj.appy().%s(*args)' % methodName
return self.getProductConfig().DisplayList(tuple(res))
nullValues = (None, '', ' ')