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