コード例 #1
0
    def test_import_from_ics__no_sync(self):
        """SYNC_NONE and importing the same file again should create new event
        objects and give them each a new sync_uid.
        """
        self.portal.invokeFactory('Folder', 'impfolder2')
        impfolder = self.portal.impfolder2

        directory = os.path.dirname(__file__)
        icsfile = open(os.path.join(directory, 'icaltest.ics'), 'rb').read()

        res = ical_import(impfolder, icsfile, self.event_type)
        self.assertEqual(res['count'], 5)

        e11 = impfolder['e1']
        suid1 = IEventAccessor(e11).sync_uid

        res = ical_import(impfolder,
                          icsfile,
                          self.event_type,
                          sync_strategy=base.SYNC_NONE)
        self.assertEqual(res['count'], 5)

        e12 = impfolder['e1-1']
        suid2 = IEventAccessor(e12).sync_uid

        self.assertEqual(len(impfolder.contentIds()), 10)
        self.assertNotEqual(suid1, suid2)
コード例 #2
0
    def test_import_from_ics(self):
        # Ical import unit test.
        self.portal.invokeFactory('Folder', 'impfolder1')
        impfolder = self.portal.impfolder1

        directory = os.path.dirname(__file__)
        icsfile = open(os.path.join(directory, 'icaltest.ics'), 'rb').read()
        res = ical_import(impfolder, icsfile, self.event_type)

        self.assertEqual(res['count'], 5)
        self.assertEqual(len(impfolder.contentIds()), 5)

        at = pytz.timezone('Europe/Vienna')
        utc = pytz.utc

        # Use pydt to normalize for DST times.

        # TODO: test for attendees. see note in
        # plone.app.event.ical.importer.ical_import
        e1 = IEventAccessor(impfolder.e1)
        self.assertEqual(e1.start, at.localize(datetime(2013, 7, 19, 12, 0)))
        self.assertEqual(e1.end, at.localize(datetime(2013, 7, 20, 13, 0)))
        self.assertEqual(e1.description, 'A basic event with many properties.')
        self.assertEqual(e1.whole_day, False)
        self.assertEqual(e1.open_end, False)
        self.assertEqual(
            e1.sync_uid,
            u'48f1a7ad64e847568d860cd092344970',
        )

        e2 = IEventAccessor(impfolder.e2)
        self.assertEqual(e2.start, utc.localize(datetime(1996, 4, 1, 1, 0)))
        self.assertEqual(e2.end, utc.localize(datetime(1996, 4, 1, 2, 0)))
        self.assertEqual(
            e2.recurrence,
            u'RRULE:FREQ=DAILY;COUNT=100\nEXDATE:19960402T010000Z,'
            u'19960403T010000Z,19960404T010000Z')

        e3 = IEventAccessor(impfolder.e3)
        self.assertEqual(e3.start, at.localize(datetime(2012, 3, 27, 10, 0)))
        self.assertEqual(e3.end, at.localize(datetime(2012, 3, 27, 18, 0)))
        self.assertEqual(
            e3.recurrence,
            u'RRULE:FREQ=WEEKLY;UNTIL=20120703T080000Z;BYDAY=TU\n'
            u'EXDATE:20120529T100000,20120403T100000,20120410T100000,'
            u'20120501T100000,20120417T100000')

        e4 = IEventAccessor(impfolder.e4)
        self.assertEqual(e4.start, utc.localize(datetime(2013, 4, 4, 0, 0)))
        self.assertEqual(e4.end, utc.localize(datetime(2013, 4, 4, 23, 59,
                                                       59)))
        self.assertEqual(e4.whole_day, True)
        self.assertEqual(e4.open_end, False)

        e5 = IEventAccessor(impfolder.e5)
        self.assertEqual(e5.start, utc.localize(datetime(2013, 4, 2, 12, 0)))
        self.assertEqual(e5.end, utc.localize(datetime(2013, 4, 2, 23, 59,
                                                       59)))
        self.assertEqual(e5.whole_day, False)
        self.assertEqual(e5.open_end, True)
コード例 #3
0
    def test_import_from_ics__sync_keep_mine(self):
        """SYNC_KEEP_MINE and importing the same file again should do nothing.
        """
        self.portal.invokeFactory('Folder', 'impfolder3')
        impfolder = self.portal.impfolder3

        directory = os.path.dirname(__file__)
        icsfile = open(os.path.join(directory, 'icaltest.ics'), 'rb').read()

        res = ical_import(impfolder, icsfile, self.event_type)
        self.assertEqual(res['count'], 5)

        e1a = IEventAccessor(impfolder.e1)
        mod1 = e1a.last_modified
        suid1 = e1a.sync_uid

        res = ical_import(impfolder,
                          icsfile,
                          self.event_type,
                          sync_strategy=base.SYNC_KEEP_MINE)
        self.assertEqual(res['count'], 0)
        e1a = IEventAccessor(impfolder.e1)
        mod2 = e1a.last_modified
        suid2 = e1a.sync_uid

        self.assertEqual(len(impfolder.contentIds()), 5)

        self.assertEqual(mod1, mod2)
        self.assertEqual(suid1, suid2)
コード例 #4
0
    def test_data_postprocessing(self):
        # Addressing bug #62
        self.portal.invokeFactory(
            'plone.app.event.dx.event',
            'event1',
            start=datetime(2012, 10, 19, 0, 30),
            end=datetime(2012, 10, 19, 1, 30),
            timezone="Europe/Vienna",
            whole_day=False
        )
        e1 = self.portal['event1']
        e1.reindexObject()

        # Prepare reference objects
        tzname_1 = "Europe/Vienna"
        tz_1 = pytz.timezone(tzname_1)
        dt_1 = tz_1.localize(datetime(2012, 10, 19, 0, 30))
        dt_1_1 = tz_1.localize(datetime(2012, 10, 19, 0, 0))
        dt_1_2 = tz_1.localize(datetime(2012, 10, 19, 23, 59, 59))

        tzname_2 = "Hongkong"
        tz_2 = pytz.timezone(tzname_2)
        dt_2 = tz_2.localize(datetime(2012, 10, 19, 0, 30))
        dt_2_1 = tz_2.localize(datetime(2012, 10, 19, 0, 0))
        dt_2_2 = tz_2.localize(datetime(2012, 10, 19, 23, 59, 59))

        # See, if start isn't moved by timezone offset. Addressing issue #62
        self.assertTrue(IEventBasic(e1).start == dt_1)
        notify(ObjectModifiedEvent(e1))
        self.assertTrue(IEventBasic(e1).start == dt_1)

        # After timezone changes, only the timezone should be applied, but the
        # date and time values not converted.
        IEventAccessor(e1).timezone = tzname_2
        notify(ObjectModifiedEvent(e1))
        self.assertTrue(IEventBasic(e1).start == dt_2)

        # Test open_end events
        # For open_end events, setting the end date has no effect
        IEventAccessor(e1).edit(
            timezone=tzname_1,
            open_end=True,
            end=datetime(2012, 11, 11, 10, 10, 0),
        )
        notify(ObjectModifiedEvent(e1))
        self.assertTrue(IEventBasic(e1).start == dt_1)
        self.assertTrue(IEventBasic(e1).end == dt_1_2)

        # Likewise with whole_day events. If values were converted, the days
        # would drift apart.
        IEventAccessor(e1).whole_day = True
        notify(ObjectModifiedEvent(e1))
        self.assertTrue(IEventBasic(e1).start == dt_1_1)
        self.assertTrue(IEventBasic(e1).end == dt_1_2)

        IEventAccessor(e1).timezone = tzname_2
        notify(ObjectModifiedEvent(e1))
        self.assertTrue(IEventBasic(e1).start == dt_2_1)
        self.assertTrue(IEventBasic(e1).end == dt_2_2)
コード例 #5
0
 def test_occurrence_accessor(self):
     start = self.now
     end = self.future
     occ = Occurrence('ignored', start, end)
     occ = occ.__of__(self.now_event)
     acc_occ = IEventAccessor(occ)
     acc_ctx = IEventAccessor(self.now_event)
     self.assertEqual(acc_occ.start, acc_ctx.start)
     self.assertEqual(acc_occ.url, 'http://nohost/plone/now/ignored')
コード例 #6
0
    def test_event_accessor(self):
        obj = MockObject()
        tz = pytz.timezone('Europe/Vienna')
        obj.start = datetime(2012, 12, 12, 10, 0, tzinfo=tz)
        obj.end = datetime(2012, 12, 12, 12, 0, tzinfo=tz)
        zope.interface.alsoProvides(obj, IEvent)

        # Create accessor
        acc = IEventAccessor(obj)

        # Accessor getters
        self.assertEqual(acc.start, obj.start)
        self.assertEqual(acc.end, obj.end)
        self.assertEqual(acc.duration, obj.end - obj.start)

        # Accessor setters
        start = datetime(2013, 4, 5, 16, 31, tzinfo=tz)
        end = datetime(2013, 4, 5, 16, 35, tzinfo=tz)
        acc.start = start
        acc.end = end
        self.assertTrue(acc.start == obj.start == start)
        self.assertTrue(acc.end == obj.end == end)

        # Accessor deletor
        acc.something = True
        self.assertTrue(acc.something == obj.something is True)
        del acc.something
        self.assertTrue(hasattr(acc, 'something') is False)
        self.assertTrue(hasattr(obj, 'something') is False)

        del acc.start
        self.assertTrue(hasattr(acc, 'start') is False)
        self.assertTrue(hasattr(obj, 'start') is False)
コード例 #7
0
    def test_event_accessor__sync_uid(self):
        self.request.set('HTTP_HOST', 'nohost')

        e1 = createContentInContainer(
            self.portal,
            'plone.app.event.dx.event',
            title='event1'
        )
        acc = IEventAccessor(e1)

        # setting no sync uid will automatically generate one
        self.assertTrue(acc.sync_uid, IUUID(e1) + '@nohost')
        # it's not stored on the object though
        self.assertEqual(e1.sync_uid, None)
        # but it's indexed
        result = self.portal.portal_catalog(sync_uid=IUUID(e1) + '@nohost')
        self.assertEqual(len(result), 1)

        # Setting the sync_uid
        acc.sync_uid = 'okay'
        e1.reindexObject()
        self.assertEqual(acc.sync_uid, 'okay')
        # Now, it's also stored on the object itself
        self.assertEqual(e1.sync_uid, 'okay')
        # and indexed
        result = self.portal.portal_catalog(sync_uid='okay')
        self.assertEqual(len(result), 1)
コード例 #8
0
def get_location(context):
    """Return the location.
    This method can be used to be overwritten by external packages, for example
    to provide a reference to a Location object as done by collective.venue.
    """
    data = IEventAccessor(context)
    return data.location
コード例 #9
0
    def test_event_accessor__start_end(self):
        e1 = createContentInContainer(
            self.portal,
            'plone.app.event.dx.event',
            title='event1'
        )

        dt = datetime(2161, 1, 1)  # United Federation of Planets
        DT = DateTime('2161/01/01 00:00:00 UTC')

        acc = IEventAccessor(e1)

        # Setting a timezone-naive datetime should convert it to UTC
        acc.start = dt
        self.assertEqual(acc.start, utils.utc(dt))
        self.assertEqual(e1.start, utils.utc(dt))
        # Setting a DateTime should convert it to datetime
        acc.start = DT
        self.assertEqual(acc.start, utils.utc(dt))
        self.assertEqual(e1.start, utils.utc(dt))

        # Same goes for acc.end
        # Setting a timezone-naive datetime should convert it to UTC
        acc.end = dt
        self.assertEqual(acc.end, utils.utc(dt))
        self.assertEqual(e1.end, utils.utc(dt))
        # Setting a DateTime should convert it to datetime
        acc.end = DT
        self.assertEqual(acc.end, utils.utc(dt))
        self.assertEqual(e1.end, utils.utc(dt))
コード例 #10
0
 def getNewEventDetail(obj):
     acc = IEventAccessor(obj)
     return [
         obj.id, [acc.start.year, acc.start.month, acc.start.day],
         [acc.end.year, acc.end.month, acc.end.day], acc.location,
         acc.attendees
     ]
コード例 #11
0
    def test_event_summary_occurrences_next_upcoming(self):
        event = IEventAccessor(self.portal['daily'])

        date = patched_now()
        with mock.patch('plone.app.event.dx.behaviors.localized_now',
                        return_value=date):
            view = zope.component.getMultiAdapter(
                (self.portal['daily'], self.request), name='event_summary')
            # altogether 4 occurrences, start occurrence is included
            self.assertEqual(4, len(view.next_occurrences))
            self.assertEqual(event.start, date)
            self.assertEqual(event.end, date + datetime.timedelta(hours=1))

        IAnnotations(self.request).clear()  # clear cache
        next_date = patched_now() + datetime.timedelta(hours=24)
        with mock.patch('plone.app.event.dx.behaviors.localized_now',
                        return_value=next_date):
            view = zope.component.getMultiAdapter(
                (self.portal['daily'], self.request), name='event_summary')
            # 3 occurrences remaining
            self.assertEqual(3, len(view.next_occurrences))
            self.assertEqual(event.start, next_date)
            next_end_date = next_date + datetime.timedelta(hours=1)
            self.assertEqual(event.end, next_end_date)

        IAnnotations(self.request).clear()  # clear cache
        next_date = patched_now() + datetime.timedelta(days=10)
        with mock.patch('plone.app.event.dx.behaviors.localized_now',
                        return_value=next_date):
            view = zope.component.getMultiAdapter(
                (self.portal['daily'], self.request), name='event_summary')
            # no occurrences remaining, show all original 4
            self.assertEqual(4, len(view.next_occurrences))
            self.assertEqual(event.start, date)
            self.assertEqual(event.end, date + datetime.timedelta(hours=1))
コード例 #12
0
    def test_event_accessor_whole_day__open_end(self):

        at = pytz.timezone("Europe/Vienna")

        start = at.localize(datetime(2012, 10, 19, 0, 30))
        end = at.localize(datetime(2012, 10, 19, 1, 30))

        start_start = at.localize(datetime(2012, 10, 19, 0, 0, 0))
        end_end = at.localize(datetime(2012, 10, 19, 23, 59, 59))

        e1 = createContentInContainer(self.portal,
                                      'plone.app.event.dx.event',
                                      title='event1',
                                      start=start,
                                      end=end)
        acc = IEventAccessor(e1)

        # check set
        self.assertEqual(e1.start, start)
        self.assertEqual(e1.end, end)

        # Setting open end
        e1.open_end = True
        self.assertEqual(e1.start, start)
        self.assertEqual(e1.end, end)
        self.assertEqual(acc.start, start)
        self.assertEqual(acc.end, end_end)

        # Setting whole day
        e1.whole_day = True
        self.assertEqual(e1.start, start)
        self.assertEqual(e1.end, end)
        self.assertEqual(acc.start, start_start)
        self.assertEqual(acc.end, end_end)
コード例 #13
0
    def test_pact_1_0_dxevent_is_migrated(self):
        def getNewEventDetail(obj):
            acc = IEventAccessor(obj)
            return [
                obj.id, [acc.start.year, acc.start.month, acc.start.day],
                [acc.end.year, acc.end.month, acc.end.day], acc.location,
                acc.attendees
            ]

        # Create some 1.0 Event objects
        create1_0EventType(self.portal)
        self.portal.invokeFactory('Folder', 'event-folder')
        self.createOldEvent(
            self.portal,
            'eventa',
            start_date=datetime(2012, 1, 1, 15, 20),
            end_date=datetime(2015, 9, 2, 16, 20),
        )
        self.createOldEvent(
            self.portal['event-folder'],
            'eventb',
            start_date=datetime(2013, 3, 3, 15, 20),
            end_date=datetime(2019, 5, 6, 16, 20),
        )

        # IEventAccessor? What's that?
        with self.assertRaisesRegexp(TypeError, 'IEventAccessor'):
            IEventAccessor(self.portal['eventa'])

        # Run upgrade step
        self.doUpgradeStep('1001', '1100')
コード例 #14
0
    def valuesTable(self):
        acc = IEventAccessor(self.context)
        if acc.start:
            horaInici = acc.start.strftime('%d/%m/%Y %H:%M')
            year = acc.start.strftime('%Y') + '/'
        else:
            horaInici = ''
            year = ''
        if acc.end:
            horaFi = acc.end.strftime('%d/%m/%Y %H:%M')
        else:
            horaFi = ''
        if self.context.llocConvocatoria is None:
            llocConvocatoria = ''
        else:
            llocConvocatoria = self.context.llocConvocatoria

        session = self.context.numSessio
        organ = self.context.aq_parent.acronim
        sessionNumber = str(organ) + '/' + str(year) + str(session)

        value = api.content.get_state(obj=self.context)
        lang = self.context.language
        status = translate(msgid=value, domain='genweb', target_language=lang)

        values = dict(
            horaInici=horaInici,
            horaFi=horaFi,
            llocConvocatoria=llocConvocatoria,
            organTitle=self.OrganTitle(),
            sessionNumber=sessionNumber,
            status=status,
        )
        return values
コード例 #15
0
    def test_event_accessor(self):
        utc = pytz.utc
        self.portal.invokeFactory(
            'plone.app.event.dx.event',
            'event1',
            start=datetime(2011, 11, 11, 11, 0, tzinfo=utc),
            end=datetime(2011, 11, 11, 12, 0, tzinfo=utc),
            timezone='UTC',
            whole_day=False
        )
        e1 = self.portal['event1']

        # setting attributes via the accessor
        acc = IEventAccessor(e1)
        acc.end = datetime(2011, 11, 13, 10, 0)
        acc.timezone = TZNAME

        tz = pytz.timezone(TZNAME)

        # accessor should return end datetime in the event's timezone
        self.assertTrue(acc.end == datetime(2011, 11, 13, 11, 0, tzinfo=tz))

        # the behavior's end datetime is stored in utc on the content object
        self.assertTrue(e1.end == datetime(2011, 11, 13, 10, 0, tzinfo=utc))

        # accessing the end property via the behavior adapter, returns the
        # value converted to the event's timezone
        self.assertTrue(
            IEventBasic(e1).end == datetime(2011, 11, 13, 11, 0, tzinfo=tz)
        )

        # timezone should be the same on the event object and accessor
        self.assertTrue(e1.timezone == acc.timezone)
コード例 #16
0
def construct_calendar(events, start=None, end=None):
    """Return a dictionary with dates in a given timeframe as keys and the
    actual occurrences for that date for building calendars.
    Long lasting events will occur on every day until their end.

    :param events: List of IEvent and/or IOccurrence objects, to construct a
                   calendar data structure from.
    :type events: list

    :param start: An optional start range date.
    :type start: Python datetime or date

    :param end: An optional start range date.
    :type end: Python datetime or date

    :returns: Dictionary with isoformat date strings as keys and event
              occurrences as values.
    :rtype: dict

    """
    if start:
        if is_datetime(start):
            start = start.date()
        assert is_date(start)
    if end:
        if is_datetime(end):
            end = end.date()
        assert is_date(end)

    cal = {}

    def _add_to_cal(cal_data, event, date):
        date_str = date.isoformat()
        if date_str not in cal_data:
            cal_data[date_str] = [event]
        else:
            cal_data[date_str].append(event)
        return cal_data

    for event in events:
        acc = IEventAccessor(event)
        start_date = acc.start.date()
        end_date = acc.end.date()

        # day span between start and end + 1 for the initial date
        range_days = (end_date - start_date).days + 1
        for add_day in range(range_days):
            next_start_date = start_date + timedelta(add_day)  # initial = 0

            # avoid long loops
            if start and end_date < start:
                break  # if the date is completly outside the range
            if start and next_start_date < start:
                continue  # if start_date is outside but end reaches into range
            if end and next_start_date > end:
                break  # if date is outside range

            _add_to_cal(cal, event, next_start_date)
    return cal
コード例 #17
0
 def set_allDay(self, v):
     v = bool(v)
     if HAS_PAE:
         if IEvent.providedBy(self.context):
             acc = IEventAccessor(self.context)
             acc.whole_day = v
             return
     self._all_day = v
コード例 #18
0
 def _allDay(self):
     if HAS_PAE:
         if IEvent.providedBy(self.context):
             acc = IEventAccessor(self.context)
             return acc.whole_day or False
     if self._all_day is not None:
         return bool(self._all_day)
     return False
コード例 #19
0
 def __init__(self, context, request):
     self.context = context
     self.request = request
     self.data = IEventAccessor(context)
     self.max_occurrences = 6
     self.excludes = [
         'title',
     ]
コード例 #20
0
 def _get_context(self, name):
     # TODO: save parent context on self, so it must not be called every
     #       time
     oa = self._own_attr
     if name in oa:
         return self.context
     else:
         return IEventAccessor(aq_parent(self.context))
コード例 #21
0
    def test_import_from_ics__sync_drop_older(self):
        """SYNC_KEEP_NEWER and importing the same file again should update only
        newer and on equal modified date but drop the change when it is older.
        """
        self.portal.invokeFactory('Folder', 'impfolder4')
        impfolder = self.portal.impfolder4

        directory = os.path.dirname(__file__)
        with open(os.path.join(directory, 'icaltest.ics'), 'rb') as icsfile:
            icsdata1 = icsfile.read()

        with open(os.path.join(directory, 'icaltest2.ics'), 'rb') as icsfile:
            icsdata2 = icsfile.read()

        res = ical_import(impfolder, icsdata1, self.event_type)
        self.assertEqual(res['count'], 5)

        e1a = IEventAccessor(impfolder.e1)
        mod1 = e1a.last_modified
        suid1 = e1a.sync_uid
        title1 = e1a.title
        desc1 = e1a.description
        start1 = e1a.start
        end1 = e1a.end

        res = ical_import(impfolder,
                          icsdata2,
                          self.event_type,
                          sync_strategy=base.SYNC_KEEP_NEWER)
        self.assertEqual(res['count'], 4)
        e1a = IEventAccessor(impfolder.e1)
        mod2 = e1a.last_modified
        suid2 = e1a.sync_uid
        title2 = e1a.title
        desc2 = e1a.description
        start2 = e1a.start
        end2 = e1a.end

        self.assertEqual(len(impfolder.contentIds()), 5)

        self.assertTrue(mod1 < mod2)
        self.assertEqual(suid1, suid2)
        self.assertNotEqual(title1, title2)
        self.assertNotEqual(desc1, desc2)
        self.assertTrue(start1 < start2)
        self.assertTrue(end1 < end2)
コード例 #22
0
def construct_icalendar(context, events):
    """Returns an icalendar.Calendar object.

    :param context: A content object, which is used for calendar details like
                    Title and Description. Usually a container, collection or
                    the event itself.

    :param events: The list of event objects, which are included in this
                   calendar.
    """
    cal = icalendar.Calendar()
    cal.add('prodid', PRODID)
    cal.add('version', VERSION)

    cal_tz = default_timezone(context)
    if cal_tz:
        cal.add('x-wr-timezone', cal_tz)

    tzmap = {}
    if not hasattr(events, '__getslice__'):  # LazyMap doesn't have __iter__
        events = [events]
    for event in events:
        if ICatalogBrain.providedBy(event) or\
                IContentListingObject.providedBy(event):
            event = event.getObject()
        acc = IEventAccessor(event)
        tz = acc.timezone
        # TODO: the standard wants each recurrence to have a valid timezone
        # definition. sounds decent, but not realizable.
        if not acc.whole_day:  # whole day events are exported as dates without
            # timezone information
            tzmap = add_to_zones_map(tzmap, tz, acc.start)
            tzmap = add_to_zones_map(tzmap, tz, acc.end)
        cal.add_component(IICalendarEventComponent(event).to_ical())

    for (tzid, transitions) in tzmap.items():
        cal_tz = icalendar.Timezone()
        cal_tz.add('tzid', tzid)
        cal_tz.add('x-lic-location', tzid)

        for (transition, tzinfo) in transitions.items():

            if tzinfo['dst']:
                cal_tz_sub = icalendar.TimezoneDaylight()
            else:
                cal_tz_sub = icalendar.TimezoneStandard()

            cal_tz_sub.add('tzname', tzinfo['name'])
            cal_tz_sub.add('dtstart', transition)
            cal_tz_sub.add('tzoffsetfrom', tzinfo['tzoffsetfrom'])
            cal_tz_sub.add('tzoffsetto', tzinfo['tzoffsetto'])
            # TODO: add rrule
            # tzi.add('rrule',
            #         {'freq': 'yearly', 'bymonth': 10, 'byday': '-1su'})
            cal_tz.add_component(cal_tz_sub)
        cal.add_component(cal_tz)

    return cal
コード例 #23
0
ファイル: content.py プロジェクト: tsimkins/agsci.common
def onEventsFolderCreate(context, event, sample=True):

    # restrict what this folder can contain
    behavior = ISelectableConstrainTypes(context)
    behavior.setConstrainTypesMode(constrains.ENABLED)
    behavior.setImmediatelyAddableTypes(['Event'])
    behavior.setLocallyAllowedTypes(['Event', 'Collection'])

    # Create sample event and set publishing date to 01-01-YYYY
    if sample:

        # Calculate dates
        now = DateTime()
        start_date = DateTime() + 30
        end_date = start_date + 1.0 / 24

        item = createContentInContainer(context,
                                        "Event",
                                        id="sample",
                                        title="Sample Event",
                                        description="This is a sample Event",
                                        checkConstraints=False)

        item.text = RichTextValue(raw='<p>You may delete this item</p>',
                                  mimeType=u'text/html',
                                  outputMimeType='text/x-html-safe')

        item.setEffectiveDate(now)

        acc = IEventAccessor(item)
        acc.start = localize(start_date)
        acc.end = localize(end_date)

    # create 'upcoming' collection
    if 'upcoming' not in context.objectIds():
        item = createContentInContainer(
            context,
            "Collection",
            id="upcoming",
            title='Upcoming Events',
        )

        item.setQuery([{
            u'i': u'path',
            u'o': u'plone.app.querystring.operation.string.absolutePath',
            u'v': u'%s::1' % context.UID()
        }, {
            u'i': u'portal_type',
            u'o': u'plone.app.querystring.operation.selection.any',
            u'v': [u'Event']
        }])

        item.setSort_on('start')

    # Set default page to the latest news collection
    context.setDefaultPage('upcoming')
コード例 #24
0
def ticket_title_generator(obj):
    """Generate a title for the ticket, also using event information.
    """

    event = obj
    ret = {
        'title': obj.title,
        'eventtitle': '',
        'eventstart': '',
        'eventend': ''
    }

    if ITicketOccurrence.providedBy(event):
        event = aq_parent(aq_parent(event))
        # Traverse to the Occurrence object
        if IATEvent.providedBy(event):
            # get the request out of thin air to be able to publishTraverse to
            # the transient Occurrence object.
            traverser = OccTravAT(event, getRequest())
        elif IDXEvent.providedBy(event):
            # TODO
            traverser = OccTravDX(event, getRequest())
        else:
            raise NotImplementedError(
                u"There is no event occurrence traverser implementation for "
                u"this kind of object.")
        try:
            event = traverser.publishTraverse(getRequest(), obj.id)
        except KeyError:
            # Maybe the ticket occurrence isn't valid anymore because the
            # event occurence doesn't exist anymore.
            # Just ignore that case.
            return ret

    elif ITicket.providedBy(event):
        event = aq_parent(event)

    if IEvent.providedBy(event) or IOccurrence.providedBy(event):
        acc = IEventAccessor(event)
        lstart = ulocalized_time(DT(acc.start),
                                 long_format=True,
                                 context=event)
        lend = ulocalized_time(DT(acc.start), long_format=True, context=event)
        # XXX: no unicode, store as utf-8 encoded string instead
        ret = dict(
            title=u'%s - %s (%s - %s)' % (
                safe_unicode(acc.title),
                safe_unicode(obj.title),
                lstart,
                lend,
            ),
            eventtitle=acc.title,
            eventstart=acc.start,
            eventend=acc.end,
        )
    return ret
コード例 #25
0
    def test_event_summary_occurrences_whole_day(self):
        self.portal['daily'].whole_day = True

        date = patched_now()
        with mock.patch('plone.app.event.dx.behaviors.localized_now',
                        return_value=date):
            view = zope.component.getMultiAdapter(
                (self.portal['daily'], self.request), name='event_summary')
            # altogether 4 occurrences, start occurrence is included
            self.assertEqual(4, len(view.next_occurrences))
            for occurrence in view.next_occurrences:
                event_occ = IEventAccessor(occurrence)
                self.assertEqual(event_occ.start.hour, 0)
                self.assertEqual(event_occ.end.hour, 23)
                self.assertEqual(event_occ.start.day, event_occ.end.day)

        IAnnotations(self.request).clear()  # clear cache
        next_date = patched_now() + datetime.timedelta(hours=24)
        with mock.patch('plone.app.event.dx.behaviors.localized_now',
                        return_value=next_date):
            view = zope.component.getMultiAdapter(
                (self.portal['daily'], self.request), name='event_summary')
            # 3 occurrences remaining
            self.assertEqual(3, len(view.next_occurrences))
            for occurrence in view.next_occurrences:
                event_occ = IEventAccessor(occurrence)
                self.assertEqual(event_occ.start.hour, 0)
                self.assertEqual(event_occ.end.hour, 23)
                self.assertEqual(event_occ.start.day, event_occ.end.day)

        IAnnotations(self.request).clear()  # clear cache
        next_date = patched_now() + datetime.timedelta(days=10)
        with mock.patch('plone.app.event.dx.behaviors.localized_now',
                        return_value=next_date):
            view = zope.component.getMultiAdapter(
                (self.portal['daily'], self.request), name='event_summary')
            # no occurrences remaining, show all original 4
            self.assertEqual(4, len(view.next_occurrences))
            for occurrence in view.next_occurrences:
                event_occ = IEventAccessor(occurrence)
                self.assertEqual(event_occ.start.hour, 0)
                self.assertEqual(event_occ.end.hour, 23)
                self.assertEqual(event_occ.start.day, event_occ.end.day)
コード例 #26
0
def _obj_or_acc(obj, ret_mode):
    """Return the content object or an IEventAccessor wrapper, depending on
    ret_mode. ret_mode 2 returns objects, ret_mode 3 returns IEventAccessor
    object wrapper. ret_mode 1 is not supported.
    """
    assert (ret_mode is not RET_MODE_BRAINS)
    if ret_mode == RET_MODE_OBJECTS:
        return obj
    elif ret_mode == RET_MODE_ACCESSORS:
        return IEventAccessor(obj)
コード例 #27
0
 def publishTraverse(self, request, name):
     context = self.context
     dateobj = guess_date_from(name, context)
     if dateobj:
         occurrence = IRecurrenceSupport(context).occurrences(
             range_start=dateobj)[0]
         occ_acc = IEventAccessor(occurrence)
         if is_same_day(dateobj, occ_acc.start):
             return occurrence
     return self.fallbackTraverse(request, name)
コード例 #28
0
def get_recurring_events(request, event):
    e = IEventAccessor(event)
    if isinstance(e.start, datetime):
        tz = e.start.tzinfo
        start = datetime.fromtimestamp(request.get('start')).replace(tzinfo=tz)
        end = datetime.fromtimestamp(request.get('end')).replace(tzinfo=tz)
    else:
        start = pydt(DateTime(request.get('start')))
        end = pydt(DateTime(request.get('end')))
    events = IRecurrenceSupport(event).occurrences(range_start=start,
                                                   range_end=end)
    return events
コード例 #29
0
ファイル: recurrence.py プロジェクト: serge73/plone.app.event
 def publishTraverse(self, request, name):
     context = self.context
     dateobj = guess_date_from(name, context)
     if dateobj:
         occs = IRecurrenceSupport(context).occurrences(range_start=dateobj)
         try:
             occurrence = occs.next()
             occ_acc = IEventAccessor(occurrence)
             if is_same_day(dateobj, occ_acc.start):
                 return occurrence
         except StopIteration:
             pass
     return self.fallbackTraverse(request, name)
コード例 #30
0
ファイル: recurrence.py プロジェクト: serge73/plone.app.event
    def occurrences(self, range_start=None, range_end=None):
        """Return all occurrences of an event, possibly within a start and end
        limit.

        :param range_start: Optional start datetime, from which you want
                            occurrences be returned.
        :type range_start: Python datetime
        :param range_end: Optional start datetime, from which you want
                          occurrences be returned.
        :type range_end: Python datetime
        :returns: List of occurrences, including the start event.
        :rtype: IEvent or IOccurrence based objects

        Please note: Events beginning before range_start but ending afterwards
                     won't be found.

        TODO: really?

        TODO: test with event start = 21st feb, event end = start+36h,
        recurring for 10 days, range_start = 1st mar, range_end = last Mark
        """
        event = IEventAccessor(self.context)

        # We get event ends by adding a duration to the start. This way, we
        # prevent that the start and end lists are of different size if an
        # event starts before range_start but ends afterwards.
        duration = event.duration

        starts = recurrence_sequence_ical(event.start,
                                          recrule=event.recurrence,
                                          from_=range_start,
                                          until=range_end,
                                          duration=duration)

        # XXX potentially occurrence won't need to be wrapped anymore
        # but doing it for backwards compatibility as views/templates
        # still rely on acquisition-wrapped objects.
        def get_obj(start):
            if pydt(event.start.replace(microsecond=0)) == start:
                # If the occurrence date is the same as the event object, the
                # occurrence is the event itself. return it as such.
                # Dates from recurrence_sequence_ical are explicitly without
                # microseconds, while event.start may contain it. So we have to
                # remove it for a valid comparison.
                return self.context
            return Occurrence(id=str(start.date()),
                              start=start,
                              end=start + duration).__of__(self.context)

        for start in starts:
            yield get_obj(start)