web/views/old_calendar.py
author Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
Mon, 18 May 2009 08:17:58 +0200
branchstable
changeset 1829 f54710fcdd62
parent 1808 aa09e20dd8c0
child 1977 606923dff11b
permissions -rw-r--r--
avoid SelectAction selection to crash on startup views
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
     1
"""html calendar views
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
     2
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
     3
:organization: Logilab
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
     4
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
     5
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
     6
"""
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
     7
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
     8
from datetime import date, time, timedelta
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
     9
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    10
from logilab.mtconverter import html_escape
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    11
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    12
from cubicweb.interfaces import ICalendarViews
1707
71b55db64269 Use of datetime instead of mx.datetime and use of new date_range.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1700
diff changeset
    13
from cubicweb.utils import ONEDAY, ONEWEEK, date_range, first_day, last_day, previous_month, next_month, days_in_month
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    14
from cubicweb.selectors import implements
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    15
from cubicweb.view import EntityView
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    16
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
    17
# used by i18n tools
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    18
WEEKDAYS = [_("monday"), _("tuesday"), _("wednesday"), _("thursday"),
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    19
            _("friday"), _("saturday"), _("sunday")]
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    20
MONTHNAMES = [ _('january'), _('february'), _('march'), _('april'), _('may'),
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    21
               _('june'), _('july'), _('august'), _('september'), _('october'),
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    22
               _('november'), _('december')
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    23
               ]
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    24
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    25
class _CalendarView(EntityView):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    26
    """base calendar view containing helpful methods to build calendar views"""
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    27
    __select__ = implements(ICalendarViews,)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    28
    need_navigation = False
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    29
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    30
    # Navigation building methods / views ####################################
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    31
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    32
    PREV = u'<a href="%s">&lt;&lt;</a>&nbsp;&nbsp;<a href="%s">&lt;</a>'
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    33
    NEXT = u'<a href="%s">&gt;</a>&nbsp;&nbsp;<a href="%s">&gt;&gt;</a>'
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    34
    NAV_HEADER = u"""<table class="calendarPageHeader">
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    35
<tr><td class="prev">%s</td><td class="next">%s</td></tr>
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    36
</table>
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    37
""" % (PREV, NEXT)
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
    38
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    39
    def nav_header(self, date, smallshift=3, bigshift=9):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    40
        """prints shortcut links to go to previous/next steps (month|week)"""
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
    41
        prev1 = next1 = prev2 = nex2 = date
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
    42
        prev1 = previous_month(date, smallshift)
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
    43
        next1 = next_month(date, smallshift)
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
    44
        prev2 = previous_month(date, bigshift)
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
    45
        next2 = next_month(date, bigshift)
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
    46
        rql = self.rset.printable_rql()
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    47
        return self.NAV_HEADER % (
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
    48
            html_escape(self.build_url(rql=rql, vid=self.id, year=prev2.year,
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
    49
                                       month=prev2.month)),
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
    50
            html_escape(self.build_url(rql=rql, vid=self.id, year=prev1.year,
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
    51
                                       month=prev1.month)),
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
    52
            html_escape(self.build_url(rql=rql, vid=self.id, year=next1.year,
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
    53
                                       month=next1.month)),
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
    54
            html_escape(self.build_url(rql=rql, vid=self.id, year=next2.year,
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
    55
                                       month=next2.month)))
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
    56
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
    57
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    58
    # Calendar building methods ##############################################
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
    59
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    60
    def build_calendars(self, schedule, begin, end):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    61
        """build several HTML calendars at once, one for each month
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    62
        between begin and end
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    63
        """
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    64
        return [self.build_calendar(schedule, date)
1707
71b55db64269 Use of datetime instead of mx.datetime and use of new date_range.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1700
diff changeset
    65
                for date in date_range(begin, end, incmonth=1)]
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
    66
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    67
    def build_calendar(self, schedule, first_day):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    68
        """method responsible for building *one* HTML calendar"""
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    69
        # FIXME  iterates between [first_day-first_day.day_of_week ;
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    70
        #                          last_day+6-last_day.day_of_week]
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    71
        umonth = self.format_date(first_day, '%B %Y') # localized month name
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    72
        rows = []
1707
71b55db64269 Use of datetime instead of mx.datetime and use of new date_range.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1700
diff changeset
    73
        current_row = [NO_CELL] * first_day.weekday()
71b55db64269 Use of datetime instead of mx.datetime and use of new date_range.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1700
diff changeset
    74
        for daynum in xrange(0, days_in_month(first_day)):
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    75
            # build cell day
1707
71b55db64269 Use of datetime instead of mx.datetime and use of new date_range.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1700
diff changeset
    76
            day = first_day + timedelta(daynum)
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    77
            events = schedule.get(day)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    78
            if events:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    79
                events = [u'\n'.join(event) for event in events.values()]
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    80
                current_row.append(CELL % (daynum+1, '\n'.join(events)))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    81
            else:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    82
                current_row.append(EMPTY_CELL % (daynum+1))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    83
            # store & reset current row on Sundays
1707
71b55db64269 Use of datetime instead of mx.datetime and use of new date_range.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1700
diff changeset
    84
            if day.weekday() == 6:
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    85
                rows.append(u'<tr>%s%s</tr>' % (WEEKNUM_CELL % day.isocalendar()[1], ''.join(current_row)))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    86
                current_row = []
1707
71b55db64269 Use of datetime instead of mx.datetime and use of new date_range.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1700
diff changeset
    87
        current_row.extend([NO_CELL] * (6-day.weekday()))
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    88
        rql = self.rset.printable_rql()
1707
71b55db64269 Use of datetime instead of mx.datetime and use of new date_range.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1700
diff changeset
    89
        if day.weekday() != 6:
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    90
            rows.append(u'<tr>%s%s</tr>' % (WEEKNUM_CELL % day.isocalendar()[1], ''.join(current_row)))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    91
        url = self.build_url(rql=rql, vid='calendarmonth',
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    92
                             year=first_day.year, month=first_day.month)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    93
        monthlink = u'<a href="%s">%s</a>' % (html_escape(url), umonth)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    94
        return CALENDAR(self.req) % (monthlink, '\n'.join(rows))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    95
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    96
    def _mk_schedule(self, begin, end, itemvid='calendaritem'):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    97
        """private method that gathers information from resultset
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    98
        and builds calendars according to it
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    99
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   100
        :param begin: begin of date range
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   101
        :param end: end of date rangs
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   102
        :param itemvid: which view to call to render elements in cells
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   103
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   104
        returns { day1 : { hour : [views] },
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   105
                  day2 : { hour : [views] } ... }
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   106
        """
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   107
        # put this here since all sub views are calling this method
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   108
        self.req.add_css('cubicweb.calendar.css')
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   109
        schedule = {}
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   110
        for row in xrange(len(self.rset.rows)):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   111
            entity = self.entity(row)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   112
            infos = u'<div class="event">'
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   113
            infos += self.view(itemvid, self.rset, row=row)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   114
            infos += u'</div>'
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   115
            for date_ in entity.matching_dates(begin, end):
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   116
                day = date(date_.year, date_.month, date_.day)
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   117
                try:
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   118
                    dt = time(date_.hour, date_.minute, date_.second)
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   119
                except AttributeError:
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   120
                    # date instance
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   121
                    dt = time(0, 0, 0)
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   122
                schedule.setdefault(day, {})
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   123
                schedule[day].setdefault(dt, []).append(infos)
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   124
        return schedule
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   125
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   126
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   127
    @staticmethod
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   128
    def get_date_range(day, shift=4):
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   129
        """returns a couple (begin, end)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   130
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   131
        <begin> is the first day of current_month - shift
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   132
        <end> is the last day of current_month + (shift+1)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   133
        """
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   134
        begin = first_day(previous_month(day, shift))
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   135
        end = last_day(next_month(day, shift))
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   136
        return begin, end
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   137
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   138
    def _build_ampm_cells(self, daynum, events):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   139
        """create a view without any hourly details.
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   140
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   141
        :param daynum: day of the built cell
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   142
        :param events: dictionnary with all events classified by hours"""
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   143
        # split events according am/pm
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   144
        am_events = [event for e_time, e_list in events.iteritems()
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   145
                     if 0 <= e_time.hour < 12
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   146
                     for event in e_list]
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   147
        pm_events = [event for e_time, e_list in events.iteritems()
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   148
                     if 12 <= e_time.hour < 24
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   149
                     for event in e_list]
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   150
        # format each am/pm cell
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   151
        if am_events:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   152
            am_content = AMPM_CONTENT % ("amCell", "am", '\n'.join(am_events))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   153
        else:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   154
            am_content = AMPM_EMPTY % ("amCell", "am")
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   155
        if pm_events:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   156
            pm_content = AMPM_CONTENT % ("pmCell", "pm", '\n'.join(pm_events))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   157
        else:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   158
            pm_content = AMPM_EMPTY % ("pmCell", "pm")
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   159
        return am_content, pm_content
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   160
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   161
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   162
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   163
class YearCalendarView(_CalendarView):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   164
    id = 'calendaryear'
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   165
    title = _('calendar (year)')
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   166
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   167
    def call(self, year=None, month=None):
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   168
        """this view renders a 3x3 calendars' table"""
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   169
        year = year or int(self.req.form.get('year', date.today().year))
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   170
        month = month or int(self.req.form.get('month', date.today().month))
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   171
        center_date = date(year, month, 1)
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   172
        begin, end = self.get_date_range(day=center_date)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   173
        schedule = self._mk_schedule(begin, end)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   174
        self.w(self.nav_header(center_date))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   175
        calendars = tuple(self.build_calendars(schedule, begin, end))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   176
        self.w(SMALL_CALENDARS_PAGE % calendars)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   177
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   178
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   179
class SemesterCalendarView(_CalendarView):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   180
    """this view renders three semesters as three rows of six columns,
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   181
    one column per month
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   182
    """
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   183
    id = 'calendarsemester'
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   184
    title = _('calendar (semester)')
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   185
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   186
    def call(self, year=None, month=None):
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   187
        year = year or int(self.req.form.get('year', date.today().year))
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   188
        month = month or int(self.req.form.get('month', date.today().month))
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   189
        begin = previous_month(date(year, month, 1), 2)
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   190
        end = next_month(date(year, month, 1), 3)
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   191
        schedule = self._mk_schedule(begin, end)
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   192
        self.w(self.nav_header(date(year, month, 1), 1, 6))
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   193
        self.w(u'<table class="semesterCalendar">')
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   194
        self.build_calendars(schedule, begin, end)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   195
        self.w(u'</table>')
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   196
        self.w(self.nav_header(date(year, month, 1), 1, 6))
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   197
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   198
    def build_calendars(self, schedule, begin, end):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   199
        self.w(u'<tr>')
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   200
        rql = self.rset.printable_rql()
1707
71b55db64269 Use of datetime instead of mx.datetime and use of new date_range.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1700
diff changeset
   201
        for cur_month in date_range(begin, end, incmonth=1):
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   202
            umonth = u'%s&nbsp;%s' % (self.format_date(cur_month, '%B'), cur_month.year)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   203
            url = self.build_url(rql=rql, vid=self.id,
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   204
                                 year=cur_month.year, month=cur_month.month)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   205
            self.w(u'<th colspan="2"><a href="%s">%s</a></th>' % (html_escape(url),
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   206
                                                                  umonth))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   207
        self.w(u'</tr>')
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   208
        _ = self.req._
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   209
        for day_num in xrange(31):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   210
            self.w(u'<tr>')
1707
71b55db64269 Use of datetime instead of mx.datetime and use of new date_range.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1700
diff changeset
   211
            for cur_month in date_range(begin, end, incmonth=1):
71b55db64269 Use of datetime instead of mx.datetime and use of new date_range.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1700
diff changeset
   212
                if day_num >= days_in_month(cur_month):
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   213
                    self.w(u'%s%s' % (NO_CELL, NO_CELL))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   214
                else:
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   215
                    day = date(cur_month.year, cur_month.month, day_num+1)
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   216
                    events = schedule.get(day)
1707
71b55db64269 Use of datetime instead of mx.datetime and use of new date_range.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1700
diff changeset
   217
                    self.w(u'<td>%s&nbsp;%s</td>\n' % (_(WEEKDAYS[day.weekday()])[0].upper(), day_num+1))
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   218
                    self.format_day_events(day, events)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   219
            self.w(u'</tr>')
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   220
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   221
    def format_day_events(self, day, events):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   222
        if events:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   223
            events = ['\n'.join(event) for event in events.values()]
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   224
            self.w(WEEK_CELL % '\n'.join(events))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   225
        else:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   226
            self.w(WEEK_EMPTY_CELL)
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   227
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   228
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   229
class MonthCalendarView(_CalendarView):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   230
    """this view renders a 3x1 calendars' table"""
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   231
    id = 'calendarmonth'
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   232
    title = _('calendar (month)')
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   233
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   234
    def call(self, year=None, month=None):
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   235
        year = year or int(self.req.form.get('year', date.today().year))
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   236
        month = month or int(self.req.form.get('month', date.today().month))
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   237
        center_date = date(year, month, 1)
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   238
        begin, end = self.get_date_range(day=center_date, shift=1)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   239
        schedule = self._mk_schedule(begin, end)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   240
        calendars = self.build_calendars(schedule, begin, end)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   241
        self.w(self.nav_header(center_date, 1, 3))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   242
        self.w(BIG_CALENDARS_PAGE % tuple(calendars))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   243
        self.w(self.nav_header(center_date, 1, 3))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   244
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   245
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   246
class WeekCalendarView(_CalendarView):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   247
    """this view renders a calendar for week events"""
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   248
    id = 'calendarweek'
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   249
    title = _('calendar (week)')
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   250
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   251
    def call(self, year=None, week=None):
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   252
        year = year or int(self.req.form.get('year', date.today().year))
1707
71b55db64269 Use of datetime instead of mx.datetime and use of new date_range.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1700
diff changeset
   253
        week = week or int(self.req.form.get('week', date.today().isocalendar()[1]))
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   254
        day0 = date(year, 1, 1)
1707
71b55db64269 Use of datetime instead of mx.datetime and use of new date_range.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1700
diff changeset
   255
        first_day_of_week = day0 - day0.weekday()*ONEDAY + ONEWEEK
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   256
        begin, end = first_day_of_week- ONEWEEK, first_day_of_week + 2*ONEWEEK
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   257
        schedule = self._mk_schedule(begin, end, itemvid='calendarlargeitem')
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   258
        self.w(self.nav_header(first_day_of_week))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   259
        self.w(u'<table class="weekCalendar">')
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   260
        _weeks = [(first_day_of_week-ONEWEEK, first_day_of_week-ONEDAY),
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   261
                  (first_day_of_week, first_day_of_week+6*ONEDAY),
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   262
                  (first_day_of_week+ONEWEEK, first_day_of_week+13*ONEDAY)]
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   263
        self.build_calendar(schedule, _weeks)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   264
        self.w(u'</table>')
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   265
        self.w(self.nav_header(first_day_of_week))
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   266
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   267
    def build_calendar(self, schedule, weeks):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   268
        rql = self.rset.printable_rql()
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   269
        _ = self.req._
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   270
        for monday, sunday in weeks:
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   271
            umonth = self.format_date(monday, '%B %Y')
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   272
            url = self.build_url(rql=rql, vid='calendarmonth',
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   273
                                 year=monday.year, month=monday.month)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   274
            monthlink = '<a href="%s">%s</a>' % (html_escape(url), umonth)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   275
            self.w(u'<tr><th colspan="3">%s %s (%s)</th></tr>' \
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   276
                  % (_('week'), monday.isocalendar()[1], monthlink))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   277
            for day in date_range(monday, sunday):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   278
                self.w(u'<tr>')
1707
71b55db64269 Use of datetime instead of mx.datetime and use of new date_range.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1700
diff changeset
   279
                self.w(u'<td>%s</td>' % _(WEEKDAYS[day.weekday()]))
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   280
                self.w(u'<td>%s</td>' % (day.strftime('%Y-%m-%d')))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   281
                events = schedule.get(day)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   282
                if events:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   283
                    events = ['\n'.join(event) for event in events.values()]
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   284
                    self.w(WEEK_CELL % '\n'.join(events))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   285
                else:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   286
                    self.w(WEEK_EMPTY_CELL)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   287
                self.w(u'</tr>')
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   288
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   289
    def nav_header(self, date, smallshift=1, bigshift=3):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   290
        """prints shortcut links to go to previous/next steps (month|week)"""
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   291
        prev1 = date - ONEWEEK * smallshift
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   292
        prev2 = date - ONEWEEK * bigshift
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   293
        next1 = date + ONEWEEK * smallshift
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   294
        next2 = date + ONEWEEK * bigshift
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   295
        rql = self.rset.printable_rql()
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   296
        return self.NAV_HEADER % (
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   297
            html_escape(self.build_url(rql=rql, vid=self.id, year=prev2.year, week=prev2.isocalendar()[1])),
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   298
            html_escape(self.build_url(rql=rql, vid=self.id, year=prev1.year, week=prev1.isocalendar()[1])),
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   299
            html_escape(self.build_url(rql=rql, vid=self.id, year=next1.year, week=next1.isocalendar()[1])),
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   300
            html_escape(self.build_url(rql=rql, vid=self.id, year=next2.year, week=next2.isocalendar()[1])))
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   301
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   302
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   303
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   304
class AMPMYearCalendarView(YearCalendarView):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   305
    id = 'ampmcalendaryear'
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   306
    title = _('am/pm calendar (year)')
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   307
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   308
    def build_calendar(self, schedule, first_day):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   309
        """method responsible for building *one* HTML calendar"""
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   310
        umonth = self.format_date(first_day, '%B %Y') # localized month name
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   311
        rows = [] # each row is: (am,pm), (am,pm) ... week_title
1707
71b55db64269 Use of datetime instead of mx.datetime and use of new date_range.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1700
diff changeset
   312
        current_row = [(NO_CELL, NO_CELL, NO_CELL)] * first_day.weekday()
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   313
        rql = self.rset.printable_rql()
1707
71b55db64269 Use of datetime instead of mx.datetime and use of new date_range.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1700
diff changeset
   314
        for daynum in xrange(0, days_in_month(first_day)):
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   315
            # build cells day
1707
71b55db64269 Use of datetime instead of mx.datetime and use of new date_range.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1700
diff changeset
   316
            day = first_day + timedelta(daynum)
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   317
            events = schedule.get(day)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   318
            if events:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   319
                current_row.append((AMPM_DAY % (daynum+1),) + self._build_ampm_cells(daynum, events))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   320
            else:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   321
                current_row.append((AMPM_DAY % (daynum+1),
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   322
                                    AMPM_EMPTY % ("amCell", "am"),
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   323
                                    AMPM_EMPTY % ("pmCell", "pm")))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   324
            # store & reset current row on Sundays
1707
71b55db64269 Use of datetime instead of mx.datetime and use of new date_range.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1700
diff changeset
   325
            if day.weekday() == 6:
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   326
                url = self.build_url(rql=rql, vid='ampmcalendarweek',
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   327
                                     year=day.year, week=day.isocalendar()[1])
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   328
                weeklink = '<a href="%s">%s</a>' % (html_escape(url),
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   329
                                                    day.isocalendar()[1])
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   330
                current_row.append(WEEKNUM_CELL % weeklink)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   331
                rows.append(current_row)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   332
                current_row = []
1707
71b55db64269 Use of datetime instead of mx.datetime and use of new date_range.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1700
diff changeset
   333
        current_row.extend([(NO_CELL, NO_CELL, NO_CELL)] * (6-day.weekday()))
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   334
        url = self.build_url(rql=rql, vid='ampmcalendarweek',
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   335
                             year=day.year, week=day.isocalendar()[1])
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   336
        weeklink = '<a href="%s">%s</a>' % (html_escape(url), day.isocalendar()[1])
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   337
        current_row.append(WEEKNUM_CELL % weeklink)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   338
        rows.append(current_row)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   339
        # build two rows for each week: am & pm
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   340
        formatted_rows = []
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   341
        for row in rows:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   342
            week_title = row.pop()
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   343
            day_row = [day for day, am, pm in row]
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   344
            am_row = [am for day, am, pm in row]
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   345
            pm_row = [pm for day, am, pm in row]
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   346
            formatted_rows.append('<tr>%s%s</tr>'% (week_title, '\n'.join(day_row)))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   347
            formatted_rows.append('<tr class="amRow"><td>&nbsp;</td>%s</tr>'% '\n'.join(am_row))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   348
            formatted_rows.append('<tr class="pmRow"><td>&nbsp;</td>%s</tr>'% '\n'.join(pm_row))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   349
        # tigh everything together
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   350
        url = self.build_url(rql=rql, vid='ampmcalendarmonth',
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   351
                             year=first_day.year, month=first_day.month)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   352
        monthlink = '<a href="%s">%s</a>' % (html_escape(url), umonth)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   353
        return CALENDAR(self.req) % (monthlink, '\n'.join(formatted_rows))
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   354
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   355
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   356
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   357
class AMPMSemesterCalendarView(SemesterCalendarView):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   358
    """this view renders a 3x1 calendars' table"""
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   359
    id = 'ampmcalendarsemester'
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   360
    title = _('am/pm calendar (semester)')
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   361
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   362
    def build_calendars(self, schedule, begin, end):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   363
        self.w(u'<tr>')
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   364
        rql = self.rset.printable_rql()
1707
71b55db64269 Use of datetime instead of mx.datetime and use of new date_range.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1700
diff changeset
   365
        for cur_month in date_range(begin, end, incmonth=1):
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   366
            umonth = u'%s&nbsp;%s' % (self.format_date(cur_month, '%B'), cur_month.year)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   367
            url = self.build_url(rql=rql, vid=self.id,
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   368
                                 year=cur_month.year, month=cur_month.month)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   369
            self.w(u'<th colspan="3"><a href="%s">%s</a></th>' % (html_escape(url),
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   370
                                                                  umonth))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   371
        self.w(u'</tr>')
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   372
        _ = self.req._
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   373
        for day_num in xrange(31):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   374
            self.w(u'<tr>')
1707
71b55db64269 Use of datetime instead of mx.datetime and use of new date_range.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1700
diff changeset
   375
            for cur_month in date_range(begin, end, incmonth=1):
71b55db64269 Use of datetime instead of mx.datetime and use of new date_range.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1700
diff changeset
   376
                if day_num >= days_in_month(cur_month):
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   377
                    self.w(u'%s%s%s' % (NO_CELL, NO_CELL, NO_CELL))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   378
                else:
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   379
                    day = date(cur_month.year, cur_month.month, day_num+1)
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   380
                    events = schedule.get(day)
1707
71b55db64269 Use of datetime instead of mx.datetime and use of new date_range.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1700
diff changeset
   381
                    self.w(u'<td>%s&nbsp;%s</td>\n' % (_(WEEKDAYS[day.weekday()])[0].upper(),
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   382
                                                       day_num+1))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   383
                    self.format_day_events(day, events)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   384
            self.w(u'</tr>')
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   385
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   386
    def format_day_events(self, day, events):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   387
        if events:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   388
            self.w(u'\n'.join(self._build_ampm_cells(day, events)))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   389
        else:
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   390
            self.w(u'%s %s'% (AMPM_EMPTY % ("amCell", "am"),
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   391
                              AMPM_EMPTY % ("pmCell", "pm")))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   392
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   393
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   394
class AMPMMonthCalendarView(MonthCalendarView):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   395
    """this view renders a 3x1 calendars' table"""
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   396
    id = 'ampmcalendarmonth'
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   397
    title = _('am/pm calendar (month)')
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   398
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   399
    def build_calendar(self, schedule, first_day):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   400
        """method responsible for building *one* HTML calendar"""
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   401
        umonth = self.format_date(first_day, '%B %Y') # localized month name
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   402
        rows = [] # each row is: (am,pm), (am,pm) ... week_title
1707
71b55db64269 Use of datetime instead of mx.datetime and use of new date_range.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1700
diff changeset
   403
        current_row = [(NO_CELL, NO_CELL, NO_CELL)] * first_day.weekday()
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   404
        rql = self.rset.printable_rql()
1707
71b55db64269 Use of datetime instead of mx.datetime and use of new date_range.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1700
diff changeset
   405
        for daynum in xrange(0, days_in_month(first_day)):
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   406
            # build cells day
1707
71b55db64269 Use of datetime instead of mx.datetime and use of new date_range.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1700
diff changeset
   407
            day = first_day + timedelta(daynum)
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   408
            events = schedule.get(day)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   409
            if events:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   410
                current_row.append((AMPM_DAY % (daynum+1),) + self._build_ampm_cells(daynum, events))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   411
            else:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   412
                current_row.append((AMPM_DAY % (daynum+1),
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   413
                                    AMPM_EMPTY % ("amCell", "am"),
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   414
                                    AMPM_EMPTY % ("pmCell", "pm")))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   415
            # store & reset current row on Sundays
1707
71b55db64269 Use of datetime instead of mx.datetime and use of new date_range.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1700
diff changeset
   416
            if day.weekday() == 6:
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   417
                url = self.build_url(rql=rql, vid='ampmcalendarweek',
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   418
                                     year=day.year, week=day.isocalendar()[1])
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   419
                weeklink = '<a href="%s">%s</a>' % (html_escape(url),
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   420
                                                    day.isocalendar()[1])
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   421
                current_row.append(WEEKNUM_CELL % weeklink)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   422
                rows.append(current_row)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   423
                current_row = []
1707
71b55db64269 Use of datetime instead of mx.datetime and use of new date_range.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1700
diff changeset
   424
        current_row.extend([(NO_CELL, NO_CELL, NO_CELL)] * (6-day.weekday()))
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   425
        url = self.build_url(rql=rql, vid='ampmcalendarweek',
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   426
                             year=day.year, week=day.isocalendar()[1])
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   427
        weeklink = '<a href="%s">%s</a>' % (html_escape(url),
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   428
                                            day.isocalendar()[1])
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   429
        current_row.append(WEEKNUM_CELL % weeklink)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   430
        rows.append(current_row)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   431
        # build two rows for each week: am & pm
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   432
        formatted_rows = []
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   433
        for row in rows:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   434
            week_title = row.pop()
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   435
            day_row = [day for day, am, pm in row]
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   436
            am_row = [am for day, am, pm in row]
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   437
            pm_row = [pm for day, am, pm in row]
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   438
            formatted_rows.append('<tr>%s%s</tr>'% (week_title, '\n'.join(day_row)))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   439
            formatted_rows.append('<tr class="amRow"><td>&nbsp;</td>%s</tr>'% '\n'.join(am_row))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   440
            formatted_rows.append('<tr class="pmRow"><td>&nbsp;</td>%s</tr>'% '\n'.join(pm_row))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   441
        # tigh everything together
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   442
        url = self.build_url(rql=rql, vid='ampmcalendarmonth',
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   443
                             year=first_day.year, month=first_day.month)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   444
        monthlink = '<a href="%s">%s</a>' % (html_escape(url),
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   445
                                             umonth)
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   446
        return CALENDAR(self.req) % (monthlink, '\n'.join(formatted_rows))
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   447
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   448
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   449
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   450
class AMPMWeekCalendarView(WeekCalendarView):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   451
    """this view renders a 3x1 calendars' table"""
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   452
    id = 'ampmcalendarweek'
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   453
    title = _('am/pm calendar (week)')
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   454
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   455
    def build_calendar(self, schedule, weeks):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   456
        rql = self.rset.printable_rql()
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   457
        w = self.w
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   458
        _ = self.req._
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   459
        for monday, sunday in weeks:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   460
            umonth = self.format_date(monday, '%B %Y')
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   461
            url = self.build_url(rql=rql, vid='ampmcalendarmonth',
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   462
                                 year=monday.year, month=monday.month)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   463
            monthlink = '<a href="%s">%s</a>' % (html_escape(url), umonth)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   464
            w(u'<tr>%s</tr>' % (
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   465
                WEEK_TITLE % (_('week'), monday.isocalendar()[1], monthlink)))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   466
            w(u'<tr><th>%s</th><th>&nbsp;</th></tr>'% _(u'Date'))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   467
            for day in date_range(monday, sunday):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   468
                events = schedule.get(day)
1707
71b55db64269 Use of datetime instead of mx.datetime and use of new date_range.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1700
diff changeset
   469
                style = day.weekday() % 2 and "even" or "odd"
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   470
                w(u'<tr class="%s">' % style)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   471
                if events:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   472
                    hours = events.keys()
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   473
                    hours.sort()
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   474
                    w(AMPM_DAYWEEK % (
1707
71b55db64269 Use of datetime instead of mx.datetime and use of new date_range.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1700
diff changeset
   475
                        len(hours), _(WEEKDAYS[day.weekday()]),
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   476
                        self.format_date(day)))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   477
                    w(AMPM_WEEK_CELL % (
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   478
                        hours[0].hour, hours[0].minute,
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   479
                        '\n'.join(events[hours[0]])))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   480
                    w(u'</tr>')
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   481
                    for hour in hours[1:]:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   482
                        w(u'<tr class="%s">%s</tr>'% (
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   483
                            style, AMPM_WEEK_CELL % (hour.hour, hour.minute,
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   484
                                                     '\n'.join(events[hour]))))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   485
                else:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   486
                    w(AMPM_DAYWEEK_EMPTY % (
1707
71b55db64269 Use of datetime instead of mx.datetime and use of new date_range.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1700
diff changeset
   487
                        _(WEEKDAYS[day.weekday()]),
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   488
                        self.format_date(day)))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   489
                    w(WEEK_EMPTY_CELL)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   490
                    w(u'</tr>')
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   491
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   492
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   493
SMALL_CALENDARS_PAGE = u"""<table class="smallCalendars">
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   494
<tr><td class="calendar">%s</td><td class="calendar">%s</td><td class="calendar">%s</td></tr>
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   495
<tr><td class="calendar">%s</td><td class="calendar">%s</td><td class="calendar">%s</td></tr>
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   496
<tr><td class="calendar">%s</td><td class="calendar">%s</td><td class="calendar">%s</td></tr>
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   497
</table>
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   498
"""
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   499
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   500
BIG_CALENDARS_PAGE = u"""<table class="bigCalendars">
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   501
<tr><td class="calendar">%s</td></tr>
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   502
<tr><td class="calendar">%s</td></tr>
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   503
<tr><td class="calendar">%s</td></tr>
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   504
</table>
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   505
"""
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   506
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   507
WEEKNUM_CELL = u'<td class="weeknum">%s</td>'
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   508
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   509
def CALENDAR(req):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   510
    _ = req._
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   511
    WEEKNUM_HEADER = u'<th class="weeknum">%s</th>' % _('week')
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   512
    CAL_HEADER = WEEKNUM_HEADER + u' \n'.join([u'<th class="weekday">%s</th>' % _(day)[0].upper()
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   513
                                               for day in WEEKDAYS])
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   514
    return u"""<table>
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   515
<tr><th class="month" colspan="8">%%s</th></tr>
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   516
<tr>
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   517
  %s
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   518
</tr>
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   519
%%s
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   520
</table>
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   521
""" % (CAL_HEADER,)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   522
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   523
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   524
DAY_TEMPLATE = """<tr><td class="weekday">%(daylabel)s</td><td>%(dmydate)s</td><td>%(dayschedule)s</td>
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   525
"""
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   526
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   527
NO_CELL = u'<td class="noday"></td>'
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   528
EMPTY_CELL = u'<td class="cellEmpty"><span class="cellTitle">%s</span></td>'
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   529
CELL = u'<td class="cell"><span class="cellTitle">%s</span><div class="cellContent">%s</div></td>'
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   530
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   531
AMPM_DAY = u'<td class="cellDay">%d</td>'
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   532
AMPM_EMPTY = u'<td class="%sEmpty"><span class="cellTitle">%s</span></td>'
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   533
AMPM_CONTENT = u'<td class="%s"><span class="cellTitle">%s</span><div class="cellContent">%s</div></td>'
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   534
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   535
WEEK_TITLE = u'<th class="weekTitle" colspan="2">%s %s (%s)</th>'
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   536
WEEK_EMPTY_CELL = u'<td class="weekEmptyCell">&nbsp;</td>'
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   537
WEEK_CELL = u'<td class="weekCell"><div class="cellContent">%s</div></td>'
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   538
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   539
AMPM_DAYWEEK_EMPTY = u'<td>%s&nbsp;%s</td>'
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   540
AMPM_DAYWEEK = u'<td rowspan="%d">%s&nbsp;%s</td>'
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   541
AMPM_WEEK_CELL = u'<td class="ampmWeekCell"><div class="cellContent">%02d:%02d - %s</div></td>'