plone.app.event.base

class plone.app.event.base.AnnotationAdapter(context)[source]

Abstract Base Class for an annotation storage.

If the annotation wasn’t set, it won’t be created until the first attempt to set a property on this adapter. So, the context doesn’t get polluted with annotations by accident.

plone.app.event.base.DT(dt, exact=False)[source]

Return a Zope DateTime instance from a Python datetime instance.

Parameters:
  • dt – Python datetime, Python date, Zope DateTime instance or string.

  • exact (Boolean) – If True, the resolution goes down to microseconds. If False, the resolution are seconds. Defaul is False.

Returns:

Zope DateTime

Return type:

Zope DateTime

class plone.app.event.base.PatchedDateTime(*args, **kw)[source]
strftime(fmt)[source]

Format the date/time using the current timezone representation.

plone.app.event.base.construct_calendar(events, start=None, end=None)[source]

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.

Parameters:
  • events (list) – List of IEvent and/or IOccurrence objects, to construct a calendar data structure from.

  • start (Python datetime or date) – An optional start range date.

  • end (Python datetime or date) – An optional start range date.

Returns:

Dictionary with isoformat date strings as keys and event occurrences as values.

Return type:

dict

plone.app.event.base.dates_for_display(occurrence)[source]

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

Parameters:

occurrence (IEvent, IOccurrence or IEventAccessor based object.) – Event or occurrence object.

Returns:

Dictionary with date strings.

Return type:

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’

plone.app.event.base.default_end(context=None)[source]

Return the default end as python datetime for prefilling forms.

Returns:

Default end datetime.

Return type:

Python datetime

plone.app.event.base.default_start(context=None)[source]

Return the default start as python datetime for prefilling forms.

Returns:

Default start datetime.

Return type:

Python datetime

plone.app.event.base.default_timezone(context=None, as_tzinfo=False)[source]

Return the timezone from the portal or user.

Parameters:
  • context (Content object) – Optional context. If not given, the current Site is used.

  • as_tzinfo (boolean) – Return the default timezone as tzinfo object.

Returns:

Timezone identifier or tzinfo object.

Return type:

string or tzinfo object

plone.app.event.base.dt_end_of_day(dt)[source]

Returns a Python datetime instance set to the end time of the given day (23:59:59).

Parameters:

dt (Python datetime) – datetime to set to the end time of the day.

Returns:

datetime set to the end time of the day (23:59:59).

Return type:

Python datetime

plone.app.event.base.dt_start_of_day(dt)[source]

Returns a Python datetime instance set to the start time of the given day (00:00:00).

Parameters:

dt (Python datetime) – datetime to set to the start time of the day.

Returns:

datetime set to the start time of the day (00:00:00).

Return type:

Python datetime

plone.app.event.base.expand_events(events, ret_mode, start=None, end=None, sort=None, sort_reverse=None)[source]

Expand to the recurrence occurrences of a given set of events.

Parameters:
  • events – IEvent based objects or IEventAccessor object wrapper.

  • ret_mode (integer [2|3]) –

    Return type of search results. These options are available:

    • 2 (objects): Return results as IEvent and/or

      IOccurrence objects.

    • 3 (accessors): Return results as IEventAccessor

      wrapper objects.

    Option “1” (brains) is not supported.

  • start (Python datetime.) – Date, from which on events should be expanded.

  • end (Python datetime) – Date, until which events should be expanded.

  • sort (string) – Object or IEventAccessor Attribute to sort on.

  • sort_reverse (boolean) – Change the order of the sorting.

plone.app.event.base.filter_and_resort(context, brains, start, end, sort, sort_reverse)[source]

#114 sorting bug is fallout from a Products.DateRecurringIndex limitation. The index contains a set of start and end dates represented as integer: that allows valid slicing of searches. However the returned brains have a .start attribute which is the start DateTime of the first occurrence of an event.

This results in mis-sorting of search results if the next occurrence of event B is after the next occurrence of event A, but the first occurrence of event B is before the first occurrence of event A. The catalog results sort that as B<A instead of A<B.

This method works around that issue by extracting all occurrence start/end from the index, and then sorting on the actual next start/end.

For ongoing events which have an occurrence starting in the past but ending in the future, the past start of that ongoing occurrence is selected, so this will show up right at the start of the result.

Parameters:
  • context (Content object) – [required] A context object.

  • brains (catalog brains) – [required] catalog brains

  • start (Python datetime.) – [required] min end datetime (sic!)

  • end – [required] max start datetime (sic!)

  • sort_reverse (boolean) – Change the order of the sorting.

  • sort ('start' or 'end') – Which field to sort on

Returns:

catalog brains

Return type:

catalog brains

plone.app.event.base.find_context(context, viewname=None, iface=None, as_url=False, append_view=True)[source]

Find the next context with a given view name or interface, up in the content tree, starting from the given context. This might not be the IPloneSiteRoot, but another subsite.

Parameters:
  • context – The context to start the search from.

  • viewname – (optional) The name of a view which a context should have configured as defaultView.

  • iface – (optional) The interface, the context to search for should implement.

  • as_url – (optional) Return the URL of the context found.

  • append_view – (optional) In case of a given viewname and called with as_url, append the viewname to the url, if the context hasn’t configured it as defaultView. Otherwise ignore this parameter.

Returns:

A context with the given view name, inteface or ISite root.

plone.app.event.base.first_weekday()[source]

Returns the number of the first Weekday in a Week, as defined in the registry. 0 is Monday, 6 is Sunday, as expected by Python’s datetime.

PLEASE NOTE: strftime %w interprets 0 as Sunday unlike the calendar module!

Returns:

Index of first weekday [0(Monday)..6(Sunday)]

Return type:

integer

plone.app.event.base.get_events(context, start=None, end=None, limit=None, ret_mode=1, expand=False, sort='start', sort_reverse=False, **kw)[source]

Return all events as catalog brains, possibly within a given timeframe.

Parameters:
  • context (Content object) – [required] A context object.

  • start (Python datetime.) – Date, from which on events should be searched.

  • end (Python datetime) – Date, until which events should be searched.

  • limit (integer) – Number of items to be returned.

  • ret_mode (integer [1|2|3]) –

    Return type of search results. These options are available:

    • 1 (brains): Return results as catalog brains.

    • 2 (objects): Return results as IEvent and/or

      IOccurrence objects.

    • 3 (accessors): Return results as IEventAccessor

      wrapper objects.

  • expand (boolean) – Expand the results to all occurrences (within a timeframe, if given). With this option set to True, the resultset also includes the event’s recurrence occurrences and is sorted by the start date. Only available in ret_mode 2 (objects) and 3 (accessors).

  • sort (string) – Catalog index id to sort on.

  • sort_reverse (boolean) – Change the order of the sorting.

Returns:

Portal events, matching the search criteria.

Return type:

catalog brains, event objects or IEventAccessor object wrapper, depending on ret_mode.

plone.app.event.base.guess_date_from(datestr, context=None)[source]

Returns a timezone aware date object if an arbitrary ASCII string is formatted in an ISO date format, otherwise None is returned.

Used for traversing and Occurence ids.

Parameters:
  • datestr (string) – Date string in an ISO format.

  • context (Content object) – Context object (for retrieving the timezone).

Returns:

Localized date object.

Return type:

Python date

plone.app.event.base.localized_now(context=None)[source]

Return the current datetime localized to the default timezone.

Parameters:

context (Content object) – Context object.

Returns:

Localized current datetime.

Return type:

Python datetime

plone.app.event.base.localized_today(context=None)[source]

Return the current date localized to the default timezone.

Parameters:

context (Content object) – Context object.

Returns:

Localized current date.

Return type:

Python date

plone.app.event.base.spell_date(dt, translation_context=None)[source]

Return a dictionary with localized and readable formatted date parts.

plone.app.event.base.start_end_from_mode(mode, dt=None, context=None)[source]

Return a start and end date from a given mode string, like “today”, “past” or “future”. This can be used in event retrieval functions.

Parameters:
  • mode (string) –

    One of the following modes:

    ’all’ Show all events. ‘past’: Show only past events with descending sorting. ‘future’: Show only future events (default). ‘today’: Show todays events. ‘now’: Show todays upcoming events. ‘7days’: Show events until 7 days in future. ‘day’: Return all events on the given day (dt parameter

    required)

    ’week’: Show a weeks events, optionally from a given date.

    These settings override the start and end parameters.

    Not implemented yet:

    ’month’: Show this month’s events.

  • dt (Python datetime) – Optional datetime for day mode.

plone.app.event.base.start_end_query(start, end)[source]

Make a catalog query out of start and end dates.

plone.app.event.base.ulocalized_time(time, *args, **kwargs)[source]

Corrects for DateTime bugs doing wrong thing with timezones

plone.app.event.base.wkday_to_mon0(day)[source]

Converts an integer weekday number to a representation where Monday is 0 and Sunday is 6 (the datetime default), from a representation where Sunday is 0, Monday is 1 and Saturday is 6 (the strftime behavior).

Parameters:

day (integer) – The weekday number [0(Sunday)..6]

Returns:

The weekday number [0(Monday)..6]

Return type:

integer

plone.app.event.base.wkday_to_mon1(day)[source]

Converts an integer weekday number to a representation where Monday is 1, Saturday is 6 and Sunday is 0 (the strftime behavior), from a representation where Monday is 0 and Sunday is 6 (the datetime default).

Parameters:

day (integer) – The weekday number [0(Monday)..6]

Returns:

The weekday number [0(Sunday)..6]

Return type:

integer