1 # -*- coding: iso-8859-1 -*- 2 """ 3 MoinMoin - EventAggregator Macro 4 5 @copyright: 2008, 2009, 2010, 2011, 2012 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 wikiutil 12 from EventAggregatorSupport import * 13 14 Dependencies = ['pages'] 15 16 # Macro functions. 17 18 def execute(macro, args): 19 20 """ 21 Execute the 'macro' with the given 'args': an optional list of selected 22 category names (categories whose pages are to be shown), together with 23 optional named arguments of the following forms: 24 25 start=YYYY-MM shows event details starting from the specified month 26 start=YYYY-MM-DD shows event details starting from the specified day 27 start=current-N shows event details relative to the current month 28 (or relative to the current day in "day" mode) 29 end=YYYY-MM shows event details ending at the specified month 30 end=YYYY-MM-DD shows event details ending on the specified day 31 end=current+N shows event details relative to the current month 32 (or relative to the current day in "day" mode) 33 34 mode=calendar shows a calendar view of events 35 mode=day shows a calendar day view of events 36 mode=list shows a list of events by month 37 mode=table shows a table of events 38 mode=map shows a map of events 39 40 calendar=NAME uses the given NAME to provide request parameters which 41 can be used to control the calendar view 42 43 template=PAGE uses the given PAGE as the default template for new 44 events (or the default template from the configuration 45 if not specified) 46 47 parent=PAGE uses the given PAGE as the parent of any new event page 48 49 Calendar view options: 50 51 names=daily shows the name of an event on every day of that event 52 names=weekly shows the name of an event once per week 53 54 Map view options: 55 56 map=NAME uses the given NAME as the map image, where an entry for 57 the map must be found in the EventMaps page (or another 58 page specified in the configuration by the 59 'event_aggregator_maps_page' setting) along with an 60 attached map image 61 """ 62 63 request = macro.request 64 fmt = macro.formatter 65 page = fmt.page 66 67 # Interpret the arguments. 68 69 try: 70 parsed_args = args and wikiutil.parse_quoted_separated(args, name_value=False) or [] 71 except AttributeError: 72 parsed_args = args.split(",") 73 74 parsed_args = [arg for arg in parsed_args if arg] 75 76 # Get special arguments. 77 78 category_names = [] 79 remote_sources = [] 80 raw_calendar_start = None 81 raw_calendar_end = None 82 calendar_start = None 83 calendar_end = None 84 mode = None 85 name_usage = "weekly" 86 calendar_name = None 87 template_name = getattr(request.cfg, "event_aggregator_new_event_template", "EventTemplate") 88 parent_name = None 89 map_name = None 90 91 for arg in parsed_args: 92 if arg.startswith("start="): 93 raw_calendar_start = arg[6:] 94 95 elif arg.startswith("end="): 96 raw_calendar_end = arg[4:] 97 98 elif arg.startswith("mode="): 99 mode = arg[5:] 100 101 elif arg.startswith("names="): 102 name_usage = arg[6:] 103 104 elif arg.startswith("calendar="): 105 calendar_name = arg[9:] 106 107 elif arg.startswith("template="): 108 template_name = arg[9:] 109 110 elif arg.startswith("parent="): 111 parent_name = arg[7:] 112 113 elif arg.startswith("map="): 114 map_name = arg[4:] 115 116 elif arg.startswith("source="): 117 remote_sources.append(arg[7:]) 118 119 else: 120 category_names.append(arg) 121 122 # Find request parameters to override settings. 123 124 mode = getQualifiedParameter(request, calendar_name, "mode", mode or "calendar") 125 126 # Different modes require different levels of precision by default. 127 128 resolution = getQualifiedParameter(request, calendar_name, "resolution", mode == "day" and "date" or "month") 129 resolution = mode == "calendar" and "month" or resolution 130 131 if resolution == "date": 132 get_date = getParameterDate 133 get_form_date = getFormDate 134 else: 135 get_date = getParameterMonth 136 get_form_date = getFormMonth 137 138 # Determine the limits of the calendar. 139 140 original_calendar_start = calendar_start = get_date(raw_calendar_start) 141 original_calendar_end = calendar_end = get_date(raw_calendar_end) 142 143 calendar_start = get_form_date(request, calendar_name, "start") or calendar_start 144 calendar_end = get_form_date(request, calendar_name, "end") or calendar_end 145 146 # Get the events according to the resolution of the calendar. 147 148 pages = getPagesFromResults(getAllCategoryPages(category_names, request), request) 149 events = getEventsFromResources(getEventPages(pages)) 150 events += getEventsFromResources(getEventResources(remote_sources, calendar_start, calendar_end, request)) 151 all_shown_events = getEventsInPeriod(events, getCalendarPeriod(calendar_start, calendar_end)) 152 earliest, latest = getEventLimits(all_shown_events) 153 154 # Get a concrete period of time. 155 156 first, last = getConcretePeriod(calendar_start, calendar_end, earliest, latest, resolution) 157 158 # Define a view of the calendar, retaining useful navigational information. 159 160 view = View(page, calendar_name, raw_calendar_start, raw_calendar_end, 161 original_calendar_start, original_calendar_end, calendar_start, calendar_end, 162 first, last, category_names, remote_sources, template_name, parent_name, 163 mode, resolution, name_usage, map_name) 164 165 return view.render(all_shown_events) 166 167 # vim: tabstop=4 expandtab shiftwidth=4