1.1 --- a/EventAggregatorSupport.py Tue Mar 24 01:21:36 2009 +0100
1.2 +++ b/EventAggregatorSupport.py Wed Mar 25 00:37:13 2009 +0100
1.3 @@ -136,12 +136,14 @@
1.4
1.5 return date
1.6
1.7 -def daterange(first, last):
1.8 +def daterange(first, last, step=1):
1.9
1.10 - "Get the range of dates starting at 'first' and ending on 'last'."
1.11 + """
1.12 + Get the range of dates starting at 'first' and ending on 'last', using the
1.13 + specified 'step'.
1.14 + """
1.15
1.16 results = []
1.17 - step = last > first and 1 or -1
1.18
1.19 months_only = len(first) == 2
1.20 start_year = first[0]
1.21 @@ -233,6 +235,12 @@
1.22 else:
1.23 return year, month - 1
1.24
1.25 +def span(start, end):
1.26 +
1.27 + "Return the difference between 'start' and 'end'."
1.28 +
1.29 + return end[0] - start[0], end[1] - start[1]
1.30 +
1.31 def getEvents(request, category_names, calendar_start=None, calendar_end=None):
1.32
1.33 """
1.34 @@ -312,4 +320,35 @@
1.35
1.36 return events, shown_events, all_shown_events, earliest, latest
1.37
1.38 +def getConcretePeriod(calendar_start, calendar_end, earliest, latest):
1.39 +
1.40 + """
1.41 + From the requested 'calendar_start' and 'calendar_end', which may be None,
1.42 + indicating that no restriction is imposed on the period for each of the
1.43 + boundaries, use the 'earliest' and 'latest' event months to define a
1.44 + specific period of interest.
1.45 + """
1.46 +
1.47 + # Define the period as starting with any specified start month or the
1.48 + # earliest event known, ending with any specified end month or the latest
1.49 + # event known.
1.50 +
1.51 + first = calendar_start or earliest
1.52 + last = calendar_end or latest
1.53 +
1.54 + # If there is no range of months to show, perhaps because there are no
1.55 + # events in the requested period, and there was no start or end month
1.56 + # specified, show only the month indicated by the start or end of the
1.57 + # requested period. If all events were to be shown but none were found show
1.58 + # the current month.
1.59 +
1.60 + if first is None:
1.61 + first = last or getCurrentMonth()
1.62 + if last is None:
1.63 + last = first or getCurrentMonth()
1.64 +
1.65 + # Permit "expiring" periods (where the start date approaches the end date).
1.66 +
1.67 + return min(first, last), last
1.68 +
1.69 # vim: tabstop=4 expandtab shiftwidth=4
2.1 --- a/macros/EventAggregator.py Tue Mar 24 01:21:36 2009 +0100
2.2 +++ b/macros/EventAggregator.py Wed Mar 25 00:37:13 2009 +0100
2.3 @@ -45,12 +45,11 @@
2.4 # Macro functions.
2.5
2.6 def getMonth(arg):
2.7 - if arg in ("current", "next", "last"):
2.8 + if arg.startswith("current"):
2.9 date = EventAggregatorSupport.getCurrentMonth()
2.10 - if arg == "next":
2.11 - date = EventAggregatorSupport.monthupdate(date, 1)
2.12 - elif arg == "last":
2.13 - date = EventAggregatorSupport.monthupdate(date, -1)
2.14 + if len(arg) > 8:
2.15 + n = int(arg[7:])
2.16 + date = EventAggregatorSupport.monthupdate(date, n)
2.17 else:
2.18 date = EventAggregatorSupport.getMonth(arg)
2.19 return date
2.20 @@ -70,14 +69,9 @@
2.21 optional named arguments of the following forms:
2.22
2.23 start=YYYY-MM shows event details starting from the specified month
2.24 - start=current shows event details starting with the current month
2.25 - start=next shows event details starting with next month
2.26 + start=current-N shows event details relative to the current month
2.27 end=YYYY-MM shows event details ending at the specified month
2.28 - end=current shows event details ending with the current month
2.29 - end=last shows event details ending with last month
2.30 - span=N shows event details for N months starting with the
2.31 - specified start month, or ending with the specified end
2.32 - month
2.33 + end=current+N shows event details relative to the current month
2.34
2.35 mode=calendar shows a calendar view of events
2.36 mode=list shows a list of events by month
2.37 @@ -109,7 +103,6 @@
2.38 category_names = []
2.39 calendar_start = None
2.40 calendar_end = None
2.41 - span = None
2.42 mode = "calendar"
2.43 name_usage = "daily"
2.44 calendar_name = None
2.45 @@ -121,9 +114,6 @@
2.46 elif arg.startswith("end="):
2.47 calendar_end = getMonth(arg[4:])
2.48
2.49 - elif arg.startswith("span="):
2.50 - span = abs(int(arg[5:]))
2.51 -
2.52 elif arg.startswith("mode="):
2.53 mode = arg[5:]
2.54
2.55 @@ -139,40 +129,34 @@
2.56 # Find request parameters to override settings.
2.57
2.58 if calendar_name is not None:
2.59 - new_calendar_start = getFormMonth(request, calendar_name, "start")
2.60 - new_calendar_end = getFormMonth(request, calendar_name, "end")
2.61 - if new_calendar_start is not None or new_calendar_end is not None:
2.62 - calendar_start = new_calendar_start
2.63 - calendar_end = new_calendar_end
2.64 -
2.65 - # Insist on a span in order to ensure start and end months.
2.66 -
2.67 - if span is None:
2.68 - span = 1
2.69 -
2.70 - # Calculate the window of interest.
2.71 -
2.72 - if span is not None:
2.73 - if calendar_start is not None:
2.74 - calendar_end = EventAggregatorSupport.monthupdate(calendar_start, max(0, span - 1))
2.75 - elif calendar_end is not None:
2.76 - calendar_start = EventAggregatorSupport.monthupdate(calendar_end, min(0, -span + 1))
2.77 - else:
2.78 - calendar_start = EventAggregatorSupport.getCurrentMonth()
2.79 - calendar_end = EventAggregatorSupport.monthupdate(calendar_start, max(0, span - 1))
2.80 -
2.81 - # Some useful navigation months.
2.82 -
2.83 - if calendar_name is not None:
2.84 - previous_year, previous_month = EventAggregatorSupport.prevmonth(calendar_start)
2.85 - next_year, next_month = EventAggregatorSupport.nextmonth(calendar_start)
2.86 - next_set_year, next_set_month = EventAggregatorSupport.nextmonth(calendar_end)
2.87 + calendar_start = getFormMonth(request, calendar_name, "start") or calendar_start
2.88 + calendar_end = getFormMonth(request, calendar_name, "end") or calendar_end
2.89
2.90 # Get the events.
2.91
2.92 events, shown_events, all_shown_events, earliest, latest = \
2.93 EventAggregatorSupport.getEvents(request, category_names, calendar_start, calendar_end)
2.94
2.95 + # Get a concrete period of time.
2.96 +
2.97 + first, last = EventAggregatorSupport.getConcretePeriod(calendar_start, calendar_end, earliest, latest)
2.98 +
2.99 + # Define some useful navigation months.
2.100 +
2.101 + if calendar_name is not None:
2.102 + span = EventAggregatorSupport.span(first, last)
2.103 + number_of_months = span[0] * 12 + span[1] + 1
2.104 +
2.105 + previous_month_start = EventAggregatorSupport.prevmonth(first)
2.106 + next_month_start = EventAggregatorSupport.nextmonth(first)
2.107 + previous_month_end = EventAggregatorSupport.prevmonth(last)
2.108 + next_month_end = EventAggregatorSupport.nextmonth(last)
2.109 +
2.110 + previous_set_start = EventAggregatorSupport.monthupdate(first, -number_of_months)
2.111 + next_set_start = EventAggregatorSupport.monthupdate(first, number_of_months)
2.112 + previous_set_end = EventAggregatorSupport.monthupdate(last, -number_of_months)
2.113 + next_set_end = EventAggregatorSupport.monthupdate(last, number_of_months)
2.114 +
2.115 # Make a calendar.
2.116
2.117 output = []
2.118 @@ -184,9 +168,6 @@
2.119
2.120 # Visit all months in the requested range, or across known events.
2.121
2.122 - first = calendar_start or earliest
2.123 - last = calendar_end or latest
2.124 -
2.125 for year, month in EventAggregatorSupport.daterange(first, last):
2.126
2.127 # Either output a calendar view...
2.128 @@ -206,22 +187,30 @@
2.129 month_label = _(month_labels[month - 1]) # zero-based labels
2.130
2.131 if calendar_name is not None:
2.132 - previous_months_link = "%s-end=%04d-%02d" % (calendar_name, previous_year, previous_month)
2.133 - previous_month_link = "%s-start=%04d-%02d" % (calendar_name, previous_year, previous_month)
2.134 + previous_set_link = "%s-start=%04d-%02d&%s-end=%04d-%02d" % (
2.135 + (calendar_name,) + previous_set_start + (calendar_name,) + previous_set_end
2.136 + )
2.137 + previous_month_link = "%s-start=%04d-%02d&%s-end=%04d-%02d" % (
2.138 + (calendar_name,) + previous_month_start + (calendar_name,) + previous_month_end
2.139 + )
2.140
2.141 output.append(fmt.span(on=1, css_class="previous-month"))
2.142 - output.append(page.link_to_raw(request, wikiutil.escape("<<"), previous_months_link))
2.143 + output.append(page.link_to_raw(request, wikiutil.escape("<<"), previous_set_link))
2.144 output.append(fmt.text(" "))
2.145 output.append(page.link_to_raw(request, wikiutil.escape("<"), previous_month_link))
2.146 output.append(fmt.span(on=0))
2.147
2.148 - next_months_link = "%s-start=%04d-%02d" % (calendar_name, next_set_year, next_set_month)
2.149 - next_month_link = "%s-start=%04d-%02d" % (calendar_name, next_year, next_month)
2.150 + next_set_link = "%s-start=%04d-%02d&%s-end=%04d-%02d" % (
2.151 + (calendar_name,) + next_set_start + (calendar_name,) + next_set_end
2.152 + )
2.153 + next_month_link = "%s-start=%04d-%02d&%s-end=%04d-%02d" % (
2.154 + (calendar_name,) + next_month_start + (calendar_name,) + next_month_end
2.155 + )
2.156
2.157 output.append(fmt.span(on=1, css_class="next-month"))
2.158 output.append(page.link_to_raw(request, wikiutil.escape(">"), next_month_link))
2.159 output.append(fmt.text(" "))
2.160 - output.append(page.link_to_raw(request, wikiutil.escape(">>"), next_months_link))
2.161 + output.append(page.link_to_raw(request, wikiutil.escape(">>"), next_set_link))
2.162 output.append(fmt.span(on=0))
2.163
2.164 full_month_label = "%s %s" % (month_label, year)