Esempio n. 1
0
def prepare_for_display(context, start, end, whole_day):
    """ Return a dictionary containing pre-calculated information for building
    <start>-<end> date strings.

    Keys are:
        'start_date' - date string of the start date
        'start_time' - time string of the start date
        'end_date'   - date string of the end date
        'end_time'   - time string of the end date
        'start_iso'  - start date in iso format
        'end_iso'    - end date in iso format
        'same_day'   - event ends on the same day
        'same_time'  - event ends at same time


    The behavior os ulocalized_time() with time_only is odd.
    Setting time_only=False should return the date part only and *not*
    the time

    >>> from DateTime import DateTime
    >>> start = DateTime(2010,3,16,14,40)
    >>> from zope.componen.hooks import getSite
    >>> site = getSite()
    >>> ulocalized_time(start, False,  time_only=True, context=site)
    u'14:40'
    >>> ulocalized_time(start, False,  time_only=False, context=site)
    u'14:40'
    >>> ulocalized_time(start, False,  time_only=None, context=site)
    u'16.03.2010'

    """

    # this needs to separate date and time as ulocalized_time does
    DT_start = DT(start)
    DT_end = DT(end)
    start_date = ulocalized_time(
            DT_start, long_format=False, time_only=None, context=context)
    start_time = ulocalized_time(
            DT_start, long_format=False, time_only=True, context=context)
    end_date = ulocalized_time(
            DT_end, long_format=False, time_only=None, context=context)
    end_time = ulocalized_time(
            DT_end, long_format=False, time_only=True, context=context)

    same_day = is_same_day(start, end)
    same_time = is_same_time(start, end)

    # set time fields to None for whole day events
    if whole_day:
        start_time = end_time = None

    return dict(start_date=start_date,
                 start_time=start_time,
                 start_iso=start.isoformat(),
                 end_date=end_date,
                 end_time=end_time,
                 end_iso=end.isoformat(),
                 same_day=same_day,
                 same_time=same_time)
Esempio n. 2
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)
Esempio n. 3
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)
Esempio n. 4
0
 def publishTraverse(self, request, name):
     dateobj = guess_date_from(name, self.context)
     if dateobj:
         occurrence = IRecurrenceSupport(self.context).occurrences(
             range_start=dateobj)[0]
         occ_acc = IEventAccessor(occurrence)
         if is_same_day(dateobj, occ_acc.start):
             return occurrence
     # No self.fallback to avoid circular call from ImageTraverser
     return super(OccurrenceTraverser, self).publishTraverse(request, name)
Esempio n. 5
0
 def publishTraverse(self, request, name):
     # TODO: here is something odd....
     #       called every time, when an attribute is traversed/accessed?
     dateobj = guess_date_from(name, self.context)
     if dateobj:
         occurrence = IRecurrenceSupport(self.context).occurrences(
             range_start=dateobj)[0]
         occ_acc = IEventAccessor(occurrence)
         if is_same_day(dateobj, occ_acc.start):
             return occurrence
     return self.fallback(name)
def prepare_for_display(context, start, end, whole_day):
    """ Return a dictionary containing pre-calculated information for building
    <start>-<end> date strings.

    Keys are:
        'start_date' - date string of the start date
        'start_time' - time string of the start date
        'end_date'   - date string of the end date
        'end_time'   - time string of the end date
        'start_iso'  - start date in iso format
        'end_iso'    - end date in iso format
        'same_day'   - event ends on the same day
        'same_time'  - event ends at same time
    """

    # The behavior os ulocalized_time() with time_only is odd.
    # Setting time_only=False should return the date part only and *not*
    # the time
    #
    # ulocalized_time(event.start(), False,  time_only=True, context=event)
    # u'14:40'
    # ulocalized_time(event.start(), False,  time_only=False, context=event)
    # u'14:40'
    # ulocalized_time(event.start(), False,  time_only=None, context=event)
    # u'16.03.2010'

    # this needs to separate date and time as ulocalized_time does
    DT_start = DT(start)
    DT_end = DT(end)
    start_date = ulocalized_time(DT_start, long_format=False, time_only=None,
                                 context=context)
    start_time = ulocalized_time(DT_start, long_format=False, time_only=True,
                                 context=context)
    end_date = ulocalized_time(DT_end, long_format=False, time_only=None,
                               context=context)
    end_time = ulocalized_time(DT_end, long_format=False, time_only=True,
                               context=context)
    same_day = is_same_day(start, end)
    same_time = is_same_time(start, end)

    # set time fields to None for whole day events
    if whole_day:
        start_time = end_time = None

    return  dict(start_date=start_date,
                 start_time=start_time,
                 start_iso=start.isoformat(),
      
           end_date=end_date,
                 end_time=end_time,
                 end_iso=end.isoformat(),
                 same_day=same_day,
                 same_time=same_time)
Esempio n. 7
0
 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)
Esempio n. 8
0
 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)
Esempio n. 9
0
def dates_for_display(occurrence):
    """ Return a dictionary containing pre-calculated information for building
    <start>-<end> date strings.

    Keys are:
        'start_date' - date string of the start date
        'start_time' - time string of the start date
        'end_date'   - date string of the end date
        'end_time'   - time string of the end date
        'start_iso'  - start date in iso format
        'end_iso'    - end date in iso format
        'same_day'   - event ends on the same day
        'same_time'  - event ends at same time
        'whole_day'  - whole day events
        'open_end'   - events without end time

    :param occurrence: Event or occurrence object.
    :type occurrence: IEvent, IOccurrence or IEventAccessor based object.
    :returns: Dictionary with date strings.
    :rtype: dict


    The behavior os ulocalized_time() with time_only is odd.
    Setting time_only=False should return the date part only and *not*
    the time

    NOTE: these tests are not run, but serve as documentation.
    TODO: remove.
    >>> from DateTime import DateTime
    >>> start = DateTime(2010,3,16,14,40)
    >>> from zope.component.hooks import getSite
    >>> site = getSite()
    >>> ulocalized_time(start, False,  time_only=True, context=site)
    u'14:40'
    >>> ulocalized_time(start, False,  time_only=False, context=site)
    u'14:40'
    >>> ulocalized_time(start, False,  time_only=None, context=site)
    u'16.03.2010'

    """
    if IEventAccessor.providedBy(occurrence):
        acc = occurrence
        occurrence = occurrence.context
    else:
        acc = IEventAccessor(occurrence)

    if acc.start is None or acc.end is None:
        # Eventually optional start/end dates from a potentially Event.
        return None

    # this needs to separate date and time as ulocalized_time does
    DT_start = DT(acc.start)
    DT_end = DT(acc.end)
    start_date = ulocalized_time(DT_start,
                                 long_format=False,
                                 time_only=None,
                                 context=occurrence)
    start_time = ulocalized_time(DT_start,
                                 long_format=False,
                                 time_only=True,
                                 context=occurrence)
    end_date = ulocalized_time(DT_end,
                               long_format=False,
                               time_only=None,
                               context=occurrence)
    end_time = ulocalized_time(DT_end,
                               long_format=False,
                               time_only=True,
                               context=occurrence)

    same_day = is_same_day(acc.start, acc.end)
    same_time = is_same_time(acc.start, acc.end)

    # set time fields to None for whole day events
    if acc.whole_day:
        start_time = end_time = None
    if acc.open_end:
        end_time = None

    start_iso = acc.whole_day and acc.start.date().isoformat()\
        or acc.start.isoformat()
    end_iso = acc.whole_day and acc.end.date().isoformat()\
        or acc.end.isoformat()

    return dict(
        # Start
        start_date=start_date,
        start_time=start_time,
        start_iso=start_iso,

        # End
        end_date=end_date,
        end_time=end_time,
        end_iso=end_iso,

        # Meta
        same_day=same_day,
        same_time=same_time,
        whole_day=acc.whole_day,
        open_end=acc.open_end,
    )
Esempio n. 10
0
def dates_for_display(occurrence):
    """ Return a dictionary containing pre-calculated information for building
    <start>-<end> date strings.

    Keys are:
        'start_date' - date string of the start date
        'start_time' - time string of the start date
        'end_date'   - date string of the end date
        'end_time'   - time string of the end date
        'start_iso'  - start date in iso format
        'end_iso'    - end date in iso format
        'same_day'   - event ends on the same day
        'same_time'  - event ends at same time
        'whole_day'  - whole day events
        'open_end'   - events without end time

    :param occurrence: Event or occurrence object.
    :type occurrence: IEvent, IOccurrence or IEventAccessor based object.
    :returns: Dictionary with date strings.
    :rtype: dict


    The behavior os ulocalized_time() with time_only is odd.
    Setting time_only=False should return the date part only and *not*
    the time

    NOTE: these tests are not run, but serve as documentation.
    TODO: remove.
    >>> from DateTime import DateTime
    >>> start = DateTime(2010,3,16,14,40)
    >>> from zope.component.hooks import getSite
    >>> site = getSite()
    >>> ulocalized_time(start, False,  time_only=True, context=site)
    u'14:40'
    >>> ulocalized_time(start, False,  time_only=False, context=site)
    u'14:40'
    >>> ulocalized_time(start, False,  time_only=None, context=site)
    u'16.03.2010'

    """
    if IEventAccessor.providedBy(occurrence):
        acc = occurrence
        occurrence = occurrence.context
    else:
        acc = IEventAccessor(occurrence)

    # this needs to separate date and time as ulocalized_time does
    DT_start = DT(acc.start)
    DT_end = DT(acc.end)
    start_date = ulocalized_time(
        DT_start, long_format=False, time_only=None, context=occurrence
    )
    start_time = ulocalized_time(
        DT_start, long_format=False, time_only=True, context=occurrence
    )
    end_date = ulocalized_time(
        DT_end, long_format=False, time_only=None, context=occurrence
    )
    end_time = ulocalized_time(
        DT_end, long_format=False, time_only=True, context=occurrence
    )

    same_day = is_same_day(acc.start, acc.end)
    same_time = is_same_time(acc.start, acc.end)

    # set time fields to None for whole day events
    if acc.whole_day:
        start_time = end_time = None
    if acc.open_end:
        end_time = None

    start_iso = acc.whole_day and acc.start.date().isoformat()\
        or acc.start.isoformat()
    end_iso = acc.whole_day and acc.end.date().isoformat()\
        or acc.end.isoformat()

    return dict(
        # Start
        start_date=start_date,
        start_time=start_time,
        start_iso=start_iso,

        # End
        end_date=end_date,
        end_time=end_time,
        end_iso=end_iso,

        # Meta
        same_day=same_day,
        same_time=same_time,
        whole_day=acc.whole_day,
        open_end=acc.open_end,
    )
Esempio n. 11
0
def dates_for_display(occurrence):
    """ Return a dictionary containing pre-calculated information for building
    <start>-<end> date strings.

    Keys are:
        'start_date' - date string of the start date
        'start_time' - time string of the start date
        'end_date'   - date string of the end date
        'end_time'   - time string of the end date
        'start_iso'  - start date in iso format
        'end_iso'    - end date in iso format
        'same_day'   - event ends on the same day
        'same_time'  - event ends at same time
        'whole_day'  - whole day events
        'open_end'   - events without end time


    The behavior os ulocalized_time() with time_only is odd.
    Setting time_only=False should return the date part only and *not*
    the time

    >>> from DateTime import DateTime
    >>> start = DateTime(2010,3,16,14,40)
    >>> from zope.componen.hooks import getSite
    >>> site = getSite()
    >>> ulocalized_time(start, False,  time_only=True, context=site)
    u'14:40'
    >>> ulocalized_time(start, False,  time_only=False, context=site)
    u'14:40'
    >>> ulocalized_time(start, False,  time_only=None, context=site)
    u'16.03.2010'

    """
    acc = IEventAccessor(occurrence)

    # this needs to separate date and time as ulocalized_time does
    DT_start = DT(acc.start)
    DT_end = DT(acc.end)
    start_date = ulocalized_time(DT_start,
                                 long_format=False,
                                 time_only=None,
                                 context=occurrence)
    start_time = ulocalized_time(DT_start,
                                 long_format=False,
                                 time_only=True,
                                 context=occurrence)
    end_date = ulocalized_time(DT_end,
                               long_format=False,
                               time_only=None,
                               context=occurrence)
    end_time = ulocalized_time(DT_end,
                               long_format=False,
                               time_only=True,
                               context=occurrence)

    same_day = is_same_day(acc.start, acc.end)
    same_time = is_same_time(acc.start, acc.end)

    # set time fields to None for whole day events
    if acc.whole_day:
        start_time = end_time = None
    if acc.open_end:
        end_time = None

    return dict(
        # Start
        start_date=start_date,
        start_time=start_time,
        start_iso=acc.whole_day and acc.start.date().isoformat()\
                                 or acc.start.isoformat(),
        # End
        end_date=end_date,
        end_time=end_time,
        end_iso=acc.whole_day and acc.end.date().isoformat()\
                               or acc.end.isoformat(),
        # Meta
        same_day=same_day,
        same_time=same_time,
        whole_day=acc.whole_day,
        open_end=acc.open_end,
    )