diff options
author | Oz N Tiram <oz.tiram@gmail.com> | 2017-06-06 09:35:59 (GMT) |
---|---|---|
committer | Walter Dörwald <walter@livinglogic.de> | 2017-06-06 09:35:59 (GMT) |
commit | 8b7a4cc40e9b2f34da94efb75b158da762624015 (patch) | |
tree | 5dd313ea843dbb65f0dd5702b61c5feafb43e5a6 /Doc/library/calendar.rst | |
parent | 167e0fc211c06df52aff1a81f513763374cb4f88 (diff) | |
download | cpython-8b7a4cc40e9b2f34da94efb75b158da762624015.zip cpython-8b7a4cc40e9b2f34da94efb75b158da762624015.tar.gz cpython-8b7a4cc40e9b2f34da94efb75b158da762624015.tar.bz2 |
bpo-30095: Make CSS classes used by calendar.HTMLCalendar customizable (GH-1439)
Several class attributes have been added to calendar.HTMLCalendar that allow customization of the CSS classes used in the resulting HTML. This can be done by subclasses HTMLCalendar and overwriting those class attributes (Patch by Oz Tiram).
Diffstat (limited to 'Doc/library/calendar.rst')
-rw-r--r-- | Doc/library/calendar.rst | 81 |
1 files changed, 80 insertions, 1 deletions
diff --git a/Doc/library/calendar.rst b/Doc/library/calendar.rst index 41e9e28..a415b47 100644 --- a/Doc/library/calendar.rst +++ b/Doc/library/calendar.rst @@ -147,7 +147,7 @@ it's the base calendar for all computations. This class can be used to generate HTML calendars. - :class:`HTMLCalendar` instances have the following methods: + :class:`!HTMLCalendar` instances have the following methods: .. method:: formatmonth(theyear, themonth, withyear=True) @@ -171,6 +171,85 @@ it's the base calendar for all computations. output (defaulting to the system default encoding). + :class:`!HTMLCalendar` has the following attributes you can override to + customize the CSS classes used by the calendar: + + .. attribute:: cssclasses + + A list of CSS classes used for each weekday. The default class list is:: + + cssclasses = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"] + + more styles can be added for each day:: + + cssclasses = ["mon text-bold", "tue", "wed", "thu", "fri", "sat", "sun red"] + + Note that the length of this list must be seven items. + + + .. attribute:: cssclass_noday + + The CSS class for a weekday occurring in the previous or coming month. + + .. versionadded:: 3.7 + + + .. attribute:: cssclasses_weekday_head + + A list of CSS classes used for weekday names in the header row. + The default is the same as :attr:`cssclasses`. + + .. versionadded:: 3.7 + + + .. attribute:: cssclass_month_head + + The month's head CSS class (used by :meth:`formatmonthname`). + The default value is ``"month"``. + + .. versionadded:: 3.7 + + + .. attribute:: cssclass_month + + The CSS class for the whole month's table (used by :meth:`formatmonth`). + The default value is ``"month"``. + + .. versionadded:: 3.7 + + + .. attribute:: cssclass_year + + The CSS class for the whole year's table of tables (used by + :meth:`formatyear`). The default value is ``"year"``. + + .. versionadded:: 3.7 + + + .. attribute:: cssclass_year_head + + The CSS class for the table head for the whole year (used by + :meth:`formatyear`). The default value is ``"year"``. + + .. versionadded:: 3.7 + + + Note that although the naming for the above described class attributes is + singular (e.g. ``cssclass_month`` ``cssclass_noday``), one can replace the + single CSS class with a space separated list of CSS classes, for example:: + + "text-bold text-red" + + Here is an example how :class:`!HTMLCalendar` can be customized:: + + class CustomHTMLCal(calendar.HTMLCalendar): + cssclasses = [style + " text-nowrap" for style in + calendar.HTMLCalendar.cssclasses] + cssclass_month_head = "text-center month-head" + cssclass_month = "text-center month" + cssclass_year = "text-italic lead" + + .. class:: LocaleTextCalendar(firstweekday=0, locale=None) This subclass of :class:`TextCalendar` can be passed a locale name in the |