==================
Term Renderer View
==================

Unit tests for TermRenderer.calendar
------------------------------------

    >>> import datetime
    >>> from schooltool.term.term import Term
    >>> from schooltool.term.browser.term import TermRenderer

    >>> term = Term('Sample', datetime.date(2004, 8, 1),
    ...                     datetime.date(2004, 8, 31))
    >>> print_cal(TermRenderer(term).calendar())
    *                        August 2004
             Mon Tue Wed Thu Fri Sat Sun
    Week 31:                           1
    Week 32:   2   3   4   5   6   7   8
    Week 33:   9  10  11  12  13  14  15
    Week 34:  16  17  18  19  20  21  22
    Week 35:  23  24  25  26  27  28  29
    Week 36:  30  31

    >>> term = Term('Sample', datetime.date(2004, 8, 2),
    ...                     datetime.date(2004, 9, 1))
    >>> print_cal(TermRenderer(term).calendar())
    *                        August 2004
             Mon Tue Wed Thu Fri Sat Sun
    Week 32:   2   3   4   5   6   7   8
    Week 33:   9  10  11  12  13  14  15
    Week 34:  16  17  18  19  20  21  22
    Week 35:  23  24  25  26  27  28  29
    Week 36:  30  31
    *                     September 2004
             Mon Tue Wed Thu Fri Sat Sun
    Week 36:           1

    >>> term = Term('Sample', datetime.date(2004, 8, 3),
    ...                     datetime.date(2004, 8, 3))
    >>> print_cal(TermRenderer(term).calendar())
    *                        August 2004
             Mon Tue Wed Thu Fri Sat Sun
    Week 32:       3

    >>> term = Term('Sample', datetime.date(2004, 12, 30),
    ...                     datetime.date(2005, 1, 3))
    >>> print_cal(TermRenderer(term).calendar())
    *                      December 2004
             Mon Tue Wed Thu Fri Sat Sun
    Week 53:              30  31
    *                       January 2005
             Mon Tue Wed Thu Fri Sat Sun
    Week 53:                       1   2
    Week 1 :   3

Each day gets a numeric index, used in Javascript

    >>> term = Term('Sample', datetime.date(2004, 12, 30),
    ...                     datetime.date(2005, 1, 3))
    >>> print_cal(TermRenderer(term).calendar(), '%(index)3s')
    *                      December 2004
             Mon Tue Wed Thu Fri Sat Sun
    Week 53:               1   2
    *                       January 2005
             Mon Tue Wed Thu Fri Sat Sun
    Week 53:                       3   4
    Week 1 :   5


Unit test for TermRenderer.month
--------------------------------

    >>> term = Term('Sample', datetime.date(2005, 1, 1),
    ...                     datetime.date(2005, 12, 31))
    >>> month = TermRenderer(term).month

The month function goes through all weeks between mindate and maxdate.

    >>> def print_month(month, day_format='%(number)3d'):
    ...     title = '%s %d' % (month['month'], month['year'])
    ...     print '*%35s' % title
    ...     print '         Mon Tue Wed Thu Fri Sat Sun'
    ...     for week in month['weeks']:
    ...         s = ['Week %-2d:' % week['number']]
    ...         for day in week['days']:
    ...             if day['number'] is None:
    ...                 s.append('   ')
    ...             else:
    ...                 s.append(day_format % day)
    ...         print ' '.join(s).rstrip()

    >>> import itertools
    >>> counter = itertools.count(1)

    >>> print_month(month(datetime.date(2005, 5, 1),
    ...                   datetime.date(2005, 5, 31), counter))
    *                           May 2005
             Mon Tue Wed Thu Fri Sat Sun
    Week 17:                           1
    Week 18:   2   3   4   5   6   7   8
    Week 19:   9  10  11  12  13  14  15
    Week 20:  16  17  18  19  20  21  22
    Week 21:  23  24  25  26  27  28  29
    Week 22:  30  31

    >>> print_month(month(datetime.date(2005, 5, 2),
    ...                   datetime.date(2005, 5, 30), counter))
    *                           May 2005
             Mon Tue Wed Thu Fri Sat Sun
    Week 18:   2   3   4   5   6   7   8
    Week 19:   9  10  11  12  13  14  15
    Week 20:  16  17  18  19  20  21  22
    Week 21:  23  24  25  26  27  28  29
    Week 22:  30

    >>> print_month(month(datetime.date(2005, 5, 3),
    ...                   datetime.date(2005, 5, 29), counter))
    *                           May 2005
             Mon Tue Wed Thu Fri Sat Sun
    Week 18:       3   4   5   6   7   8
    Week 19:   9  10  11  12  13  14  15
    Week 20:  16  17  18  19  20  21  22
    Week 21:  23  24  25  26  27  28  29

    >>> print_month(month(datetime.date(2005, 5, 10),
    ...                   datetime.date(2005, 5, 11), counter))
    *                           May 2005
             Mon Tue Wed Thu Fri Sat Sun
    Week 19:      10  11

    >>> print_month(month(datetime.date(2005, 5, 17),
    ...                   datetime.date(2005, 5, 17), counter))
    *                           May 2005
             Mon Tue Wed Thu Fri Sat Sun
    Week 20:      17


Unit test for TermRenderer.week
-------------------------------

    >>> term = Term('Sample', datetime.date(2005, 5, 1),
    ...                     datetime.date(2005, 5, 31))
    >>> term.addWeekdays(0, 1, 2, 3, 4)
    >>> week = TermRenderer(term).week

The week function is pretty simple.  First we will try to pass Monday
as start_of_week.

    >>> def print_week(week):
    ...     print 'Week %d' % week['number']
    ...     print 'index date number checked class onclick'
    ...     for day in week['days']:
    ...         print ('%(index)s %(date)s %(number)s %(checked)s'
    ...                ' %(class)s %(onclick)s') % day

    >>> counter = itertools.count(1)

    >>> print_week(week(datetime.date(2005, 5, 2),
    ...                 datetime.date(2005, 5, 2),
    ...                 datetime.date(2005, 5, 8),
    ...                 counter))
    Week 18
    index date number checked class onclick
    1 2005-05-02 2 False schoolday javascript:toggle(1)
    2 2005-05-03 3 False schoolday javascript:toggle(2)
    3 2005-05-04 4 False schoolday javascript:toggle(3)
    4 2005-05-05 5 False schoolday javascript:toggle(4)
    5 2005-05-06 6 False schoolday javascript:toggle(5)
    6 2005-05-07 7 True holiday javascript:toggle(6)
    7 2005-05-08 8 True holiday javascript:toggle(7)

min_date is handled

    >>> print_week(week(datetime.date(2005, 5, 2),
    ...                 datetime.date(2005, 5, 3),
    ...                 datetime.date(2005, 5, 8),
    ...                 counter))
    Week 18
    index date number checked class onclick
    None None None None None None
    8 2005-05-03 3 False schoolday javascript:toggle(8)
    9 2005-05-04 4 False schoolday javascript:toggle(9)
    10 2005-05-05 5 False schoolday javascript:toggle(10)
    11 2005-05-06 6 False schoolday javascript:toggle(11)
    12 2005-05-07 7 True holiday javascript:toggle(12)
    13 2005-05-08 8 True holiday javascript:toggle(13)

max_date is handled too

    >>> print_week(week(datetime.date(2005, 5, 2),
    ...                 datetime.date(2005, 5, 3),
    ...                 datetime.date(2005, 5, 6),
    ...                 counter))
    Week 18
    index date number checked class onclick
    None None None None None None
    14 2005-05-03 3 False schoolday javascript:toggle(14)
    15 2005-05-04 4 False schoolday javascript:toggle(15)
    16 2005-05-05 5 False schoolday javascript:toggle(16)
    17 2005-05-06 6 False schoolday javascript:toggle(17)
    None None None None None None
    None None None None None None

Weeks can start on Sundays too

    >>> print_week(week(datetime.date(2005, 5, 1),
    ...                 datetime.date(2005, 5, 1),
    ...                 datetime.date(2005, 5, 8),
    ...                 counter))
    Week 18
    index date number checked class onclick
    18 2005-05-01 1 True holiday javascript:toggle(18)
    19 2005-05-02 2 False schoolday javascript:toggle(19)
    20 2005-05-03 3 False schoolday javascript:toggle(20)
    21 2005-05-04 4 False schoolday javascript:toggle(21)
    22 2005-05-05 5 False schoolday javascript:toggle(22)
    23 2005-05-06 6 False schoolday javascript:toggle(23)
    24 2005-05-07 7 True holiday javascript:toggle(24)

