1 # -*- coding: iso-8859-1 -*- 2 """ 3 MoinMoin - EventAggregator Macro 4 5 @copyright: 2008, 2009, 2010, 2011, 2012, 2013, 2014 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 source=SOURCE uses the given SOURCE to provide events 53 54 search=SEARCH uses the given SEARCH expression to search for events 55 56 Calendar view options: 57 58 names=daily shows the name of an event on every day of that event 59 names=weekly shows the name of an event once per week 60 61 Map view options: 62 63 map=NAME uses the given NAME as the map image, where an entry for 64 the map must be found in the EventMaps page (or another 65 page specified in the configuration by the 66 'event_aggregator_maps_page' setting) along with an 67 attached map image 68 69 Request parameters configured by the calendar argument include the 70 following: 71 72 start equivalent to the above start argument 73 end equivalent to the above end argument 74 75 wider-start indicates the start of a view from a wider context 76 wider-end indicates the end of a view from a wider context 77 78 mode equivalent to the above mode argument 79 80 resolution=month indicates that dates have a month level of precision 81 resolution=date indicates that dates have a day/date level of precision 82 """ 83 84 request = macro.request 85 fmt = macro.formatter 86 page = fmt.page 87 88 # Interpret the arguments. 89 90 try: 91 parsed_args = args and wikiutil.parse_quoted_separated(args, name_value=False) or [] 92 except AttributeError: 93 parsed_args = args.split(",") 94 95 parsed_args = [arg for arg in parsed_args if arg] 96 97 # Get special arguments. 98 99 category_names = [] 100 remote_sources = [] 101 search_pattern = None 102 raw_calendar_start = None 103 raw_calendar_end = None 104 calendar_start = None 105 calendar_end = None 106 raw_mode = None 107 mode = None 108 name_usage = "weekly" 109 calendar_name = None 110 template_name = getattr(request.cfg, "event_aggregator_new_event_template", "EventTemplate") 111 parent_name = None 112 map_name = None 113 114 for arg in parsed_args: 115 if arg.startswith("start="): 116 raw_calendar_start = arg[6:] 117 118 elif arg.startswith("end="): 119 raw_calendar_end = arg[4:] 120 121 elif arg.startswith("mode="): 122 raw_mode = arg[5:] 123 124 elif arg.startswith("names="): 125 name_usage = arg[6:] 126 127 elif arg.startswith("calendar="): 128 calendar_name = arg[9:] 129 130 elif arg.startswith("template="): 131 template_name = arg[9:] 132 133 elif arg.startswith("parent="): 134 parent_name = arg[7:] 135 136 elif arg.startswith("map="): 137 map_name = arg[4:] 138 139 elif arg.startswith("source="): 140 remote_sources.append(arg[7:]) 141 142 elif arg.startswith("search="): 143 search_pattern = arg[7:] 144 145 else: 146 category_names.append(arg) 147 148 # Find request parameters to override settings. 149 150 mode = getQualifiedParameter(request, calendar_name, "mode", raw_mode or "calendar") 151 152 # Different modes require different levels of precision by default. 153 154 raw_resolution = raw_mode == "day" and "date" or "month" 155 156 resolution = getQualifiedParameter(request, calendar_name, "resolution", mode == "day" and "date" or "month") 157 resolution = mode == "calendar" and "month" or resolution 158 159 # Determine the limits of the calendar. 160 161 get_date, get_form_date = get_date_functions(raw_resolution) 162 163 original_calendar_start = calendar_start = get_date(raw_calendar_start) 164 original_calendar_end = calendar_end = get_date(raw_calendar_end) 165 166 wider_calendar_start = getFormMonth(request, calendar_name, "wider-start") 167 wider_calendar_end = getFormMonth(request, calendar_name, "wider-end") 168 169 get_date, get_form_date = get_date_functions(resolution) 170 171 calendar_start = get_form_date(request, calendar_name, "start") or calendar_start 172 calendar_end = get_form_date(request, calendar_name, "end") or calendar_end 173 174 # Get the events according to the resolution of the calendar. 175 176 all_shown_events, first, last = getEventsUsingParameters( 177 category_names, search_pattern, remote_sources, calendar_start, calendar_end, 178 resolution, request) 179 180 # Define a view of the calendar, retaining useful navigational information. 181 182 view = View(page, calendar_name, 183 raw_calendar_start, raw_calendar_end, 184 original_calendar_start, original_calendar_end, 185 calendar_start, calendar_end, 186 wider_calendar_start, wider_calendar_end, 187 first, last, category_names, remote_sources, search_pattern, template_name, 188 parent_name, mode, raw_resolution, resolution, name_usage, map_name) 189 190 return view.render(all_shown_events) 191 192 # vim: tabstop=4 expandtab shiftwidth=4