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