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):

View file

@ -175,7 +175,8 @@ class AppyRequest:
class SomeObjects:
'''Represents a bunch of objects retrieved from a reference or a query in
portal_catalog.'''
def __init__(self, objects=None, batchSize=None, startNumber=0):
def __init__(self, objects=None, batchSize=None, startNumber=0,
noSecurity=False):
self.objects = objects or [] # The objects
self.totalNumber = len(self.objects) # self.objects may only represent a
# part of all available objects.
@ -183,11 +184,16 @@ class SomeObjects:
# self.objects.
self.startNumber = startNumber # The index of first object in
# self.objects in the whole list.
self.noSecurity = noSecurity
def brainsToObjects(self):
'''self.objects has been populated from brains from the portal_catalog,
not from True objects. This method turns them (or some of them
depending on batchSize and startNumber) into real objects.'''
depending on batchSize and startNumber) into real objects.
If self.noSecurity is True, it gets the objects even if the logged
user does not have the right to get them.'''
start = self.startNumber
brains = self.objects[start:start + self.batchSize]
self.objects = [b.getObject() for b in brains]
if self.noSecurity: getMethod = '_unrestrictedGetObject'
else: getMethod = 'getObject'
self.objects = [getattr(b, getMethod)() for b in brains]
# ------------------------------------------------------------------------------