Skip to content

Commit

Permalink
Merge pull request #6 from darryldixon/master
Browse files Browse the repository at this point in the history
Fix for string formatting error in Repository.py
  • Loading branch information
mauritsvanrees committed Feb 12, 2020
2 parents 21c9a4d + c4884aa commit b31ee64
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/Products/ZopeVersionControl/Repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def replaceState(self, obj, new_state):
if obj.__class__ is not new_state.__class__:
raise VersionControlError(
"The class of the versioned object has changed. %s != %s"
% (repr(obj.__class__, new_state.__class__)))
% (repr(obj.__class__), repr(new_state.__class__)))
obj._p_changed = 1
for key in list(obj.__dict__.keys()):
if not key in new_state.__dict__:
Expand All @@ -100,7 +100,11 @@ def isAVersionableResource(self, obj):

security.declarePublic('isUnderVersionControl')
def isUnderVersionControl(self, object):
return hasattr(object, '__vc_info__')
info = getattr(object, '__vc_info__', None)
if info is None:
return False
return info.history_id in self._histories and \
self._histories[info.history_id].hasVersionId(info.version_id)

security.declarePublic('isResourceUpToDate')
def isResourceUpToDate(self, object, require_branch=0):
Expand Down
20 changes: 19 additions & 1 deletion src/Products/ZopeVersionControl/nonversioned.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ def getNonVersionedData(self):
# subobjects that are references.
continue
contents[name] = aq_base(value)
return {'contents': contents, 'attributes': attributes}
order = []
if getattr(self.obj, '_objects', False):
order = [x['id'] for x in self.obj._objects]
return {'contents': contents, 'attributes': attributes, 'order': order}

def restoreNonVersionedData(self, data):
StandardNonVersionedDataAdapter.restoreNonVersionedData(
Expand All @@ -163,3 +166,18 @@ def restoreNonVersionedData(self, data):
# a BTreeFolder2, which doesn't need or want the
# _objects attribute.
# XXX This is a hackish way to check for BTreeFolder2s.
# Yes, we're repeating ourselves:
if not hasattr(obj, '_tree'):
for id in data.get('order', []):
try:
obj.moveObject(id, data['order'].index(id))
except AttributeError as e:
# maybe obj doesn't support .moveObject?
pass
except ValueError as e:
# item 'id' doesn't exist in obj?
pass
except Exception as e:
# Just bail, it's not worth failing on...
pass

0 comments on commit b31ee64

Please sign in to comment.