1.1 --- a/macros/EventAggregator.py Mon Mar 23 01:52:13 2009 +0100
1.2 +++ b/macros/EventAggregator.py Tue Mar 24 01:05:50 2009 +0100
1.3 @@ -42,7 +42,25 @@
1.4 else:
1.5 return (255, 255, 255)
1.6
1.7 -# Macro function.
1.8 +# Macro functions.
1.9 +
1.10 +def getMonth(arg):
1.11 + if arg in ("current", "next", "last"):
1.12 + date = EventAggregatorSupport.getCurrentMonth()
1.13 + if arg == "next":
1.14 + date = EventAggregatorSupport.monthupdate(date, 1)
1.15 + elif arg == "last":
1.16 + date = EventAggregatorSupport.monthupdate(date, -1)
1.17 + else:
1.18 + date = EventAggregatorSupport.getMonth(arg)
1.19 + return date
1.20 +
1.21 +def getFormMonth(request, calendar_name, argname):
1.22 + arg = request.form.get("%s-%s" % (calendar_name, argname), [None])[0]
1.23 + if arg is not None:
1.24 + return getMonth(arg)
1.25 + else:
1.26 + return None
1.27
1.28 def execute(macro, args):
1.29
1.30 @@ -52,7 +70,14 @@
1.31 optional named arguments of the following forms:
1.32
1.33 start=YYYY-MM shows event details starting from the specified month
1.34 + start=current shows event details starting with the current month
1.35 + start=next shows event details starting with next month
1.36 end=YYYY-MM shows event details ending at the specified month
1.37 + end=current shows event details ending with the current month
1.38 + end=last shows event details ending with last month
1.39 + span=N shows event details for N months starting with the
1.40 + specified start month, or ending with the specified end
1.41 + month
1.42
1.43 mode=calendar shows a calendar view of events
1.44 mode=list shows a list of events by month
1.45 @@ -60,6 +85,9 @@
1.46
1.47 names=daily shows the name of an event on every day of that event
1.48 names=weekly shows the name of an event once per week
1.49 +
1.50 + calendar=NAME uses the given NAME to provide request parameters which
1.51 + can be used to control the calendar view
1.52 """
1.53
1.54 request = macro.request
1.55 @@ -81,21 +109,62 @@
1.56 category_names = []
1.57 calendar_start = None
1.58 calendar_end = None
1.59 + span = None
1.60 mode = "calendar"
1.61 name_usage = "daily"
1.62 + calendar_name = None
1.63
1.64 for arg in parsed_args:
1.65 if arg.startswith("start="):
1.66 - calendar_start = EventAggregatorSupport.getMonth(arg[6:])
1.67 + calendar_start = getMonth(arg[6:])
1.68 +
1.69 elif arg.startswith("end="):
1.70 - calendar_end = EventAggregatorSupport.getMonth(arg[4:])
1.71 + calendar_end = getMonth(arg[4:])
1.72 +
1.73 + elif arg.startswith("span="):
1.74 + span = abs(int(arg[5:]))
1.75 +
1.76 elif arg.startswith("mode="):
1.77 mode = arg[5:]
1.78 +
1.79 elif arg.startswith("names="):
1.80 name_usage = arg[6:]
1.81 +
1.82 + elif arg.startswith("calendar="):
1.83 + calendar_name = arg[9:]
1.84 +
1.85 else:
1.86 category_names.append(arg)
1.87
1.88 + # Find request parameters to override settings.
1.89 +
1.90 + if calendar_name is not None:
1.91 + new_calendar_start = getFormMonth(request, calendar_name, "start")
1.92 + new_calendar_end = getFormMonth(request, calendar_name, "end")
1.93 + if new_calendar_start is not None or new_calendar_end is not None:
1.94 + calendar_start = new_calendar_start
1.95 + calendar_end = new_calendar_end
1.96 +
1.97 + # Calculate the window of interest.
1.98 +
1.99 + if span is not None:
1.100 + if calendar_start is not None:
1.101 + calendar_end = EventAggregatorSupport.monthupdate(calendar_start, max(0, span - 1))
1.102 + elif calendar_end is not None:
1.103 + calendar_start = EventAggregatorSupport.monthupdate(calendar_end, min(0, -span + 1))
1.104 + else:
1.105 + calendar_start = EventAggregatorSupport.getCurrentMonth()
1.106 + calendar_end = EventAggregatorSupport.monthupdate(calendar_start, max(0, span - 1))
1.107 +
1.108 + # Some useful navigation months.
1.109 +
1.110 + if calendar_name is not None:
1.111 + previous_year, previous_month = EventAggregatorSupport.prevmonth(calendar_start)
1.112 + next_year, next_month = EventAggregatorSupport.nextmonth(calendar_start)
1.113 + next_set_year, next_set_month = EventAggregatorSupport.nextmonth(calendar_end)
1.114 +
1.115 + # Get the events.
1.116 +
1.117 events, shown_events, all_shown_events, earliest, latest = \
1.118 EventAggregatorSupport.getEvents(request, category_names, calendar_start, calendar_end)
1.119
1.120 @@ -125,13 +194,44 @@
1.121
1.122 output.append(fmt.table_row(on=1))
1.123 output.append(fmt.table_cell(on=1, attrs={"class" : "event-month-heading", "colspan" : "7"}))
1.124 - output.append(fmt.span(on=1))
1.125 - output.append(fmt.text(_(month_labels[month - 1]))) # zero-based labels
1.126 - output.append(fmt.span(on=0))
1.127 - output.append(fmt.text(" "))
1.128 - output.append(fmt.span(on=1))
1.129 - output.append(fmt.text(year))
1.130 - output.append(fmt.span(on=0))
1.131 +
1.132 + # Either write a month heading or produce a link for navigable
1.133 + # calendars.
1.134 +
1.135 + month_label = _(month_labels[month - 1]) # zero-based labels
1.136 +
1.137 + if calendar_name is not None:
1.138 + previous_months_link = "%s-end=%04d-%02d" % (calendar_name, previous_year, previous_month)
1.139 + previous_month_link = "%s-start=%04d-%02d" % (calendar_name, previous_year, previous_month)
1.140 +
1.141 + output.append(fmt.span(on=1, css_class="previous-month"))
1.142 + output.append(page.link_to_raw(request, wikiutil.escape("<<"), previous_months_link))
1.143 + output.append(fmt.text(" "))
1.144 + output.append(page.link_to_raw(request, wikiutil.escape("<"), previous_month_link))
1.145 + output.append(fmt.span(on=0))
1.146 +
1.147 + next_months_link = "%s-start=%04d-%02d" % (calendar_name, next_set_year, next_set_month)
1.148 + next_month_link = "%s-start=%04d-%02d" % (calendar_name, next_year, next_month)
1.149 +
1.150 + output.append(fmt.span(on=1, css_class="next-month"))
1.151 + output.append(page.link_to_raw(request, wikiutil.escape(">"), next_month_link))
1.152 + output.append(fmt.text(" "))
1.153 + output.append(page.link_to_raw(request, wikiutil.escape(">>"), next_months_link))
1.154 + output.append(fmt.span(on=0))
1.155 +
1.156 + full_month_label = "%s %s" % (month_label, year)
1.157 + month_link = "%s-start=%04d-%02d" % (calendar_name, year, month)
1.158 + output.append(page.link_to_raw(request, wikiutil.escape(full_month_label), month_link))
1.159 +
1.160 + else:
1.161 + output.append(fmt.span(on=1))
1.162 + output.append(fmt.text(month_label))
1.163 + output.append(fmt.span(on=0))
1.164 + output.append(fmt.text(" "))
1.165 + output.append(fmt.span(on=1))
1.166 + output.append(fmt.text(year))
1.167 + output.append(fmt.span(on=0))
1.168 +
1.169 output.append(fmt.table_cell(on=0))
1.170 output.append(fmt.table_row(on=0))
1.171