Commits

Alejandro Núñez Liz committed a8569e2 Draft

[FIX] Fixed problem of language in the calendar view

Comments (0)

Files changed (1)

simple_events/cms_plugins.py

 from django.utils.safestring import mark_safe
 from django.core.urlresolvers import reverse
 
-from calendar import LocaleHTMLCalendar, TimeEncoding, month_name, day_abbr
+from calendar import HTMLCalendar, TimeEncoding, month_name, day_abbr
+
+from django.utils.dates import MONTHS
+from django.utils.dates import WEEKDAYS_ABBR
+
 from datetime import date
 from itertools import groupby
 
 
 import locale
 
-class EventCalendar(LocaleHTMLCalendar):
+class EventCalendar(HTMLCalendar):
     """http://journal.uggedal.com/creating-a-flexible-monthly-calendar-in-django"""
     def __init__(self, events):
         super(EventCalendar, self).__init__()
         self.events = self.group_by_day(events)
 
-    def formatmonthname(self, theyear, themonth, withyear=True):
-        with TimeEncoding(self.locale) as encoding:
-            # TODO: expand support for all years cases
-            s = month_name[themonth]
-            if themonth-1 == 0: # previous year
-                p_s = '<a class="tipsy" title="%s" href="?month=%s&year=%s">&laquo;</a>' % (_("Previous Month"), 12, theyear-1)
-            else:
-                p_s = '<a class="tipsy" title="%s" href="?month=%s&year=%s">&laquo;</a>' % (_("Previous Month"), themonth-1, theyear)
-            if themonth+1 == 13: # next year
-                n_s = '<a class="tipsy" title="%s" href="?month=%s&year=%s">&raquo;</a>' % (_("Next Month"), 1, theyear+1)
-            else:
-                n_s = '<a class="tipsy" title="%s" href="?month=%s&year=%s">&raquo;</a>' % (_("Next Month"), themonth+1, theyear)
-            if encoding is not None:
-                s = s.decode(encoding)
-            if withyear:
-                s = '%s %s' % (s.capitalize(), theyear)
-            return '<tr><th  class="monthyear" colspan="7">%s&nbsp;%s&nbsp;%s</tr>' % (p_s, s, n_s)
-
-
     def formatday(self, day, weekday):
         if day != 0:
             cssclass = self.cssclasses[weekday]
                 return self.day_cell(cssclass, body)
             return self.day_cell(cssclass, day)
         return self.day_cell('noday', '&nbsp;')
+    
+    def formatweekday(self, day):
+        return '<th class="%s">%s</th>' % (self.cssclasses[day], WEEKDAYS_ABBR[day].title())
 
-    def formatweekday(self, day):
-        oldlocale = locale.setlocale(locale.LC_TIME, self.locale)
-        try:
-            encoding = locale.getlocale(locale.LC_TIME)[1]
-            s = day_abbr[day]
-            if encoding is not None:
-                s = s.decode(encoding)
-            result = '<th class="weekday">%s</th>' % s
-        finally:
-            locale.setlocale(locale.LC_TIME, oldlocale)
-        return result
+    def formatmonthname(self, theyear, themonth, withyear=True):
+        if withyear:
+            s = '%s %s' % (MONTHS[themonth].title(), theyear)
+        else:
+            s = '%s' % MONTHS[themonth].title()
+        return '<tr><th colspan="7" class="month">%s</th></tr>' % s
 
     def formatmonth(self, year, month):
         self.year, self.month = year, month