def test_portlet_event_renderer__get_events(self):
        start = localized_now()
        end = start + timedelta(hours=1)

        e1 = createContentInContainer(self.portal,
                                      PTYPE,
                                      id='e1',
                                      title=u'e1',
                                      start=start,
                                      end=end)
        self.portal.portal_workflow.doActionFor(e1, 'publish')

        self.portal.invokeFactory('Folder', 'eventfolder')
        createContentInContainer(self.portal.eventfolder,
                                 PTYPE,
                                 id='e2',
                                 title=u'e2',
                                 start=start,
                                 end=end)

        r = self.renderer(
            assignment=portlet_events.Assignment(count=5, state=('draft', )))
        r.update()
        self.assertEqual(0, len(r.events))

        r = self.renderer(assignment=portlet_events.Assignment(
            count=5, state=('published', )))
        r.update()
        self.assertEqual(1, len(r.events))

        r = self.renderer(assignment=portlet_events.Assignment(count=5,
                                                               state=(
                                                                   'published',
                                                                   'private',
                                                               )))
        r.update()
        self.assertEqual(2, len(r.events))

        r = self.renderer(assignment=portlet_events.Assignment(count=5))
        r.update()
        self.assertEqual(2, len(r.events))

        # No search base gives calendar urls with event_listing part
        self.assertTrue('event_listing' in r.render())

        r = self.renderer(assignment=portlet_events.Assignment(
            count=5, search_base_uid=self.portal.eventfolder.UID()))
        r.update()
        self.assertEqual(1, len(r.events))

        # A given search base gives calendar urls without event_listing part
        self.assertTrue('event_listing' not in r.render())
Esempio n. 2
0
    def test_events_recurring(self):
        startDT = DateTime('Australia/Brisbane') + 1

        self.portal.invokeFactory('Event',
                                  'e1',
                                  title='Event 1',
                                  startDate=startDT,
                                  recurrence='RRULE:FREQ=WEEKLY;COUNT=10',
                                  timezone="Australia/Brisbane")
        self.portal.invokeFactory('Event',
                                  'e2',
                                  title='Event 2',
                                  startDate=startDT,
                                  recurrence='RRULE:FREQ=DAILY;COUNT=3',
                                  timezone="Australia/Brisbane")
        self.portal.portal_workflow.doActionFor(self.portal.e1, 'publish')

        r = self.renderer(assignment=portlet_events.Assignment(
            count=5, state=('published', )))
        events = r.events
        self.assertEqual(5, len(events))
        self.assertTrue('Event 2' not in [x.title for x in events])

        rd = r.render()
        occ1DT = startDT + 7
        # The first occurrence of the event itself should show up. It should
        # link to the event and not an occurrence.
        self.assertTrue('http://nohost/plone/e1"' in rd)
        # Occurrences should link to the Occurrence.
        self.assertTrue('http://nohost/plone/e1/%s-%02d-%02d' %
                        (occ1DT.year(), occ1DT.month(), occ1DT.day()) in rd)
Esempio n. 3
0
def convert_legacy_portlets(context):
    """Convert legacy portlets (left_slots, right_slots) in the given
    context to new-style portlets.
    """

    portletsMapping = {
        'portlet_login': login.Assignment(),
        'portlet_news': news.Assignment(count=5),
        'portlet_navigation': navigation.Assignment(),
        'portlet_review': review.Assignment(),
        'portlet_recent': recent.Assignment(count=5),
        'portlet_related': DONT_MIGRATE,
        'portlet_languages': DONT_MIGRATE,
        'portlet_calendar': calendar.Assignment(),
        'portlet_events': events.Assignment(count=5),
    }

    # Convert left_slots and right_slots to portlets

    left = getUtility(IPortletManager, name='plone.leftcolumn')
    right = getUtility(IPortletManager, name='plone.rightcolumn')

    leftAssignable = getMultiAdapter((context, left),
                                     IPortletAssignmentMapping).__of__(context)
    rightAssignable = getMultiAdapter(
        (context, right), IPortletAssignmentMapping).__of__(context)

    IPortletPermissionChecker(leftAssignable)()
    IPortletPermissionChecker(rightAssignable)()

    leftChooser = INameChooser(leftAssignable)
    rightChooser = INameChooser(rightAssignable)

    left_slots = getattr(aq_base(context), 'left_slots', [])
    right_slots = getattr(aq_base(context), 'right_slots', [])

    for item in left_slots:
        path = item.split('/')
        if len(path) == 4:
            newPortlet = portletsMapping.get(path[1], None)
            if newPortlet is None and path[0] in (
                    'context', 'here') and path[2] == 'macros':
                newPortlet = classic.Assignment(path[1], path[3])
            if newPortlet is not None and newPortlet is not DONT_MIGRATE:
                leftAssignable[leftChooser.chooseName(None,
                                                      newPortlet)] = newPortlet

    for item in right_slots:
        path = item.split('/')
        if len(path) == 4:
            newPortlet = portletsMapping.get(path[1], None)
            if newPortlet is None and path[0] in (
                    'context', 'here') and path[2] == 'macros':
                newPortlet = classic.Assignment(path[1], path[3])
            if newPortlet is not None and newPortlet is not DONT_MIGRATE:
                rightAssignable[rightChooser.chooseName(
                    None, newPortlet)] = newPortlet

    context.left_slots = []
    context.right_slots = []
    def test_portlet_event_renderer__recurring(self):
        tz = pytz.timezone(TZNAME)
        start = tz.localize(datetime.now()) + timedelta(days=1)

        e1 = createContentInContainer(self.portal,
                                      PTYPE,
                                      id='e1',
                                      title='Event 1',
                                      start=start,
                                      recurrence='RRULE:FREQ=WEEKLY;COUNT=10')
        createContentInContainer(self.portal,
                                 PTYPE,
                                 id='e1',
                                 title='Event 1',
                                 start=start,
                                 recurrence='RRULE:FREQ=DAILY;COUNT=3')

        self.portal.portal_workflow.doActionFor(e1, 'publish')

        r = self.renderer(assignment=portlet_events.Assignment(
            count=5, state=('published', )))
        events = r.events
        self.assertEqual(5, len(events))
        self.assertTrue('Event 2' not in [x.title for x in events])

        rd = r.render()
        occ1dt = start + timedelta(days=7)
        # The first occurrence of the event itself should show up. It should
        # link to the event and not an occurrence.
        self.assertTrue('http://nohost/plone/e1"' in rd)
        # Occurrences should link to the Occurrence.
        self.assertTrue('http://nohost/plone/e1/%s-%02d-%02d' %
                        (occ1dt.year, occ1dt.month, occ1dt.day) in rd)
    def testInvokeEditView(self):
        mapping = PortletAssignmentMapping()

        mapping['foo'] = portlet_events.Assignment(count=5)
        editview = getMultiAdapter((mapping['foo'], self.request), name='edit')
        if PLONE5:
            self.assertTrue(isinstance(editview, portlet_events.EditForm))
        else:
            self.assertTrue(isinstance(editview, bbb_portlet_events.EditForm))
Esempio n. 6
0
    def testRenderer(self):
        context = self.portal
        view = context.restrictedTraverse('@@plone')
        manager = getUtility(IPortletManager,
                             name='plone.leftcolumn',
                             context=self.portal)
        assignment = portlet_events.Assignment(count=5)

        renderer = getMultiAdapter(
            (context, self.request, view, manager, assignment),
            IPortletRenderer)
        self.assertTrue(isinstance(renderer, portlet_events.Renderer))
Esempio n. 7
0
    def test_events(self):
        start = DateTime('Australia/Brisbane') + 2
        end = DateTime('Australia/Brisbane') + 4
        self.portal.invokeFactory('Event', 'e1', startDate=start, endDate=end)
        self.portal.invokeFactory('Folder', 'eventfolder')
        # one event in the events folder
        self.portal.eventfolder.invokeFactory('Event',
                                              'e2',
                                              startDate=start,
                                              endDate=end)
        self.portal.portal_workflow.doActionFor(self.portal.e1, 'publish')

        portlet = self.renderer(
            assignment=portlet_events.Assignment(count=5, state=('draft', )))
        self.assertEqual(0, len(portlet.events))

        portlet = self.renderer(assignment=portlet_events.Assignment(
            count=5, state=('published', )))
        self.assertEqual(1, len(portlet.events))

        portlet = self.renderer(assignment=portlet_events.Assignment(
            count=5, state=(
                'published',
                'private',
            )))
        self.assertEqual(2, len(portlet.events))

        portlet = self.renderer(assignment=portlet_events.Assignment(count=5))
        self.assertEqual(2, len(portlet.events))

        # No search base gives calendar urls with event_listing part
        self.assertTrue('event_listing' in portlet.render())

        portlet = self.renderer(assignment=portlet_events.Assignment(
            count=5, search_base="/eventfolder"))
        self.assertEqual(1, len(portlet.events))

        # A given search base gives calendar urls without event_listing part
        self.assertTrue('event_listing' not in portlet.render())
Esempio n. 8
0
    def test_portlets_render_events(self):
        self.portal.invokeFactory('Event', 'e1')
        self.portal.invokeFactory('Event', 'e2')
        self.portal.invokeFactory('Event', 'e3')
        self.portal.portal_workflow.doActionFor(self.portal.e1, 'publish')
        self.portal.portal_workflow.doActionFor(self.portal.e2, 'publish')

        assignment = portlet_events.Assignment(count=2)
        renderer = EventsPortletRenderer(self.context, self.request, None,
                                         None, assignment)
        result = renderer.render()
        # import pdb; pdb.set_trace()
        self.assertEqual(len(result['items']), 2)
    def test_events(self):
        start = DateTime('Australia/Brisbane') + 2
        end = DateTime('Australia/Brisbane') + 4
        self.portal.invokeFactory('Event', 'e1', startDate=start, endDate=end)
        self.portal.invokeFactory('Folder', 'eventfolder')
        # one event in the events folder
        self.portal.eventfolder.invokeFactory('Event',
                                              'e2',
                                              startDate=start,
                                              endDate=end)
        self.portal.portal_workflow.doActionFor(self.portal.e1, 'publish')

        portlet = self.renderer(
            assignment=portlet_events.Assignment(count=5, state=('draft', )))
        self.assertEquals(0, len(portlet.events))

        portlet = self.renderer(assignment=portlet_events.Assignment(
            count=5, state=('published', )))
        self.assertEquals(1, len(portlet.events))

        portlet = self.renderer(assignment=portlet_events.Assignment(
            count=5, state=(
                'published',
                'private',
            )))
        self.assertEquals(2, len(portlet.events))

        portlet = self.renderer(assignment=portlet_events.Assignment(count=5))
        self.assertEquals(2, len(portlet.events))

        portlet = self.renderer(assignment=portlet_events.Assignment(
            count=5, search_base="/eventfolder"))
        self.assertEquals(1, len(portlet.events))

        # TODO: better create objects at setup and use thest in these tests
        self.portal.manage_delObjects(['e1', 'eventfolder'])
Esempio n. 10
0
    def renderer(self,
                 context=None,
                 request=None,
                 view=None,
                 manager=None,
                 assignment=None):
        context = context or self.portal
        request = request or self.request
        view = view or context.restrictedTraverse('@@plone')
        manager = manager or getUtility(
            IPortletManager, name='plone.leftcolumn', context=self.portal)
        assignment = assignment or portlet_events.Assignment(
            template='portlet_recent', macro='portlet')

        return getMultiAdapter((context, request, view, manager, assignment),
                               IPortletRenderer)
Esempio n. 11
0
def migrate_events_portlets(context, path=None):
    """
    Fix missing attributes from old events portlets.

    Fixes a recursion error after upgrading:

    2019-04-29 18:10:09 ERROR imageportlet Error while determining renderer availability of portlet ('context' '/...' 'events'): maximum recursion depth exceeded
    Traceback (most recent call last):
      File "eggs/plone.portlets-2.3-py2.7.egg/plone/portlets/manager.py", line 117, in _lazyLoadPortlets
        isAvailable = renderer.available
      File "src/plone.app.event/plone/app/event/portlets/portlet_events.py", line 141, in available
        return self.data.count > 0 and len(self.events)
      File "src/plone.app.event/plone/app/event/portlets/portlet_events.py", line 154, in events
        if ICollection and ICollection.providedBy(self.search_base):
      File "src/plone.app.event/plone/app/event/portlets/portlet_events.py", line 122, in search_base
        if not self._search_base and self.data.search_base_uid:
      File "src/plone.app.event/plone/app/event/portlets/portlet_events.py", line 106, in _uid
        path = self.search_base
    ...
      File "src/plone.app.event/plone/app/event/portlets/portlet_events.py", line 122, in search_base
        if not self._search_base and self.data.search_base_uid:
      File "src/plone.app.event/plone/app/event/portlets/portlet_events.py", line 106, in _uid
        path = self.search_base
    RuntimeError: maximum recursion depth exceeded
    """
    annotations = IAnnotations(context, None)
    if annotations is None:
        return

    default_assignment_attrs = vars(portlet_events.Assignment())
    for mapping in annotations.get(
            constants.CONTEXT_ASSIGNMENT_KEY, {}).values():
        for assignment in mapping.values():
            if not isinstance(assignment, portlet_events.Assignment):
                continue

            attrs = vars(assignment)
            for attr, default in default_assignment_attrs.items():
                if attr not in attrs:
                    setattr(assignment, attr, default)
Esempio n. 12
0
 def testInterfaces(self):
     portlet = portlet_events.Assignment()
     self.assertTrue(IPortletAssignment.providedBy(portlet))
     self.assertTrue(IPortletDataProvider.providedBy(portlet.data))
Esempio n. 13
0
 def test_events_listing_link(self):
     r = self.renderer(assignment=portlet_events.Assignment(count=5))
     rd = r.render()
     self.assertTrue('?mode=future' in rd)
     self.assertTrue('?mode=past' in rd)
Esempio n. 14
0
    def testInvokeEditView(self):
        mapping = PortletAssignmentMapping()

        mapping['foo'] = portlet_events.Assignment(count=5)
        editview = getMultiAdapter((mapping['foo'], self.request), name='edit')
        self.failUnless(isinstance(editview, portlet_events.EditForm))
Esempio n. 15
0
 def testInterfaces(self):
     portlet = portlet_events.Assignment()
     self.failUnless(IPortletAssignment.providedBy(portlet))
     self.failUnless(IPortletDataProvider.providedBy(portlet.data))