Added possibility to select AND/OR operator for searches in lists.
This commit is contained in:
parent
cbb77e0224
commit
f70af04d4c
|
@ -237,8 +237,7 @@ class ArchetypeFieldDescriptor:
|
||||||
self.classDescr.addDefaultMethod(methodName, self)
|
self.classDescr.addDefaultMethod(methodName, self)
|
||||||
# - put an index on this field?
|
# - put an index on this field?
|
||||||
if self.appyType.indexed:
|
if self.appyType.indexed:
|
||||||
if (self.appyType.type == 'String') and \
|
if (self.appyType.type == 'String') and (self.appyType.isSelect):
|
||||||
(self.appyType.isMultiValued()):
|
|
||||||
self.fieldParams['index'] = 'ZCTextIndex, lexicon_id=' \
|
self.fieldParams['index'] = 'ZCTextIndex, lexicon_id=' \
|
||||||
'plone_lexicon, index_type=Okapi BM25 Rank'
|
'plone_lexicon, index_type=Okapi BM25 Rank'
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -124,6 +124,8 @@ class Generator(AbstractGenerator):
|
||||||
msg('search_new', '', msg.SEARCH_NEW),
|
msg('search_new', '', msg.SEARCH_NEW),
|
||||||
msg('search_from', '', msg.SEARCH_FROM),
|
msg('search_from', '', msg.SEARCH_FROM),
|
||||||
msg('search_to', '', msg.SEARCH_TO),
|
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('ref_invalid_index', '', msg.REF_INVALID_INDEX),
|
||||||
msg('bad_int', '', msg.BAD_INT),
|
msg('bad_int', '', msg.BAD_INT),
|
||||||
msg('bad_float', '', msg.BAD_FLOAT),
|
msg('bad_float', '', msg.BAD_FLOAT),
|
||||||
|
|
|
@ -443,6 +443,7 @@ class ToolMixin(AbstractMixin):
|
||||||
# given field.
|
# given field.
|
||||||
attrValue = rq.form[attrName]
|
attrValue = rq.form[attrName]
|
||||||
if attrName.find('*') != -1:
|
if attrName.find('*') != -1:
|
||||||
|
# The type of the value is encoded after char "*".
|
||||||
attrName, attrType = attrName.split('*')
|
attrName, attrType = attrName.split('*')
|
||||||
if attrType == 'bool':
|
if attrType == 'bool':
|
||||||
exec 'attrValue = %s' % attrValue
|
exec 'attrValue = %s' % attrValue
|
||||||
|
@ -471,7 +472,12 @@ class ToolMixin(AbstractMixin):
|
||||||
toDate = self._getDateTime(year, month, day, False)
|
toDate = self._getDateTime(year, month, day, False)
|
||||||
attrValue = (fromDate, toDate)
|
attrValue = (fromDate, toDate)
|
||||||
if isinstance(attrValue, list):
|
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
|
criteria[attrName[2:]] = attrValue
|
||||||
rq.SESSION['searchCriteria'] = criteria
|
rq.SESSION['searchCriteria'] = criteria
|
||||||
# Goto the screen that displays search results
|
# Goto the screen that displays search results
|
||||||
|
|
|
@ -28,8 +28,19 @@
|
||||||
<tal:simpleSearch condition="not: appyType/isSelect">
|
<tal:simpleSearch condition="not: appyType/isSelect">
|
||||||
<input type="text" tal:attributes="name widgetName"/>
|
<input type="text" tal:attributes="name widgetName"/>
|
||||||
</tal:simpleSearch>
|
</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: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">
|
<select tal:attributes="name widgetName" multiple="multiple" size="5">
|
||||||
<option tal:repeat="v python:tool.getSelectValues(appyType)"
|
<option tal:repeat="v python:tool.getSelectValues(appyType)"
|
||||||
tal:attributes="value python:v[0]" tal:content="python: v[1]">
|
tal:attributes="value python:v[0]" tal:content="python: v[1]">
|
||||||
|
|
|
@ -65,6 +65,8 @@ class PoMessage:
|
||||||
SEARCH_NEW = 'New search'
|
SEARCH_NEW = 'New search'
|
||||||
SEARCH_FROM = 'From'
|
SEARCH_FROM = 'From'
|
||||||
SEARCH_TO = 'to'
|
SEARCH_TO = 'to'
|
||||||
|
SEARCH_OR = 'or'
|
||||||
|
SEARCH_AND = 'and'
|
||||||
WORKFLOW_COMMENT = 'Optional comment'
|
WORKFLOW_COMMENT = 'Optional comment'
|
||||||
WORKFLOW_STATE = 'state'
|
WORKFLOW_STATE = 'state'
|
||||||
DATA_CHANGE = 'Data change'
|
DATA_CHANGE = 'Data change'
|
||||||
|
|
Loading…
Reference in a new issue