コード例 #1
0
    def test_marker_on_root_delete(self):
        # Here, we create a marker, and check that's it remerber which
        # object it mark. If you delete the marker, mark should
        # disppear on object before.

        factory = self.root.manage_addProduct['silva.core.layout']
        factory.manage_addCustomizationMarker('ITestMarker')
        self.assertTrue('ITestMarker' in self.root.objectIds())
        marker = getattr(self.root, 'ITestMarker')

        # Set the mark on the root
        manager = IMarkManager(self.root)
        manager.add_marker(u'marker:root.ITestMarker')

        # The marker remerbers which object it have marked.
        self.assertEqual(marker.markedObjects(), [self.root,])

        # And the manager confirm that
        manager = IMarkManager(self.root)
        self.assertInterfaceEqual(
            manager.usedMarkers, [u'marker:root.ITestMarker'])

        # Now, I delete the marker before removing from the object.
        self.root.manage_delObjects(['ITestMarker',])

        # And root have been updated
        manager = IMarkManager(self.root)
        self.assertInterfaceEqual(manager.usedMarkers, [])
        self.assertInterfaceEqual(
            manager.availableMarkers,
            ['silva.core.layout.interfaces.ICustomizableMarker',
             'silva.core.views.interfaces.IDisableBreadcrumbTag',
             'silva.core.views.interfaces.IDisableNavigationTag'])
コード例 #2
0
ファイル: makers.py プロジェクト: silvacms/silva.core.smi
    def remove(self):
        values, errors = self.extractData()
        if not values.get("usedMarkers", None):
            self.send_message(_(u"You need to select a marker."), type=u"error")
            return silvaforms.FAILURE

        manager = IMarkManager(self.context)
        for value in values["usedMarkers"]:
            manager.remove_marker(value)
        self.send_message(_(u"Marker removed."), type=u"feedback")
        return silvaforms.SUCCESS
コード例 #3
0
    def test_upgrade_customization_markers(self):
        """Upgrade a document with a marker.
        """
        document = self.root.document
        IMarkManager(document).add_marker(IDisableBreadcrumbTag)
        self.assertEqual(document_upgrader.validate(document), True)
        self.assertNotEqual(document_upgrader.upgrade(document), document)

        upgraded = self.root.document
        self.assertTrue(IDocument.providedBy(upgraded))
        self.assertIn(IDisableBreadcrumbTag, IMarkManager(upgraded).usedMarkers)
コード例 #4
0
    def test_marker_on_root(self):
        manager = IMarkManager(self.root)
        self.assertTrue(verifyObject(IMarkManager, manager))

        # By default, we got interfaces implemented by Root
        self.assertInterfaceEqual(
            manager.usedInterfaces,
            ['silva.core.interfaces.content.IFolder',
             'silva.core.interfaces.content.IPublication',
             'silva.core.interfaces.content.IPublishable',
             'silva.core.interfaces.content.IRoot'])

        # And there is no marker used.
        self.assertInterfaceEqual(manager.usedMarkers, [])
        # The base interfaces for markers is availables however.
        self.assertInterfaceEqual(
            manager.availableMarkers,
            ['silva.core.layout.interfaces.ICustomizableMarker',
             'silva.core.views.interfaces.IDisableBreadcrumbTag',
             'silva.core.views.interfaces.IDisableNavigationTag'])

        # We can add a marker in ZODB
        factory = self.root.manage_addProduct['silva.core.layout']
        factory.manage_addCustomizationMarker('ITestMarker')
        self.assertTrue('ITestMarker' in self.root.objectIds())
        marker = getattr(self.root, 'ITestMarker')

        # A marker is an interface which extend ICustomizableMarker,
        # so it's customizable
        self.assertTrue(verifyObject(IInterface, marker))
        self.assertTrue(marker.extends(ICustomizableMarker))
        self.assertTrue(marker.extends(ICustomizable))

        # Marker have an markerId which gives it's identifier, we
        # should be the same than the interface __identifier__
        self.assertTrue(marker.markerId(), u'marker:root.ITestMarker')
        self.assertTrue(marker.__identifier__, u'marker:root.ITestMarker')

        # Now, we should see our marker in availables ones
        # Since our manager cache it's result, we need to recreate a new one.
        manager = IMarkManager(self.root)
        self.assertInterfaceEqual(
            manager.availableMarkers,
            ['marker:root.ITestMarker',
             'silva.core.layout.interfaces.ICustomizableMarker',
             'silva.core.views.interfaces.IDisableBreadcrumbTag',
             'silva.core.views.interfaces.IDisableNavigationTag'])

        # We can assign a marker to the root
        manager.add_marker(u'marker:root.ITestMarker')

        # And we will have root object which provided this object
        self.assertTrue(marker.providedBy(self.root))

        # And we will see changes in the manager
        manager = IMarkManager(self.root)
        self.assertInterfaceEqual(
            manager.usedMarkers, ['marker:root.ITestMarker'])
        self.assertInterfaceEqual(
            manager.availableMarkers,
            ['silva.core.layout.interfaces.ICustomizableMarker',
             'silva.core.views.interfaces.IDisableBreadcrumbTag',
             'silva.core.views.interfaces.IDisableNavigationTag'])

        # Like we assign the marker, we can remove it.
        manager.remove_marker(u'marker:root.ITestMarker')

        # And it will disppear
        self.failIf(marker.providedBy(self.root))
        manager = IMarkManager(self.root)
        self.assertInterfaceEqual(manager.usedMarkers, [])
        self.assertInterfaceEqual(
            manager.availableMarkers,
            ['marker:root.ITestMarker',
             'silva.core.layout.interfaces.ICustomizableMarker',
             'silva.core.views.interfaces.IDisableBreadcrumbTag',
             'silva.core.views.interfaces.IDisableNavigationTag'])

        # We can delete the marker
        self.root.manage_delObjects(['ITestMarker',])

        # And it won't appear in the manager anymore (it's gone)
        manager = IMarkManager(self.root)
        self.assertInterfaceEqual(manager.usedMarkers, [])
        self.assertInterfaceEqual(
            manager.availableMarkers,
            ['silva.core.layout.interfaces.ICustomizableMarker',
             'silva.core.views.interfaces.IDisableBreadcrumbTag',
             'silva.core.views.interfaces.IDisableNavigationTag'])
コード例 #5
0
    def upgrade(self, doc):
        logger.info(u'Upgrading HTML in: %s.', content_path(doc))
        # ID + Title
        identifier = doc.id
        title = doc.get_title()
        parent = aq_parent(doc)

        # Create a new doccopy the annotation
        try:
            new_doc = self.create_document(
                parent, identifier + 'conv__silva30', title)
        except ValueError:
            logger.error(u'Cannot convert document: %s.', content_path(doc))
            return doc
        new_identifier = new_doc.getId() # The id can have changed
        # Copy annotation
        copy_annotation(doc, new_doc)
        # Move references
        move_references(doc, new_doc)

        # Last closed version
        last_closed_version_id = doc.get_last_closed_version()
        if last_closed_version_id is not None:
            last_closed_version = doc._getOb(last_closed_version_id, None)
            if last_closed_version is not None:
                new_last_closed_version = new_doc.get_editable()
                self.copy_version(
                    last_closed_version, new_last_closed_version, True)
                new_doc.approve_version()
                if new_doc.get_public_version():
                    # The version can already be expired
                    new_doc.close_version()
                new_doc.create_copy()

        # Published version
        public_version = doc.get_viewable()
        if public_version is not None:
            new_public_version = new_doc.get_editable()
            self.copy_version(
                public_version, new_public_version, True)
            new_doc.approve_version()

        # Editable version
        editable_version = doc.get_editable()
        if editable_version is not None:
            if public_version is not None:
                new_doc.create_copy()
            new_editable_version = new_doc.get_editable()
            self.copy_version(
                editable_version, new_editable_version)

        # Markers
        new_mark_mg = IMarkManager(new_doc)
        for marker in IMarkManager(doc).usedMarkers:
            new_mark_mg.add_marker(marker)

        # Delete old document and rename content to final id
        order_mg = IOrderManager(parent)
        position = order_mg.get_position(doc)
        parent.manage_delObjects([identifier])
        try:
            parent.manage_renameObject(new_identifier, identifier)
        except CopyError:
            try:
                parent._checkId(identifier)
            except BadRequest:
                logger.error(
                    u"Could not replace document with '%s' identifier, renaming it to '%s_changed'.",
                    identifier, identifier)
                identifier += '_changed'
                parent.manage_renameObject(new_identifier, identifier)
            else:
                raise
        new_doc = parent[identifier]
        if position > -1:
            order_mg.move(new_doc, position)
        ICataloging(new_doc).reindex()
        return new_doc
コード例 #6
0
    def upgrade(self, doc):
        logger.info('Upgrading HTML in: %s.', content_path(doc))
        # ID + Title
        identifier = doc.id
        title = doc.get_title()
        parent = aq_parent(doc)

        # Create a new doccopy the annotation
        try:
            new_doc = self.create_document(parent,
                                           identifier + 'conv__silva30', title)
        except ValueError:
            logger.error('Cannot convert document: %s.', content_path(doc))
            return doc
        new_identifier = new_doc.getId()  # The id can have changed
        # Copy annotation
        copy_annotation(doc, new_doc)
        # Move references
        move_references(doc, new_doc)

        # Last closed version
        last_closed_version_id = doc.get_last_closed_version()
        if last_closed_version_id is not None:
            last_closed_version = doc._getOb(last_closed_version_id, None)
            if last_closed_version is not None:
                new_last_closed_version = new_doc.get_editable()
                self.copy_version(last_closed_version, new_last_closed_version,
                                  True)
                new_doc.approve_version()
                if new_doc.get_public_version():
                    # The version can already be expired
                    new_doc.close_version()
                new_doc.create_copy()

        # Published version
        public_version = doc.get_viewable()
        if public_version is not None:
            new_public_version = new_doc.get_editable()
            self.copy_version(public_version, new_public_version, True)
            new_doc.approve_version()

        # Editable version
        editable_version = doc.get_editable()
        if editable_version is not None:
            if public_version is not None:
                new_doc.create_copy()
            new_editable_version = new_doc.get_editable()
            self.copy_version(editable_version, new_editable_version)

        # Markers
        new_mark_mg = IMarkManager(new_doc)
        for marker in IMarkManager(doc).usedMarkers:
            new_mark_mg.add_marker(marker)

        # Delete old document and rename content to final id
        order_mg = IOrderManager(parent)
        position = order_mg.get_position(doc)
        parent.manage_delObjects([identifier])
        try:
            parent.manage_renameObject(new_identifier, identifier)
        except CopyError:
            try:
                parent._checkId(identifier)
            except BadRequest:
                logger.error(
                    "Could not replace document with '%s' identifier, renaming it to '%s_changed'.",
                    identifier, identifier)
                identifier += '_changed'
                parent.manage_renameObject(new_identifier, identifier)
            else:
                raise
        new_doc = parent[identifier]
        if position > -1:
            order_mg.move(new_doc, position)
        ICataloging(new_doc).reindex()
        return new_doc