Bugfix in the search engine, implemented float fields in the advanced search, execute batchjobs as Zope admin.

This commit is contained in:
Gaetan Delannay 2010-01-14 17:54:18 +01:00
parent d192496c88
commit bdc7baf25a
5 changed files with 61 additions and 36 deletions

View file

@ -176,17 +176,22 @@ class ToolMixin(AbstractMixin):
v = fieldValue[:-1]
params[attrName] = {'query':(v,v+'Z'), 'range':'minmax'}
elif type(fieldValue) in sequenceTypes:
# We have a range of values instead of a single value
minv, maxv = fieldValue
rangev = 'minmax'
queryv = fieldValue
if minv == None:
rangev = 'max'
queryv = maxv
elif maxv == None:
rangev = 'min'
queryv = minv
params[attrName] = {'query':queryv, 'range':rangev}
if fieldValue and isinstance(fieldValue[0], basestring):
# We have a list of string values (ie: we need to
# search v1 or v2 or...)
params[attrName] = fieldValue
else:
# We have a range of (int, float, DateTime...) values
minv, maxv = fieldValue
rangev = 'minmax'
queryv = fieldValue
if minv == None:
rangev = 'max'
queryv = maxv
elif maxv == None:
rangev = 'min'
queryv = minv
params[attrName] = {'query':queryv, 'range':rangev}
else:
params[attrName] = fieldValue
# Add a sort order if specified
@ -405,9 +410,9 @@ class ToolMixin(AbstractMixin):
'''Returns True if request value in key p_key can be considered as
empty.'''
rq = self.REQUEST.form
if key.endswith('*int'):
if key.endswith('*int') or key.endswith('*float'):
# We return True if "from" AND "to" values are empty.
toKey = '%s_to' % key[2:-4]
toKey = '%s_to' % key[2:key.find('*')]
return not rq[key].strip() and not rq[toKey].strip()
elif key.endswith('*date'):
# We return True if "from" AND "to" values are empty. A value is
@ -459,14 +464,16 @@ class ToolMixin(AbstractMixin):
attrName, attrType = attrName.split('*')
if attrType == 'bool':
exec 'attrValue = %s' % attrValue
elif attrType == 'int':
elif attrType in ('int', 'float'):
# Get the "from" value
if not attrValue.strip(): attrValue = None
else: attrValue = int(attrValue)
else:
exec 'attrValue = %s(attrValue)' % attrType
# Get the "to" value
toValue = rq.form['%s_to' % attrName[2:]].strip()
if not toValue: toValue = None
else: toValue = int(toValue)
if not toValue: toValue = None
else:
exec 'toValue = %s(toValue)' % attrType
attrValue = (attrValue, toValue)
elif attrType == 'date':
prefix = attrName[2:]
@ -703,6 +710,6 @@ class ToolMixin(AbstractMixin):
res = []
for v in validator:
text = self.translate('%s_list_%s' % (appyType['label'], v))
res.append((v, self.truncate(text, 50)))
res.append((v, self.truncate(text, 30)))
return res
# ------------------------------------------------------------------------------

View file

@ -11,7 +11,15 @@
</metal:searchInteger>
<metal:searchFloat define-macro="searchFloat">
<p tal:content="fieldName">Hello</p>
<label tal:content="python: tool.translate(appyType['label'])"></label><br>&nbsp;&nbsp;
<tal:from define="fromName python: '%s*float' % widgetName">
<label tal:attributes="for fromName" tal:content="python: tool.translate('search_from')"></label>
<input type="text" tal:attributes="name fromName" size="4"/>
</tal:from>
<tal:to define="toName python: '%s_to' % fieldName">
<label tal:attributes="for toName" tal:content="python: tool.translate('search_to')"></label>
<input type="text" tal:attributes="name toName" size="4"/>
</tal:to><br/>
</metal:searchFloat>
<metal:searchString define-macro="searchString">

View file

@ -283,7 +283,7 @@ class AbstractWrapper:
maxResults=maxResults, noSecurity=noSecurity)
return [o.appy() for o in res['objects']]
def count(self, klass, **fields):
def count(self, klass, noSecurity=False, **fields):
'''Identical to m_search above, but returns the number of objects that
match the search instead of returning the objects themselves. Use
this method instead of writing len(self.search(...)).'''
@ -291,7 +291,7 @@ class AbstractWrapper:
contentType = flavour.o.getPortalType(klass)
search = Search('customSearch', **fields)
res = self.tool.o.executeQuery(contentType,flavour.number,search=search,
brainsOnly=True)
brainsOnly=True, noSecurity=noSecurity)
if res: return res._len # It is a LazyMap instance
else: return 0