Repository :
http://git.fedorahosted.org/cgit/fedocal.git
On branch : master
---------------------------------------------------------------
commit 60472a3cf58974d5ed873d9704ef9d2955d73655
Author: Pierre-Yves Chibon <pingou(a)pingoured.fr>
Date: Tue Nov 6 08:48:42 2012 +0100
Enable navigation in the monthly calendar
The date can now be clicked and then bring you to the right week
---------------------------------------------------------------
fedocal/__init__.py | 3 +-
fedocal/fedocallib/__init__.py | 13 +++++++----
fedocal/fedocallib/fedora_calendar.py | 35 +++++++++++++++++++++++---------
3 files changed, 35 insertions(+), 16 deletions(-)
diff --git a/fedocal/__init__.py b/fedocal/__init__.py
index 039a88a..6c2adfe 100644
--- a/fedocal/__init__.py
+++ b/fedocal/__init__.py
@@ -123,7 +123,8 @@ def calendar_fullday(calendar_name, year, month, day):
auth_form = forms.LoginForm()
admin = is_admin()
month_name = fedocallib.MONTH[week_start.month - 1]
- curmonth_cal = fedocallib.get_html_monthly_cal()
+ curmonth_cal = fedocallib.get_html_monthly_cal(year=year,
+ month=month, calendar_name=calendar_name)
return flask.render_template('agenda.html',
calendar=calendarobj,
month=month_name,
diff --git a/fedocal/fedocallib/__init__.py b/fedocal/fedocallib/__init__.py
index e0cb601..76db809 100644
--- a/fedocal/fedocallib/__init__.py
+++ b/fedocal/fedocallib/__init__.py
@@ -452,11 +452,13 @@ def add_meetings_to_vcal(ical, meetings):
for meeting in meetings:
add_meeting_to_vcal(ical, meeting)
-def get_html_monthly_cal(month = None, year = None):
+def get_html_monthly_cal(month=None, year=None, calendar_name=None):
""" Display a monthly calendar as HTML.
- :arg month: optionnal month. Defaults to current month
- :arg year: optionnal year. Defaults to current year.
+ :kwarg month: optionnal month. Defaults to current month
+ :kwarg year: optionnal year. Defaults to current year.
+ :kwarg calendar_name: the name of the calendar to which the links
+ should point.
"""
if year is None or month is None:
curdate = date.today()
@@ -466,7 +468,8 @@ def get_html_monthly_cal(month = None, year = None):
if month is None:
month = curdate.month
- htmlcal = FedocalCalendar()
- curmonth_cal_nf = htmlcal.formatmonth(year, month)
+ htmlcal = FedocalCalendar(year=year, month=month,
+ calendar_name=calendar_name)
+ curmonth_cal_nf = htmlcal.formatmonth()
return curmonth_cal_nf
diff --git a/fedocal/fedocallib/fedora_calendar.py
b/fedocal/fedocallib/fedora_calendar.py
index 030d30b..8c7b981 100644
--- a/fedocal/fedocallib/fedora_calendar.py
+++ b/fedocal/fedocallib/fedora_calendar.py
@@ -24,6 +24,15 @@ class FedocalCalendar(HTMLCalendar):
html validation and some features 'locally required'
"""
+ def __init__(self, year, month, calendar_name=None):
+ """ Constructor.
+ Stores the year and the month asked.
+ """
+ super(FedocalCalendar, self).__init__()
+ self.year = year
+ self.month = month
+ self.calendar_name = calendar_name
+
def formatday(self, day, weekday):
"""
Return a day as a table cell.
@@ -34,16 +43,22 @@ class FedocalCalendar(HTMLCalendar):
if day == 0:
return '<td class="noday"> </td>' #
day outside month
else:
- if day == cur_date.day:
- return '<td class="%s, today"><a
href="%s">%d</a></td>' % (
- self.cssclasses[weekday], flask.url_for('index'),
- day)
+ link_day = day
+ if self.calendar_name:
+ link_day= '<a href="%s">%d</a>' %
(flask.url_for(
+ 'calendar_fullday',
+ calendar_name=self.calendar_name, year=self.year,
+ month=self.month, day=day), day)
+ if day == cur_date.day \
+ and self.month == cur_date.month \
+ and self.year == cur_date.year:
+ return '<td class="%s, today">%s</td>' % (
+ self.cssclasses[weekday], link_day)
else:
- return '<td class="%s"><a
href="%s">%d</a></td>' % (
- self.cssclasses[weekday], flask.url_for('index'),
- day)
+ return '<td class="%s">%s</td>' % (
+ self.cssclasses[weekday], link_day)
- def formatmonth(self, theyear, themonth, withyear=True):
+ def formatmonth(self, withyear=True):
"""
Return a formatted month as a html valid table.
"""
@@ -51,11 +66,11 @@ class FedocalCalendar(HTMLCalendar):
a = v.append
a('<table class="month">')
a('\n')
- a(self.formatmonthname(theyear, themonth, withyear=withyear))
+ a(self.formatmonthname(self.year, self.month, withyear=withyear))
a('\n')
#a(self.formatweekheader())
#a('\n')
- for week in self.monthdays2calendar(theyear, themonth):
+ for week in self.monthdays2calendar(self.year, self.month):
a(self.formatweek(week))
a('\n')
a('</table>')