[gen] Bugfixes in the search engine.
This commit is contained in:
parent
eba86ae6bc
commit
4515eb1f80
|
@ -591,35 +591,36 @@ class ToolMixin(BaseMixin):
|
||||||
rq = self.REQUEST
|
rq = self.REQUEST
|
||||||
# Store the search criteria in the session
|
# Store the search criteria in the session
|
||||||
criteria = self._getDefaultSearchCriteria()
|
criteria = self._getDefaultSearchCriteria()
|
||||||
for attrName in rq.form.keys():
|
for name in rq.form.keys():
|
||||||
if attrName.startswith('w_') and \
|
if name.startswith('w_') and not self._searchValueIsEmpty(name):
|
||||||
not self._searchValueIsEmpty(attrName):
|
hasStar = name.find('*') != -1
|
||||||
field = self.getAppyType(attrName[2:], rq.form['className'])
|
fieldName = not hasStar and name[2:] or name[2:name.find('*')]
|
||||||
if not field.persist: continue
|
field = self.getAppyType(fieldName, rq.form['className'])
|
||||||
|
if field and not field.persist: continue
|
||||||
# We have a(n interval of) value(s) that is not empty for a
|
# We have a(n interval of) value(s) that is not empty for a
|
||||||
# given field.
|
# given field or index.
|
||||||
attrValue = rq.form[attrName]
|
value = rq.form[name]
|
||||||
if attrName.find('*') != -1:
|
if hasStar:
|
||||||
attrValue = attrValue.strip()
|
value = value.strip()
|
||||||
# The type of the value is encoded after char "*".
|
# The type of the value is encoded after char "*".
|
||||||
attrName, attrType = attrName.split('*')
|
name, type = name.split('*')
|
||||||
if attrType == 'bool':
|
if type == 'bool':
|
||||||
exec 'attrValue = %s' % attrValue
|
exec 'value = %s' % value
|
||||||
elif attrType in ('int', 'float'):
|
elif type in ('int', 'float'):
|
||||||
# Get the "from" value
|
# Get the "from" value
|
||||||
if not attrValue: attrValue = None
|
if not value: value = None
|
||||||
else:
|
else:
|
||||||
exec 'attrValue = %s(attrValue)' % attrType
|
exec 'value = %s(value)' % type
|
||||||
# Get the "to" value
|
# Get the "to" value
|
||||||
toValue = rq.form['%s_to' % attrName[2:]].strip()
|
toValue = rq.form['%s_to' % name[2:]].strip()
|
||||||
if not toValue: toValue = None
|
if not toValue: toValue = None
|
||||||
else:
|
else:
|
||||||
exec 'toValue = %s(toValue)' % attrType
|
exec 'toValue = %s(toValue)' % type
|
||||||
attrValue = (attrValue, toValue)
|
value = (value, toValue)
|
||||||
elif attrType == 'date':
|
elif type == 'date':
|
||||||
prefix = attrName[2:]
|
prefix = name[2:]
|
||||||
# Get the "from" value
|
# Get the "from" value
|
||||||
year = attrValue
|
year = value
|
||||||
month = rq.form['%s_from_month' % prefix]
|
month = rq.form['%s_from_month' % prefix]
|
||||||
day = rq.form['%s_from_day' % prefix]
|
day = rq.form['%s_from_day' % prefix]
|
||||||
fromDate = self._getDateTime(year, month, day, True)
|
fromDate = self._getDateTime(year, month, day, True)
|
||||||
|
@ -628,23 +629,23 @@ class ToolMixin(BaseMixin):
|
||||||
month = rq.form['%s_to_month' % prefix]
|
month = rq.form['%s_to_month' % prefix]
|
||||||
day = rq.form['%s_to_day' % prefix]
|
day = rq.form['%s_to_day' % prefix]
|
||||||
toDate = self._getDateTime(year, month, day, False)
|
toDate = self._getDateTime(year, month, day, False)
|
||||||
attrValue = (fromDate, toDate)
|
value = (fromDate, toDate)
|
||||||
elif attrType.startswith('string'):
|
elif type.startswith('string'):
|
||||||
# In the case of a string, it could be necessary to
|
# In the case of a string, it could be necessary to
|
||||||
# apply some text transform.
|
# apply some text transform.
|
||||||
if len(attrType) > 6:
|
if len(type) > 6:
|
||||||
transform = attrType.split('-')[1]
|
transform = type.split('-')[1]
|
||||||
if (transform != 'none') and attrValue:
|
if (transform != 'none') and value:
|
||||||
exec 'attrValue = attrValue.%s()' % \
|
exec 'value = value.%s()' % \
|
||||||
self.transformMethods[transform]
|
self.transformMethods[transform]
|
||||||
if isinstance(attrValue, list):
|
if isinstance(value, list):
|
||||||
# It is a list of values. Check if we have an operator for
|
# 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
|
# the field, to see if we make an "and" or "or" for all
|
||||||
# those values. "or" will be the default.
|
# those values. "or" will be the default.
|
||||||
operKey = 'o_%s' % attrName[2:]
|
operKey = 'o_%s' % name[2:]
|
||||||
oper = ' %s ' % rq.form.get(operKey, 'or').upper()
|
oper = ' %s ' % rq.form.get(operKey, 'or').upper()
|
||||||
attrValue = oper.join(attrValue)
|
value = oper.join(value)
|
||||||
criteria[attrName[2:]] = attrValue
|
criteria[name[2:]] = value
|
||||||
# Complete criteria with Ref info if the search is restricted to
|
# Complete criteria with Ref info if the search is restricted to
|
||||||
# referenced objects of a Ref field.
|
# referenced objects of a Ref field.
|
||||||
refInfo = rq.get('ref', None)
|
refInfo = rq.get('ref', None)
|
||||||
|
|
Loading…
Reference in a new issue