More search possibilities.
This commit is contained in:
parent
36c4ce5f77
commit
37c252c3fd
|
@ -450,7 +450,7 @@ class Info(Type):
|
||||||
'''An info is a field whose purpose is to present information
|
'''An info is a field whose purpose is to present information
|
||||||
(text, html...) to the user.'''
|
(text, html...) to the user.'''
|
||||||
def __init__(self, validator=None, multiplicity=(1,1), index=None,
|
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,
|
page='main', group=None, move=0, indexed=False,
|
||||||
searchable=False, specificReadPermission=False,
|
searchable=False, specificReadPermission=False,
|
||||||
specificWritePermission=False, width=None, height=None,
|
specificWritePermission=False, width=None, height=None,
|
||||||
|
|
|
@ -133,8 +133,7 @@ class ToolMixin(AbstractMixin):
|
||||||
needing to get information about them). If no p_maxResults is
|
needing to get information about them). If no p_maxResults is
|
||||||
specified, the method returns maximum
|
specified, the method returns maximum
|
||||||
self.getNumberOfResultsPerPage(). The method returns all objects if
|
self.getNumberOfResultsPerPage(). The method returns all objects if
|
||||||
p_maxResults equals string "NO_LIMIT". p_maxResults is ignored if
|
p_maxResults equals string "NO_LIMIT".
|
||||||
p_brainsOnly is True.
|
|
||||||
|
|
||||||
If p_noSecurity is True, it gets all the objects, even those that the
|
If p_noSecurity is True, it gets all the objects, even those that the
|
||||||
currently logged user can't see.'''
|
currently logged user can't see.'''
|
||||||
|
@ -206,7 +205,10 @@ class ToolMixin(AbstractMixin):
|
||||||
if noSecurity: catalogMethod = 'unrestrictedSearchResults'
|
if noSecurity: catalogMethod = 'unrestrictedSearchResults'
|
||||||
else: catalogMethod = 'searchResults'
|
else: catalogMethod = 'searchResults'
|
||||||
exec 'brains = self.portal_catalog.%s(**params)' % catalogMethod
|
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()
|
if not maxResults: maxResults = self.getNumberOfResultsPerPage()
|
||||||
elif maxResults == 'NO_LIMIT': maxResults = None
|
elif maxResults == 'NO_LIMIT': maxResults = None
|
||||||
res = SomeObjects(brains, maxResults, startNumber,noSecurity=noSecurity)
|
res = SomeObjects(brains, maxResults, startNumber,noSecurity=noSecurity)
|
||||||
|
@ -570,8 +572,14 @@ class ToolMixin(AbstractMixin):
|
||||||
# Compute the label of the search, or ref field
|
# Compute the label of the search, or ref field
|
||||||
if t == 'search':
|
if t == 'search':
|
||||||
searchName = d2
|
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:
|
else:
|
||||||
|
# This is a named, predefined search.
|
||||||
label = '%s_search_%s' % (d1.split(':')[0], searchName)
|
label = '%s_search_%s' % (d1.split(':')[0], searchName)
|
||||||
res['backText'] = self.translate(label)
|
res['backText'] = self.translate(label)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -269,8 +269,8 @@ class AbstractWrapper:
|
||||||
s = res
|
s = res
|
||||||
return unicodedata.normalize('NFKD', s).encode("ascii","ignore")
|
return unicodedata.normalize('NFKD', s).encode("ascii","ignore")
|
||||||
|
|
||||||
def search(self, klass, sortBy='', maxResults=None,
|
def search(self, klass, sortBy='', maxResults=None, noSecurity=False,
|
||||||
noSecurity=False, **fields):
|
**fields):
|
||||||
'''Searches objects of p_klass. p_sortBy must be the name of an indexed
|
'''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
|
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
|
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
|
if res: return res._len # It is a LazyMap instance
|
||||||
else: return 0
|
else: return 0
|
||||||
|
|
||||||
def compute(self, klass, context=None, expression=None, noSecurity=False,
|
def compute(self, klass, sortBy='', maxResults=None, context=None,
|
||||||
**fields):
|
expression=None, noSecurity=False, **fields):
|
||||||
'''This method, like m_search and m_count above, performs a query on
|
'''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
|
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),
|
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 currently walked object, instance of p_klass, and "ctx",
|
||||||
which is the context as initialized (or not) by p_context. p_context
|
which is the context as initialized (or not) by p_context. p_context
|
||||||
may be used as
|
may be used as
|
||||||
(1) a variable that is updated on every call to produce a result;
|
(1) a variable or instance that is updated on every call to
|
||||||
(2) an input variable;
|
produce a result;
|
||||||
|
(2) an input variable or instance;
|
||||||
(3) both.
|
(3) both.
|
||||||
|
|
||||||
The method returns p_context, modified or not by evaluation of
|
The method returns p_context, modified or not by evaluation of
|
||||||
|
@ -328,11 +329,12 @@ class AbstractWrapper:
|
||||||
'''
|
'''
|
||||||
flavour = self.flavour
|
flavour = self.flavour
|
||||||
contentType = flavour.o.getPortalType(klass)
|
contentType = flavour.o.getPortalType(klass)
|
||||||
search = Search('customSearch', **fields)
|
search = Search('customSearch', sortBy=sortBy, **fields)
|
||||||
# Initialize the context variable "ctx"
|
# Initialize the context variable "ctx"
|
||||||
ctx = context
|
ctx = context
|
||||||
for brain in self.tool.o.executeQuery(contentType, flavour.number, \
|
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
|
# Get the Appy object from the brain
|
||||||
obj = brain.getObject().appy()
|
obj = brain.getObject().appy()
|
||||||
exec expression
|
exec expression
|
||||||
|
|
Loading…
Reference in a new issue