예제 #1
0
 def new(self, item):
     counter = 0
     for dontcare, child in item.ZopeFind(item, search_sub=1):
         if ICheckedOut.providedBy(child) or ICheckedIn.providedBy(child):
             raise RuntimeError, "Child is marked with ICheckedOut or ICheckedIn"
         if counter > 30:
             raise RuntimeError, "The object contains more than 30 children"
         counter += 1                
     return func(self, item)
예제 #2
0
 def catalog_object(self, obj, uid=None, idxs=None, update_metadata=1, pghandler=None, skip_interface_check=False):
     """If skip_interface_check then only catalog obj if it provides 
     ICheckedOut or ICheckedIn"""
     if not skip_interface_check:
         if not (ICheckedOut.providedBy(obj) or ICheckedIn.providedBy(obj)):
             return
     CatalogTool.catalog_object(
         self, IVersionMetadata(obj), uid, idxs, update_metadata, pghandler
     )
예제 #3
0
 def new(self, item):
     counter = 0
     for dontcare, child in item.ZopeFind(item, search_sub=1):
         if ICheckedOut.providedBy(child) or ICheckedIn.providedBy(child):
             raise RuntimeError, "Child is marked with ICheckedOut or ICheckedIn"
         if counter > 30:
             raise RuntimeError, "The object contains more than 30 children"
         counter += 1
     return func(self, item)
예제 #4
0
 def catalog_object(self,
                    obj,
                    uid=None,
                    idxs=None,
                    update_metadata=1,
                    pghandler=None,
                    skip_interface_check=False):
     """If skip_interface_check then only catalog obj if it provides 
     ICheckedOut or ICheckedIn"""
     if not skip_interface_check:
         if not (ICheckedOut.providedBy(obj) or ICheckedIn.providedBy(obj)):
             return
     CatalogTool.catalog_object(self, IVersionMetadata(obj), uid, idxs,
                                update_metadata, pghandler)
예제 #5
0
 def state(self):
     if ICheckedOut.providedBy(self.context):
         return 'checked_out'
     if ICheckedIn.providedBy(self.context):
         return 'checked_in'
     return None
예제 #6
0
    def start_new_version(self, item):
        if not self.can_start_new_version(item):
            raise RuntimeError, "Cannot start new version for %s" % item.absolute_url()

        notify(BeforeObjectCheckoutEvent(item))

        adapted = IVersionMetadata(item)
        # If ICheckedIn is not provided then item is not yet subject to 
        # versioning.
        if not ICheckedIn.providedBy(item):

            # Rename item. Use deeper API to avoid permission problems.
            original_id = item.id
            newid = '%s-%s' % (item.id, randint(1,1000000))
            parent = item.aq_parent
            item._notifyOfCopyTo(parent, op=1)
            parent._delObject(item.id, suppress_events=False)
            item = aq_base(item)
            item._setId(newid)
            parent._setObject(newid, item, set_owner=0, suppress_events=False)
            item = parent._getOb(newid)

            # Create a VersionFolder with same id as item's original id
            folder = _createObjectByType(
                'VersionFolder', item.aq_parent, original_id, title=item.Title()
            )
            portal_types = getToolByName(item, 'portal_types')
            fti = portal_types.getTypeInfo('VersionFolder')
            fti._finishConstruction(folder)

            # Initialize IVersionMetadata for item, Since it is the first 
            # version it is initialized from itself.
            IVersionMetadata(item).initialize(item)

            # Add marker interface
            alsoProvides(item, ICheckedIn)

            # Delete item from container
            item._notifyOfCopyTo(folder, op=1)
            item.aq_parent._delObject(item.id, suppress_events=False)
            item = aq_base(item)
            item._setId('%.8d' % IVersionMetadata(item).version)
            folder._setObject(item.id, item, set_owner=0, suppress_events=False)

            item = folder._getOb(item.id)

            # Catalog item
            vc = getToolByName(item, 'upfront_versioning_catalog')
            vc.reindexObject(item)
            pc = getToolByName(item, 'portal_catalog')
            pc.reindexObject(item)

        # Create a sibling for item. The id is computed by incrementing
        # the version stored in the IVersionMetadata adapted item.
        item._notifyOfCopyTo(item.aq_parent, op=0)
        copy = item._getCopy(item.aq_parent)
        # Initialize IVersionMetadata for this copy. This provides a new 
        # version number.
        IVersionMetadata(copy).initialize(item)
        copy._setId('%.8d' % IVersionMetadata(copy).version)
        item.aq_parent._setObject(copy.id, copy, set_owner=1, suppress_events=False)
        copy = item.aq_parent._getOb(copy.id)

        # Put copy and children initial state. We may want to make this 
        # configurable?
        for dontcare, child in [(copy.id, copy)] + copy.ZopeFind(copy, search_sub=1):
            child.notifyWorkflowCreated()

        # Toggle marker interfaces
        if ICheckedIn.providedBy(copy):
            noLongerProvides(copy, ICheckedIn)
        alsoProvides(copy, ICheckedOut)

        # Reindex to update catalog
        copy.reindexObject()

        # Catalog new version and original
        vc = getToolByName(item, 'upfront_versioning_catalog')
        vc.catalog_object(item, skip_interface_check=True)    
        vc.catalog_object(copy)

        notify(AfterObjectCheckoutEvent(copy, item))

        return copy
예제 #7
0
 def state(self):
     if ICheckedOut.providedBy(self.context):
         return 'checked_out'
     if ICheckedIn.providedBy(self.context):
         return 'checked_in'
     return None
예제 #8
0
    def start_new_version(self, item):
        if not self.can_start_new_version(item):
            raise RuntimeError, "Cannot start new version for %s" % item.absolute_url(
            )

        notify(BeforeObjectCheckoutEvent(item))

        adapted = IVersionMetadata(item)
        # If ICheckedIn is not provided then item is not yet subject to
        # versioning.
        if not ICheckedIn.providedBy(item):

            # Rename item. Use deeper API to avoid permission problems.
            original_id = item.id
            newid = '%s-%s' % (item.id, randint(1, 1000000))
            parent = item.aq_parent
            item._notifyOfCopyTo(parent, op=1)
            parent._delObject(item.id, suppress_events=False)
            item = aq_base(item)
            item._setId(newid)
            parent._setObject(newid, item, set_owner=0, suppress_events=False)
            item = parent._getOb(newid)

            # Create a VersionFolder with same id as item's original id
            folder = _createObjectByType('VersionFolder',
                                         item.aq_parent,
                                         original_id,
                                         title=item.Title())
            portal_types = getToolByName(item, 'portal_types')
            fti = portal_types.getTypeInfo('VersionFolder')
            fti._finishConstruction(folder)

            # Initialize IVersionMetadata for item, Since it is the first
            # version it is initialized from itself.
            IVersionMetadata(item).initialize(item)

            # Add marker interface
            alsoProvides(item, ICheckedIn)

            # Delete item from container
            item._notifyOfCopyTo(folder, op=1)
            item.aq_parent._delObject(item.id, suppress_events=False)
            item = aq_base(item)
            item._setId('%.8d' % IVersionMetadata(item).version)
            folder._setObject(item.id,
                              item,
                              set_owner=0,
                              suppress_events=False)

            item = folder._getOb(item.id)

            # Catalog item
            vc = getToolByName(item, 'upfront_versioning_catalog')
            vc.reindexObject(item)
            pc = getToolByName(item, 'portal_catalog')
            pc.reindexObject(item)

        # Create a sibling for item. The id is computed by incrementing
        # the version stored in the IVersionMetadata adapted item.
        item._notifyOfCopyTo(item.aq_parent, op=0)
        copy = item._getCopy(item.aq_parent)
        # Initialize IVersionMetadata for this copy. This provides a new
        # version number.
        IVersionMetadata(copy).initialize(item)
        copy._setId('%.8d' % IVersionMetadata(copy).version)
        item.aq_parent._setObject(copy.id,
                                  copy,
                                  set_owner=1,
                                  suppress_events=False)
        copy = item.aq_parent._getOb(copy.id)

        # Put copy and children initial state. We may want to make this
        # configurable?
        for dontcare, child in [(copy.id, copy)] + copy.ZopeFind(copy,
                                                                 search_sub=1):
            child.notifyWorkflowCreated()

        # Toggle marker interfaces
        if ICheckedIn.providedBy(copy):
            noLongerProvides(copy, ICheckedIn)
        alsoProvides(copy, ICheckedOut)

        # Reindex to update catalog
        copy.reindexObject()

        # Catalog new version and original
        vc = getToolByName(item, 'upfront_versioning_catalog')
        vc.catalog_object(item, skip_interface_check=True)
        vc.catalog_object(copy)

        notify(AfterObjectCheckoutEvent(copy, item))

        return copy
예제 #9
0
 def getVersionsOf(self, obj):
     """Return all versions of object identified by token"""
     if not (ICheckedOut.providedBy(obj) or ICheckedIn.providedBy(obj)):
         return []
     return self(token=IVersionMetadata(obj).token)
예제 #10
0
 def getVersionsOf(self, obj):
     """Return all versions of object identified by token"""
     if not (ICheckedOut.providedBy(obj) or ICheckedIn.providedBy(obj)):
         return []
     return self(token=IVersionMetadata(obj).token)