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