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.Resources import getEventsUsingParameters 12 from EventAggregatorSupport.View import View, getQualifiedParameter 13 from MoinDateSupport import getFormDate, getFormMonth, \ 14 getParameterDate, getParameterMonth 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 mode = None 89 name_usage = "weekly" 90 calendar_name = None 91 template_name = getattr(request.cfg, "event_aggregator_new_event_template", "EventTemplate") 92 parent_name = None 93 map_name = None 94 95 for arg in parsed_args: 96 if arg.startswith("start="): 97 raw_calendar_start = arg[6:] 98 99 elif arg.startswith("end="): 100 raw_calendar_end = arg[4:] 101 102 elif arg.startswith("mode="): 103 mode = arg[5:] 104 105 elif arg.startswith("names="): 106 name_usage = arg[6:] 107 108 elif arg.startswith("calendar="): 109 calendar_name = arg[9:] 110 111 elif arg.startswith("template="): 112 template_name = arg[9:] 113 114 elif arg.startswith("parent="): 115 parent_name = arg[7:] 116 117 elif arg.startswith("map="): 118 map_name = arg[4:] 119 120 elif arg.startswith("source="): 121 remote_sources.append(arg[7:]) 122 123 elif arg.startswith("search="): 124 search_pattern = arg[7:] 125 126 else: 127 category_names.append(arg) 128 129 # Find request parameters to override settings. 130 131 mode = getQualifiedParameter(request, calendar_name, "mode", mode or "calendar") 132 133 # Different modes require different levels of precision by default. 134 135 resolution = getQualifiedParameter(request, calendar_name, "resolution", mode == "day" and "date" or "month") 136 resolution = mode == "calendar" and "month" or resolution 137 138 if resolution == "date": 139 get_date = getParameterDate 140 get_form_date = getFormDate 141 else: 142 get_date = getParameterMonth 143 get_form_date = getFormMonth 144 145 # Determine the limits of the calendar. 146 147 original_calendar_start = calendar_start = get_date(raw_calendar_start) 148 original_calendar_end = calendar_end = get_date(raw_calendar_end) 149 150 calendar_start = get_form_date(request, calendar_name, "start") or calendar_start 151 calendar_end = get_form_date(request, calendar_name, "end") or calendar_end 152 153 wider_calendar_start = getFormMonth(request, calendar_name, "wider-start") 154 wider_calendar_end = getFormMonth(request, calendar_name, "wider-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, resolution, name_usage, map_name) 171 172 return view.render(all_shown_events) 173 174 # vim: tabstop=4 expandtab shiftwidth=4