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