EventAggregator

actions/EventAggregatorSummary.py

15:4634d879b618
2009-03-26 Paul Boddie Moved week coverage calculation to the support module.
     1 # -*- coding: iso-8859-1 -*-     2 """     3     MoinMoin - EventAggregatorSummary Action     4      5     @copyright: 2008, 2009 by Paul Boddie <paul@boddie.org.uk>     6     @copyright: 2000-2004 Juergen Hermann <jh@web.de>,     7                 2005-2008 MoinMoin:ThomasWaldmann.     8     @license: GNU GPL (v2 or later), see COPYING.txt for details.     9 """    10     11 from MoinMoin import config    12 import EventAggregatorSupport    13     14 Dependencies = ['pages']    15     16 # Action function.    17     18 def execute(pagename, request):    19     20     """    21     For the given 'pagename' and 'request', write an iCalendar summary of the    22     event data found in the categories specified via the "category" request    23     parameter, using the "start" and "end" parameters (if specified). Multiple    24     "category" parameters can be specified.    25     """    26     27     category_names = request.form.get("category", [])    28     29     if request.form.has_key("start"):    30         calendar_start = EventAggregatorSupport.getMonth(request.form["start"][0])    31     else:    32         calendar_start = None    33     34     if request.form.has_key("end"):    35         calendar_end = EventAggregatorSupport.getMonth(request.form["end"][0])    36     else:    37         calendar_end = None    38     39     events, shown_events, all_shown_events, earliest, latest = \    40         EventAggregatorSupport.getEvents(request, category_names, calendar_start, calendar_end)    41     42     # Output iCalendar data...    43     44     request.emit_http_headers(["Content-Type: text/calendar; charset=%s" % config.charset])    45     46     request.write("BEGIN:VCALENDAR\r\n")    47     request.write("PRODID:-//MoinMoin//EventAggregatorSummary\r\n")    48     request.write("VERSION:2.0\r\n")    49     50     for event_page, event_details in all_shown_events:    51     52         # Get a pretty version of the page name.    53     54         pretty_pagename = EventAggregatorSupport.getPrettyPageName(event_page)    55     56         # Output the event details.    57     58         request.write("BEGIN:VEVENT\r\n")    59         request.write("SUMMARY:%s\r\n" % pretty_pagename)    60         request.write("UID:%s\r\n" % request.getQualifiedURL(event_page.url(request)))    61         request.write("URL:%s\r\n" % request.getQualifiedURL(event_page.url(request)))    62         request.write("DTSTART;VALUE=DATE:%04d%02d%02d\r\n" % event_details["start"])    63         request.write("DTEND;VALUE=DATE:%04d%02d%02d\r\n" % EventAggregatorSupport.nextdate(event_details["end"]))    64         if event_details.has_key("topics"):    65             request.write("CATEGORIES:%s\r\n" % ",".join(event_details["topics"]))    66         request.write("END:VEVENT\r\n")    67     68     request.write("END:VCALENDAR\r\n")    69     70 # vim: tabstop=4 expandtab shiftwidth=4