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 search_pattern = None 81 raw_calendar_start = None 82 raw_calendar_end = None 83 calendar_start = None 84 calendar_end = None 85 mode = None 86 name_usage = "weekly" 87 calendar_name = None 88 template_name = getattr(request.cfg, "event_aggregator_new_event_template", "EventTemplate") 89 parent_name = None 90 map_name = None 91 92 for arg in parsed_args: 93 if arg.startswith("start="): 94 raw_calendar_start = arg[6:] 95 96 elif arg.startswith("end="): 97 raw_calendar_end = arg[4:] 98 99 elif arg.startswith("mode="): 100 mode = arg[5:] 101 102 elif arg.startswith("names="): 103 name_usage = arg[6:] 104 105 elif arg.startswith("calendar="): 106 calendar_name = arg[9:] 107 108 elif arg.startswith("template="): 109 template_name = arg[9:] 110 111 elif arg.startswith("parent="): 112 parent_name = arg[7:] 113 114 elif arg.startswith("map="): 115 map_name = arg[4:] 116 117 elif arg.startswith("source="): 118 remote_sources.append(arg[7:]) 119 120 elif arg.startswith("search="): 121 search_pattern = arg[7:] 122 123 else: 124 category_names.append(arg) 125 126 # Find request parameters to override settings. 127 128 mode = getQualifiedParameter(request, calendar_name, "mode", mode or "calendar") 129 130 # Different modes require different levels of precision by default. 131 132 resolution = getQualifiedParameter(request, calendar_name, "resolution", mode == "day" and "date" or "month") 133 resolution = mode == "calendar" and "month" or resolution 134 135 if resolution == "date": 136 get_date = getParameterDate 137 get_form_date = getFormDate 138 else: 139 get_date = getParameterMonth 140 get_form_date = getFormMonth 141 142 # Determine the limits of the calendar. 143 144 original_calendar_start = calendar_start = get_date(raw_calendar_start) 145 original_calendar_end = calendar_end = get_date(raw_calendar_end) 146 147 calendar_start = get_form_date(request, calendar_name, "start") or calendar_start 148 calendar_end = get_form_date(request, calendar_name, "end") or calendar_end 149 150 wider_calendar_start = getFormMonth(request, calendar_name, "wider-start") 151 wider_calendar_end = getFormMonth(request, calendar_name, "wider-end") 152 153 # Get the events according to the resolution of the calendar. 154 155 all_shown_events, first, last = getEventsUsingParameters( 156 category_names, search_pattern, remote_sources, calendar_start, calendar_end, 157 resolution, request) 158 159 # Define a view of the calendar, retaining useful navigational information. 160 161 view = View(page, calendar_name, 162 raw_calendar_start, raw_calendar_end, 163 original_calendar_start, original_calendar_end, 164 calendar_start, calendar_end, 165 wider_calendar_start, wider_calendar_end, 166 first, last, category_names, remote_sources, search_pattern, template_name, 167 parent_name, mode, resolution, name_usage, map_name) 168 169 return view.render(all_shown_events) 170 171 # vim: tabstop=4 expandtab shiftwidth=4