More search possibilities.

This commit is contained in:
Gaetan Delannay 2010-02-22 15:28:20 +01:00
parent 36c4ce5f77
commit 37c252c3fd
3 changed files with 23 additions and 13 deletions

View file

@ -450,7 +450,7 @@ class Info(Type):
'''An info is a field whose purpose is to present information
(text, html...) to the user.'''
def __init__(self, validator=None, multiplicity=(1,1), index=None,
default=None, optional=False, editDefault=False, show=True,
default=None, optional=False, editDefault=False, show='view',
page='main', group=None, move=0, indexed=False,
searchable=False, specificReadPermission=False,
specificWritePermission=False, width=None, height=None,

View file

@ -133,8 +133,7 @@ class ToolMixin(AbstractMixin):
needing to get information about them). If no p_maxResults is
specified, the method returns maximum
self.getNumberOfResultsPerPage(). The method returns all objects if
p_maxResults equals string "NO_LIMIT". p_maxResults is ignored if
p_brainsOnly is True.
p_maxResults equals string "NO_LIMIT".
If p_noSecurity is True, it gets all the objects, even those that the
currently logged user can't see.'''
@ -206,7 +205,10 @@ class ToolMixin(AbstractMixin):
if noSecurity: catalogMethod = 'unrestrictedSearchResults'
else: catalogMethod = 'searchResults'
exec 'brains = self.portal_catalog.%s(**params)' % catalogMethod
if brainsOnly: return brains
if brainsOnly:
# Return brains only.
if not maxResults: return brains
else: return brains[:maxResults]
if not maxResults: maxResults = self.getNumberOfResultsPerPage()
elif maxResults == 'NO_LIMIT': maxResults = None
res = SomeObjects(brains, maxResults, startNumber,noSecurity=noSecurity)
@ -570,8 +572,14 @@ class ToolMixin(AbstractMixin):
# Compute the label of the search, or ref field
if t == 'search':
searchName = d2
if searchName == '_advanced': label = 'search_results'
if not searchName:
# We search all objects of a given type.
label = '%s_plural' % d1.split(':')[0]
elif searchName == '_advanced':
# This is an advanced, custom search.
label = 'search_results'
else:
# This is a named, predefined search.
label = '%s_search_%s' % (d1.split(':')[0], searchName)
res['backText'] = self.translate(label)
else:

View file

@ -269,8 +269,8 @@ class AbstractWrapper:
s = res
return unicodedata.normalize('NFKD', s).encode("ascii","ignore")
def search(self, klass, sortBy='', maxResults=None,
noSecurity=False, **fields):
def search(self, klass, sortBy='', maxResults=None, noSecurity=False,
**fields):
'''Searches objects of p_klass. p_sortBy must be the name of an indexed
field (declared with indexed=True); every param in p_fields must
take the name of an indexed field and take a possible value of this
@ -302,8 +302,8 @@ class AbstractWrapper:
if res: return res._len # It is a LazyMap instance
else: return 0
def compute(self, klass, context=None, expression=None, noSecurity=False,
**fields):
def compute(self, klass, sortBy='', maxResults=None, context=None,
expression=None, noSecurity=False, **fields):
'''This method, like m_search and m_count above, performs a query on
objects of p_klass. But in this case, instead of returning a list of
matching objects (like m_search) or counting elements (like p_count),
@ -314,8 +314,9 @@ class AbstractWrapper:
which is the currently walked object, instance of p_klass, and "ctx",
which is the context as initialized (or not) by p_context. p_context
may be used as
(1) a variable that is updated on every call to produce a result;
(2) an input variable;
(1) a variable or instance that is updated on every call to
produce a result;
(2) an input variable or instance;
(3) both.
The method returns p_context, modified or not by evaluation of
@ -328,11 +329,12 @@ class AbstractWrapper:
'''
flavour = self.flavour
contentType = flavour.o.getPortalType(klass)
search = Search('customSearch', **fields)
search = Search('customSearch', sortBy=sortBy, **fields)
# Initialize the context variable "ctx"
ctx = context
for brain in self.tool.o.executeQuery(contentType, flavour.number, \
search=search, brainsOnly=True, noSecurity=noSecurity):
search=search, brainsOnly=True, maxResults=maxResults,
noSecurity=noSecurity):
# Get the Appy object from the brain
obj = brain.getObject().appy()
exec expression