diff --git a/src/Products/ZopeVersionControl/Repository.py b/src/Products/ZopeVersionControl/Repository.py index b491a9a..e095d19 100644 --- a/src/Products/ZopeVersionControl/Repository.py +++ b/src/Products/ZopeVersionControl/Repository.py @@ -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__: @@ -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): diff --git a/src/Products/ZopeVersionControl/nonversioned.py b/src/Products/ZopeVersionControl/nonversioned.py index 71e8439..ac0ce9b 100644 --- a/src/Products/ZopeVersionControl/nonversioned.py +++ b/src/Products/ZopeVersionControl/nonversioned.py @@ -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( @@ -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 +