Repository :
http://git.fedorahosted.org/cgit/fedocal.git
On branch : master
---------------------------------------------------------------
commit dadaed250b3e0351cceeb604a5481039d97df9fe
Author: Johan Cwiklinski <johan(a)x-tnd.be>
Date: Sun Nov 4 15:28:53 2012 +0100
Override HTMLCalendar to produce valid HTML output
---------------------------------------------------------------
fedocal/fedocallib/__init__.py | 5 ++-
fedocal/fedocallib/fedora_calendar.py | 39 +++++++++++++++++++++++++++++++++
fedocal/tests/test_fedocallib.py | 2 +-
3 files changed, 43 insertions(+), 3 deletions(-)
diff --git a/fedocal/fedocallib/__init__.py b/fedocal/fedocallib/__init__.py
index c8d6ff0..6b05a4a 100644
--- a/fedocal/fedocallib/__init__.py
+++ b/fedocal/fedocallib/__init__.py
@@ -27,7 +27,7 @@ from sqlalchemy.orm import sessionmaker
from week import Week
from model import Calendar, Reminder, Meeting
-import calendar as pycalendar
+from fedora_calendar import FedocalCalendar
MONTH = ['January', 'February', 'March', 'April',
'May', 'June', 'July',
'August', 'September', 'October', 'November',
'December']
@@ -528,6 +528,7 @@ def get_html_monthly_cal(month = None, year = None):
if month is None:
month = curdate.month
- htmlcal = pycalendar.HTMLCalendar()
+ htmlcal = FedocalCalendar()
curmonth_cal_nf = htmlcal.formatmonth(year, month)
+
return curmonth_cal_nf
diff --git a/fedocal/fedocallib/fedora_calendar.py
b/fedocal/fedocallib/fedora_calendar.py
new file mode 100644
index 0000000..ece9865
--- /dev/null
+++ b/fedocal/fedocallib/fedora_calendar.py
@@ -0,0 +1,39 @@
+# -*- coding: utf-8 -*-
+
+"""
+fedora_calendar - HTML Calendar
+
+Copyright (C) 2012 Johan Cwiklinski
+Author: Johan Cwiklinski <johan(a)x-tnd.be>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at
+your option) any later version.
+See
http://www.gnu.org/copyleft/gpl.html for the full text of the
+license.
+"""
+
+from calendar import HTMLCalendar
+from datetime import date
+
+class FedocalCalendar(HTMLCalendar):
+
+ def formatmonth(self, theyear, themonth, withyear=True):
+ """
+ Return a formatted month as a html valid table.
+ """
+ v = []
+ a = v.append
+ a('<table class="month">')
+ a('\n')
+ a(self.formatmonthname(theyear, themonth, withyear=withyear))
+ a('\n')
+ a(self.formatweekheader())
+ a('\n')
+ for week in self.monthdays2calendar(theyear, themonth):
+ a(self.formatweek(week))
+ a('\n')
+ a('</table>')
+ a('\n')
+ return ''.join(v)
diff --git a/fedocal/tests/test_fedocallib.py b/fedocal/tests/test_fedocallib.py
index a55c7c3..f3d0475 100644
--- a/fedocal/tests/test_fedocallib.py
+++ b/fedocal/tests/test_fedocallib.py
@@ -49,7 +49,7 @@ from fedocallib import model
from tests import Modeltests
result_201211_html = """
-<table border="0" cellpadding="0" cellspacing="0"
class="month">
+<table class="month">
<tr><th colspan="7" class="month">November
2012</th></tr>
<tr><th class="mon">Mon</th><th
class="tue">Tue</th><th
class="wed">Wed</th><th
class="thu">Thu</th><th
class="fri">Fri</th><th
class="sat">Sat</th><th
class="sun">Sun</th></tr>
<tr><td class="noday"> </td><td
class="noday"> </td><td
class="noday"> </td><td
class="thu">1</td><td class="fri">2</td><td
class="sat">3</td><td
class="sun">4</td></tr>