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