Пример #1
0
def registerPortletType(site, title, description, addview, for_=[Interface]):
    """Register a new type of portlet.

    site should be the local site where the registration should be made. The
    title and description should be meaningful metadata about the portlet for
    the UI.

    The addview should be the name of an add view registered, and must be
    unique.
    """
    sm = getSiteManager(site)

    portlet = PortletType()
    portlet.title = title
    portlet.description = description
    portlet.addview = addview
    portlet.for_ = for_

    sm.registerUtility(component=portlet, provided=IPortletType, name=addview)
Пример #2
0
    def _initPortletNode(self, node):
        """Create a portlet type from a node
        """
        registeredPortletTypes = [
          r.name for r in self.context.registeredUtilities() \
                          if r.provided == IPortletType]

        addview = str(node.getAttribute('addview'))
        extend = node.hasAttribute('extend')
        purge = node.hasAttribute('purge')

        #In certain cases, continue to the next node
        if node.hasAttribute('remove'):
            self._removePortlet(name=addview)
            return
        if self._checkBasicPortletNodeErrors(node, registeredPortletTypes):
            return

        #Retrieve or create the portlet type and determine the current list
        #of associated portlet manager interfaces (for_)
        if extend:
            #To extend a portlet type that is registered, we modify the title
            #and description if provided by the profile.
            portlet = queryUtility(IPortletType, name = addview)
            if str(node.getAttribute('title')):
                portlet.title = str(node.getAttribute('title'))
            if str(node.getAttribute('description')):
                portlet.description = str(node.getAttribute('description'))
            for_ = portlet.for_
            if for_ is None:
                for_ = []
        else:
            #Otherwise, create a new portlet type with the correct attributes.
            portlet = PortletType()
            portlet.title = str(node.getAttribute('title'))
            portlet.description = str(node.getAttribute('description'))
            portlet.addview = addview
            for_ = []


        #Process the node's child "for" nodes to add or remove portlet
        #manager interface names to the for_ list
        for_ = self._modifyForList(node, for_)

        #Store the for_ attribute, with [IDefaultPortletManager] as the default
        if for_ == []:
            for_ = [IDefaultPortletManager]
        portlet.for_ = for_

        if purge:
            self._removePortlet(addview)
        if not extend:
            self.context.registerUtility(component=portlet,
                                         provided=IPortletType,
                                         name=addview)
Пример #3
0
def registerPortletType(site, title, description, addview, for_=[Interface]):
    """Register a new type of portlet.

    site should be the local site where the registration should be made. The
    title and description should be meaningful metadata about the portlet for
    the UI.

    The addview should be the name of an add view registered, and must be
    unique.
    """
    sm = getSiteManager(site)

    portlet = PortletType()
    portlet.title = title
    portlet.description = description
    portlet.addview = addview
    portlet.for_ = for_

    sm.registerUtility(component=portlet, provided=IPortletType, name=addview)
Пример #4
0
def portletsSetUp(test):
    sectionsSetUp(test)

    from zope.interface import Interface
    from zope.annotation.interfaces import IAttributeAnnotatable
    from plone.portlets.interfaces import ILocalPortletAssignable

    # this bases class adds __of__ method
    from Acquisition import Implicit

    class MockPortal(Implicit):
        implements(IAttributeAnnotatable, ILocalPortletAssignable)

        _last_path = None
        def unrestrictedTraverse(self, path, default):
            if path[0] == '/':
                return default # path is absolute
            if isinstance(path, unicode):
                return default
            if path == 'not/existing/bar':
                return default
            if path.endswith('/notassignable'):
                return object()
            self._last_path = path
            return self

        def getPhysicalPath(self):
            return [''] + self._last_path.split('/')

    portal = MockPortal()
    test.globs['plone'] = portal
    test.globs['transmogrifier'].context = test.globs['plone']

    class PortletsSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(PortletsSource, self).__init__(*args, **kw)
            self.sample = (
                dict(),
                dict(_path='not/existing/bar'),
                dict(_path='spam/eggs/notassignable'),
                dict(_path='assignable'),
                dict(_path='other-assignable', 
                    files=dict(portlets=dict(
                        name='.portlets.xml',
                        data="""<?xml version="1.0" encoding="utf-8"?>
<portlets>
  <assignment category="context" key="/other-assignable" manager="plone.leftcolumn" name="habra-rss" type="portlets.rss">
    <property name="count">
      20
    </property>
    <property name="url">
      http://habrahabr.ru/rss/
    </property>
    <property name="portlet_title">
      Habrahabr RSS feed
    </property>
    <property name="timeout">
      120
    </property>
  </assignment>
  <blacklist category="user" manager="plone.leftcolumn" status="block"/>
  <blacklist category="group" manager="plone.leftcolumn" status="acquire"/>
  <blacklist category="content_type" manager="plone.leftcolumn" status="acquire"/>
  <blacklist category="context" manager="plone.leftcolumn" status="acquire"/>
</portlets>
""")
                    )
                )
            )

    provideUtility(PortletsSource,
        name=u'quintagroup.transmogrifier.tests.portletssource')

    class PortletsSource2(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(PortletsSource2, self).__init__(*args, **kw)
            self.sample = (
                dict(),
                dict(_path='other-assignable',
                    files=dict(portlets=dict(
                        name='.portlets.xml',
                        data="""<?xml version="1.0" encoding="utf-8"?>
<portlets>
  <assignment category="context" key="/other-assignable" manager="plone.leftcolumn" name="sumno-rss-2" type="portlets.rss">
    <property name="count">
      30
    </property>
    <property name="url">
      http://sumno.com/rss
    </property>
    <property name="portlet_title">
      Sumno RSS feed
    </property>
    <property name="timeout">
      360
    </property>
  </assignment>
  <blacklist category="user" manager="plone.leftcolumn" status="block"/>
  <blacklist category="group" manager="plone.leftcolumn" status="acquire"/>
  <blacklist category="content_type" manager="plone.leftcolumn" status="acquire"/>
  <blacklist category="context" manager="plone.leftcolumn" status="acquire"/>
</portlets>
""")
                    )
                )
            )
    provideUtility(PortletsSource2,
       name=u'quintagroup.transmogrifier.tests.portletssource2')

    # prepare the one portlet for testing
    from zope.interface import alsoProvides
    from zope.component import getUtility, getMultiAdapter
    from zope.component.interfaces import IFactory
    from zope.component.factory import Factory

    from plone.portlets.manager import PortletManager
    from plone.portlets.interfaces import IPortletManager, IPortletType, \
        IPortletAssignmentMapping
    from plone.portlets.registration import PortletType

    from plone.app.portlets.assignable import localPortletAssignmentMappingAdapter
    from plone.portlets.assignable import LocalPortletAssignmentManager
    from plone.app.portlets.interfaces import IPortletTypeInterface
    from plone.portlets.interfaces import  ILocalPortletAssignmentManager
    from plone.portlets.constants import USER_CATEGORY
    # from plone.app.portlets.browser.interfaces import IPortletAdding
    from plone.app.portlets.portlets.rss import IRSSPortlet, Assignment #, Renderer, AddForm, EditForm

    # register portlet manager and assignment mapping adapter
    manager = PortletManager()
    provideUtility(manager, IPortletManager, name='plone.leftcolumn')
    provideAdapter(localPortletAssignmentMappingAdapter)
    provideAdapter(LocalPortletAssignmentManager)
    mapping = getMultiAdapter((portal, manager), IPortletAssignmentMapping)
    assignable = getMultiAdapter((portal, manager), ILocalPortletAssignmentManager)
    test.globs['mapping'] = mapping
    test.globs['assignable'] = assignable

    # register portlet (this is what plone:portlet zcml directive does)
    PORTLET_NAME = 'portlets.rss'
    alsoProvides(IRSSPortlet, IPortletTypeInterface)
    provideUtility(provides=IPortletTypeInterface, name=PORTLET_NAME, component=IRSSPortlet)
    provideUtility(provides=IFactory, name=PORTLET_NAME, component=Factory(Assignment))

    # register a portlet type (this is what <portlet /> element in portlets.xml
    # does)
    portlet = PortletType()
    portlet.title = 'RSS Feed'
    portlet.description = 'A portlet which can receive and render an RSS feed.'
    portlet.addview = PORTLET_NAME
    portlet.for_ = [Interface]
    provideUtility(component=portlet, provides=IPortletType, 
        name=PORTLET_NAME)

    # add a portlet and configure it (this is done on @@manage-portlets view)
    assignment = getUtility(IFactory, name=PORTLET_NAME)()
    mapping['rss'] = assignment
    portlet_interface = getUtility(IPortletTypeInterface, name=PORTLET_NAME)
    data = {
        'portlet_title': u'RSS feed',
        'count': 10,
        'url': u'http://sumno.com/feeds/main-page/',
        'timeout': 60
    }
    for k, v in data.items():
        field = portlet_interface.get(k)
        field = field.bind(assignment)
        field.validate(v)
        field.set(assignment, v)
    # set blacklists for user category to 'block'
    assignable.setBlacklistStatus(USER_CATEGORY, True)
def portletsSetUp(test):
    sectionsSetUp(test)

    from zope.interface import Interface
    from zope.annotation.interfaces import IAttributeAnnotatable
    from plone.portlets.interfaces import ILocalPortletAssignable

    # this bases class adds __of__ method
    from Acquisition import Implicit

    class MockPortal(Implicit):
        implements(IAttributeAnnotatable, ILocalPortletAssignable)

        _last_path = None
        def unrestrictedTraverse(self, path, default):
            if path[0] == '/':
                return default # path is absolute
            if isinstance(path, unicode):
                return default
            if path == 'not/existing/bar':
                return default
            if path.endswith('/notassignable'):
                return object()
            self._last_path = path
            return self

        def getPhysicalPath(self):
            return [''] + self._last_path.split('/')

    portal = MockPortal()
    test.globs['plone'] = portal
    test.globs['transmogrifier'].context = test.globs['plone']

    class PortletsSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(PortletsSource, self).__init__(*args, **kw)
            self.sample = (
                dict(),
                dict(_path='not/existing/bar'),
                dict(_path='spam/eggs/notassignable'),
                dict(_path='assignable'),
                dict(_path='other-assignable', 
                    files=dict(portlets=dict(
                        name='.portlets.xml',
                        data="""<?xml version="1.0" encoding="utf-8"?>
<portlets>
  <assignment category="context" key="/other-assignable" manager="plone.leftcolumn" name="habra-rss" type="portlets.rss">
    <property name="count">
      20
    </property>
    <property name="url">
      http://habrahabr.ru/rss/
    </property>
    <property name="portlet_title">
      Habrahabr RSS feed
    </property>
    <property name="timeout">
      120
    </property>
  </assignment>
  <blacklist category="user" manager="plone.leftcolumn" status="block"/>
  <blacklist category="group" manager="plone.leftcolumn" status="acquire"/>
  <blacklist category="content_type" manager="plone.leftcolumn" status="acquire"/>
  <blacklist category="context" manager="plone.leftcolumn" status="acquire"/>
</portlets>
""")
                    )
                )
            )

    provideUtility(PortletsSource,
        name=u'quintagroup.transmogrifier.tests.portletssource')

    class PortletsSource2(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(PortletsSource2, self).__init__(*args, **kw)
            self.sample = (
                dict(),
                dict(_path='other-assignable',
                    files=dict(portlets=dict(
                        name='.portlets.xml',
                        data="""<?xml version="1.0" encoding="utf-8"?>
<portlets>
  <assignment category="context" key="/other-assignable" manager="plone.leftcolumn" name="sumno-rss-2" type="portlets.rss">
    <property name="count">
      30
    </property>
    <property name="url">
      http://sumno.com/rss
    </property>
    <property name="portlet_title">
      Sumno RSS feed
    </property>
    <property name="timeout">
      360
    </property>
  </assignment>
  <blacklist category="user" manager="plone.leftcolumn" status="block"/>
  <blacklist category="group" manager="plone.leftcolumn" status="acquire"/>
  <blacklist category="content_type" manager="plone.leftcolumn" status="acquire"/>
  <blacklist category="context" manager="plone.leftcolumn" status="acquire"/>
</portlets>
""")
                    )
                )
            )
    provideUtility(PortletsSource2,
       name=u'quintagroup.transmogrifier.tests.portletssource2')

    # prepare the one portlet for testing
    from zope.interface import alsoProvides
    from zope.component import getUtility, getMultiAdapter
    from zope.component.interfaces import IFactory
    from zope.component.factory import Factory

    from plone.portlets.manager import PortletManager
    from plone.portlets.interfaces import IPortletManager, IPortletType, \
        IPortletAssignmentMapping
    from plone.portlets.registration import PortletType

    from plone.app.portlets.assignable import localPortletAssignmentMappingAdapter
    from plone.portlets.assignable import LocalPortletAssignmentManager
    from plone.app.portlets.interfaces import IPortletTypeInterface
    from plone.portlets.interfaces import  ILocalPortletAssignmentManager
    from plone.portlets.constants import USER_CATEGORY
    # from plone.app.portlets.browser.interfaces import IPortletAdding
    from plone.app.portlets.portlets.rss import IRSSPortlet, Assignment #, Renderer, AddForm, EditForm

    # register portlet manager and assignment mapping adapter
    manager = PortletManager()
    provideUtility(manager, IPortletManager, name='plone.leftcolumn')
    provideAdapter(localPortletAssignmentMappingAdapter)
    provideAdapter(LocalPortletAssignmentManager)
    mapping = getMultiAdapter((portal, manager), IPortletAssignmentMapping)
    assignable = getMultiAdapter((portal, manager), ILocalPortletAssignmentManager)
    test.globs['mapping'] = mapping
    test.globs['assignable'] = assignable

    # register portlet (this is what plone:portlet zcml directive does)
    PORTLET_NAME = 'portlets.rss'
    alsoProvides(IRSSPortlet, IPortletTypeInterface)
    provideUtility(provides=IPortletTypeInterface, name=PORTLET_NAME, component=IRSSPortlet)
    provideUtility(provides=IFactory, name=PORTLET_NAME, component=Factory(Assignment))

    # register a portlet type (this is what <portlet /> element in portlets.xml
    # does)
    portlet = PortletType()
    portlet.title = 'RSS Feed'
    portlet.description = 'A portlet which can receive and render an RSS feed.'
    portlet.addview = PORTLET_NAME
    portlet.for_ = [Interface]
    provideUtility(component=portlet, provides=IPortletType, 
        name=PORTLET_NAME)

    # add a portlet and configure it (this is done on @@manage-portlets view)
    assignment = getUtility(IFactory, name=PORTLET_NAME)()
    mapping['rss'] = assignment
    portlet_interface = getUtility(IPortletTypeInterface, name=PORTLET_NAME)
    data = {
        'portlet_title': u'RSS feed',
        'count': 10,
        'url': u'http://sumno.com/feeds/main-page/',
        'timeout': 60
    }
    for k, v in data.items():
        field = portlet_interface.get(k)
        field = field.bind(assignment)
        field.validate(v)
        field.set(assignment, v)
    # set blacklists for user category to 'block'
    assignable.setBlacklistStatus(USER_CATEGORY, True)