mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
bpo-35078: Allow customization of CSS class name of a month in calendar module (gh-10137)
Refactor formatweekday(), formatmonthname() methods in LocaleHTMLCalendar and LocaleTextCalendar classes in calendar module to call the base class methods. This enables customizable CSS classes for LocaleHTMLCalendar and LocaleTextCalendar. Patch by Srinivas Reddy Thatiparthy
This commit is contained in:
parent
337d3103a2
commit
85339f5c22
3 changed files with 31 additions and 17 deletions
|
|
@ -571,19 +571,11 @@ class LocaleTextCalendar(TextCalendar):
|
|||
|
||||
def formatweekday(self, day, width):
|
||||
with different_locale(self.locale):
|
||||
if width >= 9:
|
||||
names = day_name
|
||||
else:
|
||||
names = day_abbr
|
||||
name = names[day]
|
||||
return name[:width].center(width)
|
||||
return super().formatweekday(day, width)
|
||||
|
||||
def formatmonthname(self, theyear, themonth, width, withyear=True):
|
||||
with different_locale(self.locale):
|
||||
s = month_name[themonth]
|
||||
if withyear:
|
||||
s = "%s %r" % (s, theyear)
|
||||
return s.center(width)
|
||||
return super().formatmonthname(theyear, themonth, width, withyear)
|
||||
|
||||
|
||||
class LocaleHTMLCalendar(HTMLCalendar):
|
||||
|
|
@ -601,16 +593,11 @@ class LocaleHTMLCalendar(HTMLCalendar):
|
|||
|
||||
def formatweekday(self, day):
|
||||
with different_locale(self.locale):
|
||||
s = day_abbr[day]
|
||||
return '<th class="%s">%s</th>' % (self.cssclasses[day], s)
|
||||
return super().formatweekday(day)
|
||||
|
||||
def formatmonthname(self, theyear, themonth, withyear=True):
|
||||
with different_locale(self.locale):
|
||||
s = month_name[themonth]
|
||||
if withyear:
|
||||
s = '%s %s' % (s, theyear)
|
||||
return '<tr><th colspan="7" class="month">%s</th></tr>' % s
|
||||
|
||||
return super().formatmonthname(theyear, themonth, withyear)
|
||||
|
||||
# Support for old module level interface
|
||||
c = TextCalendar()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue