Added backup/restore scripts (wrappers around repozo). The backup script has the possibility to execute a tool method on a Appy application.

This commit is contained in:
Gaetan Delannay 2010-01-12 21:15:14 +01:00
parent 500637eb53
commit db8ad18c5f
6 changed files with 508 additions and 10 deletions

View file

@ -108,7 +108,7 @@ class ToolMixin(AbstractMixin):
_sortFields = {'title': 'sortable_title'}
def executeQuery(self, contentType, flavourNumber=1, searchName=None,
startNumber=0, search=None, remember=False,
brainsOnly=False, maxResults=None):
brainsOnly=False, maxResults=None, noSecurity=False):
'''Executes a query on a given p_contentType (or several, separated
with commas) in Plone's portal_catalog. Portal types are from the
flavour numbered p_flavourNumber. If p_searchName is specified, it
@ -134,7 +134,10 @@ class ToolMixin(AbstractMixin):
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_brainsOnly is True.
If p_noSecurity is True, it gets all the objects, even those that the
currently logged user can't see.'''
# Is there one or several content types ?
if contentType.find(',') != -1:
# Several content types are specified
@ -194,11 +197,14 @@ class ToolMixin(AbstractMixin):
# (for searchability) and can't be used for sorting.
if self._sortFields.has_key(sb): sb = self._sortFields[sb]
params['sort_on'] = sb
brains = self.portal_catalog.searchResults(**params)
# Determine what method to call on the portal catalog
if noSecurity: catalogMethod = 'unrestrictedSearchResults'
else: catalogMethod = 'searchResults'
exec 'brains = self.portal_catalog.%s(**params)' % catalogMethod
if brainsOnly: return brains
if not maxResults: maxResults = self.getNumberOfResultsPerPage()
elif maxResults == 'NO_LIMIT': maxResults = None
res = SomeObjects(brains, maxResults, startNumber)
res = SomeObjects(brains, maxResults, startNumber,noSecurity=noSecurity)
res.brainsToObjects()
# In some cases (p_remember=True), we need to keep some information
# about the query results in the current user's session, allowing him

View file

@ -262,12 +262,14 @@ class AbstractWrapper:
replaced with normal chars.'''
return unicodedata.normalize('NFKD', s).encode("ascii","ignore")
def search(self, klass, sortBy='', maxResults=None, **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
field. You can optionally specify a maximum number of results in
p_maxResults.'''
p_maxResults. If p_noSecurity is specified, you get all objects,
even if the logged user does not have the permission to view it.'''
# Find the content type corresponding to p_klass
flavour = self.flavour
contentType = flavour.o.getPortalType(klass)
@ -278,7 +280,7 @@ class AbstractWrapper:
# If I let maxResults=None, only a subset of the results will be
# returned by method executeResult.
res = self.tool.o.executeQuery(contentType,flavour.number,search=search,
maxResults=maxResults)
maxResults=maxResults, noSecurity=noSecurity)
return [o.appy() for o in res['objects']]
def count(self, klass, **fields):