From 2ecd2d7ef1562325325cccfe525e2f7eac16c7eb Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Sat, 9 Jan 2010 19:09:13 +0100 Subject: [PATCH] Search screen now supports String fields with Selection instances as validators. --- gen/plone25/mixins/ToolMixin.py | 18 +++++++++++++++++- gen/plone25/mixins/__init__.py | 10 ++++++++-- gen/plone25/skin/widgets.pt | 4 ++-- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/gen/plone25/mixins/ToolMixin.py b/gen/plone25/mixins/ToolMixin.py index 8995f04..27e437d 100644 --- a/gen/plone25/mixins/ToolMixin.py +++ b/gen/plone25/mixins/ToolMixin.py @@ -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 # ------------------------------------------------------------------------------ diff --git a/gen/plone25/mixins/__init__.py b/gen/plone25/mixins/__init__.py index 4721c5f..810bcd6 100644 --- a/gen/plone25/mixins/__init__.py +++ b/gen/plone25/mixins/__init__.py @@ -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, '', ' ') diff --git a/gen/plone25/skin/widgets.pt b/gen/plone25/skin/widgets.pt index 7d5c1bb..fcd4b0e 100644 --- a/gen/plone25/skin/widgets.pt +++ b/gen/plone25/skin/widgets.pt @@ -23,8 +23,8 @@ Show a multi-selection box for fields whose validator defines a list of values.