# HG changeset patch # User Tero Marttila # Date 1234385803 -7200 # Node ID 090192b64d7e4a8c50c0e0de86a9bca81d2cc790 # Parent 95c0c49d76aa3cfff70d3c80912a18966b3f4c57 add three calendars to the channel_calendar view diff -r 95c0c49d76aa -r 090192b64d7e handlers.py --- a/handlers.py Wed Feb 11 22:24:55 2009 +0200 +++ b/handlers.py Wed Feb 11 22:56:43 2009 +0200 @@ -181,17 +181,12 @@ day = 1 )) - # get set of days available - days = set(channel.source.get_month_days(target)) - # display calendar return templates.render_to_response("channel_calendar", req = request, prefs = request.prefs, channel = channel, - calendar = calendar.Calendar(), - month = target.date(), - days = days, + month = target, ) @preferences.handler(prefs.formatter, prefs.timezone, prefs.count) diff -r 95c0c49d76aa -r 090192b64d7e helpers.py --- a/helpers.py Wed Feb 11 22:24:55 2009 +0200 +++ b/helpers.py Wed Feb 11 22:56:43 2009 +0200 @@ -13,6 +13,12 @@ Our set of helpers, inheriting from base helpers """ + # set contructor... + set = set + + # reference to calendar instance + calendar = calendar.Calendar() + def tz_name (self, tz) : """ Returns a string describing the given timezone @@ -72,49 +78,53 @@ return (month.year == today.year and month.month == today.month) - def prev_month_year (self, month) : - """ - Returns the year of the month before the given one + @staticmethod + def _wrap_year (year, month) : """ + Wraps month to between [1, 12], spilling overflow/underflow by to year. - if month.month == 1 : - return month.year - 1 - + Returns (year, month) + """ + + # underflow? + if month == 0 : + # wrap to previous year + return (year - 1, 12) + + # overflow? + elif month == 13 : + # wrap to next year + return (year + 1, 1) + + # sane value + elif 1 <= month <= 12 : + return (year, month) + + # insane value else : - return month.year - - def next_month_year (self, month) : - """ - Returns the year of the month after the given one - """ - - if month.month == 12 : - return month.year + 1 - - else : - return month.year + assert False, "invalid year/month: %d/%d" % (year, month) def prev_month (self, month) : """ - Returns the month before the given one + Returns the month preceding the given one (as a datetime.datetime) """ - - if month.month == 1 : - return 12 - - else : - return month.month - 1 + + # previous month + y, m = self._wrap_year(month.year, month.month - 1) + + # build datetime + return datetime.datetime(year=y, month=m, day=1, tzinfo=month.tzinfo) def next_month (self, month) : """ - Returns the month after the given one + Returns the month following the given one (as a datetime.datetime) """ - - if month.month == 12 : - return 1 - - else : - return month.month + 1 + + # previous month + y, m = self._wrap_year(month.year, month.month + 1) + + # build datetime + return datetime.datetime(year=y, month=m, day=1, tzinfo=month.tzinfo) def fmt_time (self, time=None) : """ diff -r 95c0c49d76aa -r 090192b64d7e log_source.py --- a/log_source.py Wed Feb 11 22:24:55 2009 +0200 +++ b/log_source.py Wed Feb 11 22:56:43 2009 +0200 @@ -627,7 +627,7 @@ """ Returns a set of dates for which logfiles are available in the given datetime's month """ - + # iterate over month's days for dt in self._iter_month_days(month) : # date in our target timezone diff -r 95c0c49d76aa -r 090192b64d7e static/irclogs.css --- a/static/irclogs.css Wed Feb 11 22:24:55 2009 +0200 +++ b/static/irclogs.css Wed Feb 11 22:56:43 2009 +0200 @@ -145,7 +145,7 @@ /* Calendar */ table.calendar { - + display: inline; } table.calendar th { diff -r 95c0c49d76aa -r 090192b64d7e templates/channel_calendar.tmpl --- a/templates/channel_calendar.tmpl Wed Feb 11 22:24:55 2009 +0200 +++ b/templates/channel_calendar.tmpl Wed Feb 11 22:56:43 2009 +0200 @@ -1,23 +1,26 @@ <%inherit file="channel.tmpl" /> -<%def name="month_table(cal, month, dates)"> +<%def name="month_table(month)"> +## the set of available days +<% log_dates = h.set(channel.source.get_month_days(month)) %> +## the calendar table ## table header - month name ## month header - weekday names - % for weekday in cal.iterweekdays() : + % for weekday in h.calendar.iterweekdays() : % endfor ## iterate over the weeks -% for week in cal.monthdays2calendar(month.year, month.month) : +% for week in h.calendar.monthdays2calendar(month.year, month.month) : ## iterate over the week's days % for day, weekday in week : @@ -28,9 +31,9 @@ ## build date <% date = h.build_date(month, day) %>\ ## render cell - \ + \ ## link to logs for this day? - % if date in dates : + % if date in log_dates : ${day}\ % else : ${day}\ @@ -43,5 +46,8 @@
- » - « + » + « ${h.fmt_month(month)}
${h.fmt_weekday(weekday)}
-${month_table(calendar, month, days)} +## three months +${month_table(h.prev_month(month))} +${month_table(month )} +${month_table(h.next_month(month))}