Added possibility to select AND/OR operator for searches in lists.

This commit is contained in:
Gaetan Delannay 2010-03-19 13:13:36 +01:00
parent cbb77e0224
commit f70af04d4c
5 changed files with 24 additions and 4 deletions

View file

@ -237,8 +237,7 @@ class ArchetypeFieldDescriptor:
self.classDescr.addDefaultMethod(methodName, self)
# - put an index on this field?
if self.appyType.indexed:
if (self.appyType.type == 'String') and \
(self.appyType.isMultiValued()):
if (self.appyType.type == 'String') and (self.appyType.isSelect):
self.fieldParams['index'] = 'ZCTextIndex, lexicon_id=' \
'plone_lexicon, index_type=Okapi BM25 Rank'
else:

View file

@ -124,6 +124,8 @@ class Generator(AbstractGenerator):
msg('search_new', '', msg.SEARCH_NEW),
msg('search_from', '', msg.SEARCH_FROM),
msg('search_to', '', msg.SEARCH_TO),
msg('search_or', '', msg.SEARCH_OR),
msg('search_and', '', msg.SEARCH_AND),
msg('ref_invalid_index', '', msg.REF_INVALID_INDEX),
msg('bad_int', '', msg.BAD_INT),
msg('bad_float', '', msg.BAD_FLOAT),

View file

@ -443,6 +443,7 @@ class ToolMixin(AbstractMixin):
# given field.
attrValue = rq.form[attrName]
if attrName.find('*') != -1:
# The type of the value is encoded after char "*".
attrName, attrType = attrName.split('*')
if attrType == 'bool':
exec 'attrValue = %s' % attrValue
@ -471,7 +472,12 @@ class ToolMixin(AbstractMixin):
toDate = self._getDateTime(year, month, day, False)
attrValue = (fromDate, toDate)
if isinstance(attrValue, list):
attrValue = ' OR '.join(attrValue)
# It is a list of values. Check if we have an operator for
# the field, to see if we make an "and" or "or" for all
# those values. "or" will be the default.
operKey = 'o_%s' % attrName[2:]
oper = ' %s ' % rq.form.get(operKey, 'or').upper()
attrValue = oper.join(attrValue)
criteria[attrName[2:]] = attrValue
rq.SESSION['searchCriteria'] = criteria
# Goto the screen that displays search results

View file

@ -28,8 +28,19 @@
<tal:simpleSearch condition="not: appyType/isSelect">
<input type="text" tal:attributes="name widgetName"/>
</tal:simpleSearch>
<tal:comment replace="nothing">Show a multi-selection box for fields whose validator defines a list of values.</tal:comment>
<tal:comment replace="nothing">Show a multi-selection box for fields whose validator defines a list of values, with a "AND/OR" checkbox.</tal:comment>
<tal:selectSearch condition="appyType/isSelect">
<tal:comment replace="nothing">The "and" / "or" radio buttons</tal:comment>
<tal:operator define="operName python: 'o_%s' % fieldName;
orName python: '%s_or' % operName;
andName python: '%s_and' % operName;"
condition="python: appyType['multiplicity'][1]!=1">
<input type="radio" class="noborder" tal:attributes="name operName; id orName" checked="checked" value="or"/>
<label tal:attributes="for orName" tal:content="python: tool.translate('search_or')"></label>
<input type="radio" class="noborder" tal:attributes="name operName; id andName" value="and"/>
<label tal:attributes="for andName" tal:content="python: tool.translate('search_and')"></label><br/>
</tal:operator>
<tal:comment replace="nothing">The list of values</tal:comment>
<select tal:attributes="name widgetName" multiple="multiple" size="5">
<option tal:repeat="v python:tool.getSelectValues(appyType)"
tal:attributes="value python:v[0]" tal:content="python: v[1]">

View file

@ -65,6 +65,8 @@ class PoMessage:
SEARCH_NEW = 'New search'
SEARCH_FROM = 'From'
SEARCH_TO = 'to'
SEARCH_OR = 'or'
SEARCH_AND = 'and'
WORKFLOW_COMMENT = 'Optional comment'
WORKFLOW_STATE = 'state'
DATA_CHANGE = 'Data change'