1 # -*- coding: iso-8859-1 -*- 2 """ 3 MoinMoin - EventAggregatorUpdate Action 4 5 @copyright: 2012, 2013, 2014 by Paul Boddie <paul@boddie.org.uk> 6 @license: GNU GPL (v2 or later), see COPYING.txt for details. 7 """ 8 9 from EventAggregatorSupport.Actions import get_date_functions 10 from EventAggregatorSupport import * 11 from MoinDateSupport import getParameterMonth 12 from MoinMoin.Page import Page, is_cache_exception 13 from MoinMoin import caching, config, log 14 15 logging = log.getLogger(__name__) 16 17 # Action function. 18 19 def execute(pagename, request): 20 21 """ 22 On the given 'pagename', for the given 'request', write a page fragment 23 producing the rendered calendar information for inclusion in an existing Web 24 page. Since the page is not processed, all necessary parameters need to be 25 supplied in the request. 26 """ 27 28 form = get_form(request) 29 page = Page(request, pagename) 30 31 # Attempt to get any previously cached view. 32 33 key = page.getCacheKey(request) 34 cache = caching.CacheEntry(request, page, key, scope='item') 35 36 if cache.exists(): 37 send(request, cache.content()) 38 return 39 40 # Find settings from the request parameters only. 41 42 calendar_name = form.get("calendar", [None])[0] 43 category_names = form.get("category", []) 44 search_pattern = form.get("search", [None])[0] 45 remote_sources = form.get("source", []) 46 name_usage = getParameter(request, "names", "weekly") 47 template_name = getParameter(request, "template") 48 parent_name = getParameter(request, "parent") 49 mode = getParameter(request, "mode", "calendar") 50 raw_resolution = getParameter(request, "raw-resolution") 51 resolution = getParameter(request, "resolution", mode == "day" and "date" or "month") 52 map_name = getParameter(request, "map") 53 54 # The underlying dimensions of the calendar are supplied in special 55 # parameters. 56 57 raw_calendar_start = getParameter(request, "calendarstart") 58 raw_calendar_end = getParameter(request, "calendarend") 59 60 # Different modes require different levels of precision by default. 61 62 resolution = mode == "calendar" and "month" or resolution 63 64 # Determine the limits of the calendar. 65 66 get_date, _get_form_date = get_date_functions(raw_resolution) 67 68 original_calendar_start = calendar_start = get_date(raw_calendar_start) 69 original_calendar_end = calendar_end = get_date(raw_calendar_end) 70 71 wider_calendar_start = getParameterMonth(getParameter(request, "wider-start")) 72 wider_calendar_end = getParameterMonth(getParameter(request, "wider-end")) 73 74 get_date, _get_form_date = get_date_functions(resolution) 75 76 calendar_start = get_date(getParameter(request, "start")) or calendar_start 77 calendar_end = get_date(getParameter(request, "end")) or calendar_end 78 79 # Get the events according to the resolution of the calendar. 80 81 all_shown_events, first, last = getEventsUsingParameters( 82 category_names, search_pattern, remote_sources, calendar_start, calendar_end, 83 resolution, request) 84 85 # Define a view of the calendar, retaining useful navigational information. 86 87 view = View(page, calendar_name, 88 raw_calendar_start, raw_calendar_end, 89 original_calendar_start, original_calendar_end, 90 calendar_start, calendar_end, 91 wider_calendar_start, wider_calendar_end, 92 first, last, category_names, remote_sources, search_pattern, template_name, 93 parent_name, mode, raw_resolution, resolution, name_usage, map_name) 94 95 output = view.render(all_shown_events) 96 97 # Attempt to cache the output and then send it. 98 99 try: 100 page.enforceCacheLimit(request) 101 cache.update(output.encode(config.charset)) 102 except caching.CacheError, exc: 103 logging.warning("Could not cache output for EventAggregatorUpdate in page %s: %s" % (pagename, str(exc))) 104 105 send(request, output) 106 107 def send(request, output): 108 109 "Send via the 'request' the given 'output' as a response." 110 111 send_headers = get_send_headers(request) 112 send_headers(["Content-Type: text/html; charset=%s" % config.charset]) 113 request.write(output) 114 115 # vim: tabstop=4 expandtab shiftwidth=4