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