web/views/old_calendar.py
author Alexandre Fayolle <alexandre.fayolle@logilab.fr>
Sat, 29 May 2010 10:33:40 +0200
branchstable
changeset 5607 38d43dc5ee57
parent 5424 8ecbcbff9777
child 5556 9ab2b4c74baf
permissions -rw-r--r--
skip flymake junk when reloading this avoids nasty ex aequo scores in selectors in dev. mode
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4722
diff changeset
     1
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4722
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4722
diff changeset
     3
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4722
diff changeset
     4
# This file is part of CubicWeb.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4722
diff changeset
     5
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4722
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4722
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4722
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4722
diff changeset
     9
# any later version.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4722
diff changeset
    10
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4722
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4722
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4722
diff changeset
    14
# details.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4722
diff changeset
    15
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4722
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4722
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    18
"""html calendar views
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    19
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    20
"""
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    21
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
    22
from datetime import date, time, timedelta
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    23
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    24
from logilab.mtconverter import xml_escape
4466
8b0ca7904820 moved generic datetime manipulation function to lgc
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    25
from logilab.common.date import (ONEDAY, ONEWEEK, days_in_month, previous_month,
8b0ca7904820 moved generic datetime manipulation function to lgc
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    26
                                 next_month, first_day, last_day, date_range)
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    27
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    28
from cubicweb.interfaces import ICalendarViews
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    29
from cubicweb.selectors import implements
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    30
from cubicweb.view import EntityView
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    31
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
    32
# used by i18n tools
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    33
WEEKDAYS = [_("monday"), _("tuesday"), _("wednesday"), _("thursday"),
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    34
            _("friday"), _("saturday"), _("sunday")]
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    35
MONTHNAMES = [ _('january'), _('february'), _('march'), _('april'), _('may'),
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    36
               _('june'), _('july'), _('august'), _('september'), _('october'),
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    37
               _('november'), _('december')
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    38
               ]
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    39
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    40
class _CalendarView(EntityView):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    41
    """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
    42
    __select__ = implements(ICalendarViews,)
4244
2c3de1953d00 rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4212
diff changeset
    43
    paginable = False
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    44
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    45
    # Navigation building methods / views ####################################
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    46
2996
866a2c135c33 B #345282 xhtml requires to use &#160; instead of &nbsp;
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2312
diff changeset
    47
    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
    48
    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
    49
    NAV_HEADER = u"""<table class="calendarPageHeader">
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    50
<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
    51
</table>
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    52
""" % (PREV, NEXT)
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
    53
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    54
    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
    55
        """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
    56
        prev1 = previous_month(date, smallshift)
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
    57
        next1 = next_month(date, smallshift)
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
    58
        prev2 = previous_month(date, bigshift)
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
    59
        next2 = next_month(date, bigshift)
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    60
        rql = self.cw_rset.printable_rql()
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    61
        return self.NAV_HEADER % (
3457
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
    62
            xml_escape(self._cw.build_url(rql=rql, vid=self.__regid__, year=prev2.year,
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
    63
                                          month=prev2.month)),
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
    64
            xml_escape(self._cw.build_url(rql=rql, vid=self.__regid__, year=prev1.year,
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
    65
                                          month=prev1.month)),
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
    66
            xml_escape(self._cw.build_url(rql=rql, vid=self.__regid__, year=next1.year,
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
    67
                                          month=next1.month)),
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
    68
            xml_escape(self._cw.build_url(rql=rql, vid=self.__regid__, year=next2.year,
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
    69
                                          month=next2.month)))
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
    70
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
    71
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    72
    # Calendar building methods ##############################################
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
    73
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    74
    def build_calendars(self, schedule, begin, end):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    75
        """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
    76
        between begin and end
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    77
        """
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    78
        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
    79
                for date in date_range(begin, end, incmonth=1)]
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
    80
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    81
    def build_calendar(self, schedule, first_day):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    82
        """method responsible for building *one* HTML calendar"""
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    83
        # 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
    84
        #                          last_day+6-last_day.day_of_week]
3457
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
    85
        umonth = self._cw.format_date(first_day, '%B %Y') # localized month name
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    86
        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
    87
        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
    88
        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
    89
            # 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
    90
            day = first_day + timedelta(daynum)
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    91
            events = schedule.get(day)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    92
            if events:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    93
                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
    94
                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
    95
            else:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    96
                current_row.append(EMPTY_CELL % (daynum+1))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    97
            # 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
    98
            if day.weekday() == 6:
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
    99
                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
   100
                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
   101
        current_row.extend([NO_CELL] * (6-day.weekday()))
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   102
        rql = self.cw_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
   103
        if day.weekday() != 6:
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   104
            rows.append(u'<tr>%s%s</tr>' % (WEEKNUM_CELL % day.isocalendar()[1], ''.join(current_row)))
3457
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   105
        url = self._cw.build_url(rql=rql, vid='calendarmonth',
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   106
                                 year=first_day.year, month=first_day.month)
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   107
        monthlink = u'<a href="%s">%s</a>' % (xml_escape(url), umonth)
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   108
        return CALENDAR(self._cw) % (monthlink, '\n'.join(rows))
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   109
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   110
    def _mk_schedule(self, begin, end, itemvid='calendaritem'):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   111
        """private method that gathers information from resultset
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   112
        and builds calendars according to it
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   113
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   114
        :param begin: begin of date range
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   115
        :param end: end of date rangs
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   116
        :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
   117
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   118
        returns { day1 : { hour : [views] },
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   119
                  day2 : { hour : [views] } ... }
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   120
        """
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   121
        # put this here since all sub views are calling this method
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   122
        self._cw.add_css('cubicweb.calendar.css')
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   123
        schedule = {}
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   124
        for row in xrange(len(self.cw_rset.rows)):
4721
8f63691ccb7f pylint style fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
   125
            entity = self.cw_rset.get_entity(row, 0)
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   126
            infos = u'<div class="event">'
3457
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   127
            infos += self._cw.view(itemvid, self.cw_rset, row=row)
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   128
            infos += u'</div>'
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   129
            for date_ in entity.matching_dates(begin, end):
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   130
                day = date(date_.year, date_.month, date_.day)
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   131
                try:
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   132
                    dt = time(date_.hour, date_.minute, date_.second)
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   133
                except AttributeError:
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   134
                    # date instance
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   135
                    dt = time(0, 0, 0)
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   136
                schedule.setdefault(day, {})
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   137
                schedule[day].setdefault(dt, []).append(infos)
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   138
        return schedule
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   139
1688
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
    @staticmethod
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   142
    def get_date_range(day, shift=4):
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   143
        """returns a couple (begin, end)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   144
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   145
        <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
   146
        <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
   147
        """
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   148
        begin = first_day(previous_month(day, shift))
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   149
        end = last_day(next_month(day, shift))
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   150
        return begin, end
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   151
4722
9c13d5db03d9 pylint suggested refactorings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4721
diff changeset
   152
    def _build_ampm_cells(self, events):
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   153
        """create a view without any hourly details.
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   154
4722
9c13d5db03d9 pylint suggested refactorings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4721
diff changeset
   155
        :param events: dictionnary with all events classified by hours
9c13d5db03d9 pylint suggested refactorings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4721
diff changeset
   156
        """
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   157
        # split events according am/pm
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   158
        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
   159
                     if 0 <= e_time.hour < 12
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   160
                     for event in e_list]
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   161
        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
   162
                     if 12 <= e_time.hour < 24
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   163
                     for event in e_list]
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   164
        # format each am/pm cell
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   165
        if am_events:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   166
            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
   167
        else:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   168
            am_content = AMPM_EMPTY % ("amCell", "am")
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   169
        if pm_events:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   170
            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
   171
        else:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   172
            pm_content = AMPM_EMPTY % ("pmCell", "pm")
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   173
        return am_content, pm_content
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   174
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   175
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   176
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   177
class YearCalendarView(_CalendarView):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3023
diff changeset
   178
    __regid__ = 'calendaryear'
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   179
    title = _('calendar (year)')
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   180
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   181
    def call(self, year=None, month=None):
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   182
        """this view renders a 3x3 calendars' table"""
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   183
        year = year or int(self._cw.form.get('year', date.today().year))
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   184
        month = month or int(self._cw.form.get('month', date.today().month))
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   185
        center_date = date(year, month, 1)
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   186
        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
   187
        schedule = self._mk_schedule(begin, end)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   188
        self.w(self.nav_header(center_date))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   189
        calendars = tuple(self.build_calendars(schedule, begin, end))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   190
        self.w(SMALL_CALENDARS_PAGE % calendars)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   191
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   192
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   193
class SemesterCalendarView(_CalendarView):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   194
    """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
   195
    one column per month
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   196
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3023
diff changeset
   197
    __regid__ = 'calendarsemester'
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   198
    title = _('calendar (semester)')
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   199
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   200
    def call(self, year=None, month=None):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   201
        year = year or int(self._cw.form.get('year', date.today().year))
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   202
        month = month or int(self._cw.form.get('month', date.today().month))
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   203
        begin = previous_month(date(year, month, 1), 2)
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   204
        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
   205
        schedule = self._mk_schedule(begin, end)
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   206
        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
   207
        self.w(u'<table class="semesterCalendar">')
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   208
        self.build_calendars(schedule, begin, end)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   209
        self.w(u'</table>')
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   210
        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
   211
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   212
    def build_calendars(self, schedule, begin, end):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   213
        self.w(u'<tr>')
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   214
        rql = self.cw_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
   215
        for cur_month in date_range(begin, end, incmonth=1):
3457
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   216
            umonth = u'%s&#160;%s' % (self._cw.format_date(cur_month, '%B'), cur_month.year)
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   217
            url = self._cw.build_url(rql=rql, vid=self.__regid__,
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   218
                                     year=cur_month.year, month=cur_month.month)
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   219
            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
   220
                                                                  umonth))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   221
        self.w(u'</tr>')
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   222
        _ = self._cw._
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   223
        for day_num in xrange(31):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   224
            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
   225
            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
   226
                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
   227
                    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
   228
                else:
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   229
                    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
   230
                    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
   231
                    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
   232
                    self.format_day_events(day, events)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   233
            self.w(u'</tr>')
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   234
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   235
    def format_day_events(self, day, events):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   236
        if events:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   237
            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
   238
            self.w(WEEK_CELL % '\n'.join(events))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   239
        else:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   240
            self.w(WEEK_EMPTY_CELL)
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   241
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   242
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   243
class MonthCalendarView(_CalendarView):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   244
    """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
   245
    __regid__ = 'calendarmonth'
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   246
    title = _('calendar (month)')
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   247
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   248
    def call(self, year=None, month=None):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   249
        year = year or int(self._cw.form.get('year', date.today().year))
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   250
        month = month or int(self._cw.form.get('month', date.today().month))
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   251
        center_date = date(year, month, 1)
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   252
        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
   253
        schedule = self._mk_schedule(begin, end)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   254
        calendars = self.build_calendars(schedule, begin, end)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   255
        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
   256
        self.w(BIG_CALENDARS_PAGE % tuple(calendars))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   257
        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
   258
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   259
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   260
class WeekCalendarView(_CalendarView):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   261
    """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
   262
    __regid__ = 'calendarweek'
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   263
    title = _('calendar (week)')
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   264
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   265
    def call(self, year=None, week=None):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   266
        year = year or int(self._cw.form.get('year', date.today().year))
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   267
        week = week or int(self._cw.form.get('week', date.today().isocalendar()[1]))
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   268
        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
   269
        first_day_of_week = day0 - day0.weekday()*ONEDAY + ONEWEEK
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   270
        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
   271
        schedule = self._mk_schedule(begin, end, itemvid='calendarlargeitem')
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   272
        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
   273
        self.w(u'<table class="weekCalendar">')
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   274
        _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
   275
                  (first_day_of_week, first_day_of_week+6*ONEDAY),
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   276
                  (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
   277
        self.build_calendar(schedule, _weeks)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   278
        self.w(u'</table>')
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   279
        self.w(self.nav_header(first_day_of_week))
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   280
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   281
    def build_calendar(self, schedule, weeks):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   282
        rql = self.cw_rset.printable_rql()
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   283
        _ = self._cw._
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   284
        for monday, sunday in weeks:
3457
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   285
            umonth = self._cw.format_date(monday, '%B %Y')
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   286
            url = self._cw.build_url(rql=rql, vid='calendarmonth',
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   287
                                     year=monday.year, month=monday.month)
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   288
            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
   289
            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
   290
                  % (_('week'), monday.isocalendar()[1], monthlink))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   291
            for day in date_range(monday, sunday):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   292
                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
   293
                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
   294
                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
   295
                events = schedule.get(day)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   296
                if events:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   297
                    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
   298
                    self.w(WEEK_CELL % '\n'.join(events))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   299
                else:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   300
                    self.w(WEEK_EMPTY_CELL)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   301
                self.w(u'</tr>')
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   302
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   303
    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
   304
        """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
   305
        prev1 = date - ONEWEEK * smallshift
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   306
        prev2 = date - ONEWEEK * bigshift
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   307
        next1 = date + ONEWEEK * smallshift
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   308
        next2 = date + ONEWEEK * bigshift
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   309
        rql = self.cw_rset.printable_rql()
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   310
        return self.NAV_HEADER % (
3457
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   311
            xml_escape(self._cw.build_url(rql=rql, vid=self.__regid__, year=prev2.year, week=prev2.isocalendar()[1])),
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   312
            xml_escape(self._cw.build_url(rql=rql, vid=self.__regid__, year=prev1.year, week=prev1.isocalendar()[1])),
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   313
            xml_escape(self._cw.build_url(rql=rql, vid=self.__regid__, year=next1.year, week=next1.isocalendar()[1])),
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   314
            xml_escape(self._cw.build_url(rql=rql, vid=self.__regid__, year=next2.year, week=next2.isocalendar()[1])))
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   315
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   316
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   317
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   318
class AMPMYearCalendarView(YearCalendarView):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3023
diff changeset
   319
    __regid__ = 'ampmcalendaryear'
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   320
    title = _('am/pm calendar (year)')
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   321
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   322
    def build_calendar(self, schedule, first_day):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   323
        """method responsible for building *one* HTML calendar"""
3457
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   324
        umonth = self._cw.format_date(first_day, '%B %Y') # localized month name
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   325
        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
   326
        current_row = [(NO_CELL, NO_CELL, NO_CELL)] * first_day.weekday()
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   327
        rql = self.cw_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
   328
        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
   329
            # 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
   330
            day = first_day + timedelta(daynum)
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   331
            events = schedule.get(day)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   332
            if events:
4722
9c13d5db03d9 pylint suggested refactorings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4721
diff changeset
   333
                current_row.append((AMPM_DAY % (daynum+1),) + self._build_ampm_cells(events))
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   334
            else:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   335
                current_row.append((AMPM_DAY % (daynum+1),
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   336
                                    AMPM_EMPTY % ("amCell", "am"),
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   337
                                    AMPM_EMPTY % ("pmCell", "pm")))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   338
            # 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
   339
            if day.weekday() == 6:
3457
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   340
                url = self._cw.build_url(rql=rql, vid='ampmcalendarweek',
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   341
                                     year=day.year, week=day.isocalendar()[1])
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   342
                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
   343
                                                    day.isocalendar()[1])
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   344
                current_row.append(WEEKNUM_CELL % weeklink)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   345
                rows.append(current_row)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   346
                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
   347
        current_row.extend([(NO_CELL, NO_CELL, NO_CELL)] * (6-day.weekday()))
3457
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   348
        url = self._cw.build_url(rql=rql, vid='ampmcalendarweek',
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   349
                             year=day.year, week=day.isocalendar()[1])
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   350
        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
   351
        current_row.append(WEEKNUM_CELL % weeklink)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   352
        rows.append(current_row)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   353
        # build two rows for each week: am & pm
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   354
        formatted_rows = []
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   355
        for row in rows:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   356
            week_title = row.pop()
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   357
            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
   358
            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
   359
            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
   360
            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
   361
            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
   362
            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
   363
        # tigh everything together
3457
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   364
        url = self._cw.build_url(rql=rql, vid='ampmcalendarmonth',
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   365
                             year=first_day.year, month=first_day.month)
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   366
        monthlink = '<a href="%s">%s</a>' % (xml_escape(url), umonth)
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   367
        return CALENDAR(self._cw) % (monthlink, '\n'.join(formatted_rows))
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   368
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   369
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   370
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   371
class AMPMSemesterCalendarView(SemesterCalendarView):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   372
    """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
   373
    __regid__ = 'ampmcalendarsemester'
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   374
    title = _('am/pm calendar (semester)')
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   375
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   376
    def build_calendars(self, schedule, begin, end):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   377
        self.w(u'<tr>')
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   378
        rql = self.cw_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
   379
        for cur_month in date_range(begin, end, incmonth=1):
3457
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   380
            umonth = u'%s&#160;%s' % (self._cw.format_date(cur_month, '%B'), cur_month.year)
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   381
            url = self._cw.build_url(rql=rql, vid=self.__regid__,
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   382
                                 year=cur_month.year, month=cur_month.month)
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   383
            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
   384
                                                                  umonth))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   385
        self.w(u'</tr>')
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   386
        _ = self._cw._
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   387
        for day_num in xrange(31):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   388
            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
   389
            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
   390
                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
   391
                    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
   392
                else:
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   393
                    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
   394
                    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
   395
                    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
   396
                                                       day_num+1))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   397
                    self.format_day_events(day, events)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   398
            self.w(u'</tr>')
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   399
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   400
    def format_day_events(self, day, events):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   401
        if events:
4722
9c13d5db03d9 pylint suggested refactorings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4721
diff changeset
   402
            self.w(u'\n'.join(self._build_ampm_cells(events)))
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   403
        else:
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   404
            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
   405
                              AMPM_EMPTY % ("pmCell", "pm")))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   406
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   407
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   408
class AMPMMonthCalendarView(MonthCalendarView):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   409
    """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
   410
    __regid__ = 'ampmcalendarmonth'
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   411
    title = _('am/pm calendar (month)')
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   412
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   413
    def build_calendar(self, schedule, first_day):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   414
        """method responsible for building *one* HTML calendar"""
3457
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   415
        umonth = self._cw.format_date(first_day, '%B %Y') # localized month name
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   416
        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
   417
        current_row = [(NO_CELL, NO_CELL, NO_CELL)] * first_day.weekday()
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   418
        rql = self.cw_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
   419
        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
   420
            # 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
   421
            day = first_day + timedelta(daynum)
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   422
            events = schedule.get(day)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   423
            if events:
4722
9c13d5db03d9 pylint suggested refactorings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4721
diff changeset
   424
                current_row.append((AMPM_DAY % (daynum+1),) + self._build_ampm_cells(events))
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   425
            else:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   426
                current_row.append((AMPM_DAY % (daynum+1),
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   427
                                    AMPM_EMPTY % ("amCell", "am"),
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   428
                                    AMPM_EMPTY % ("pmCell", "pm")))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   429
            # 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
   430
            if day.weekday() == 6:
3457
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   431
                url = self._cw.build_url(rql=rql, vid='ampmcalendarweek',
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   432
                                         year=day.year, week=day.isocalendar()[1])
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   433
                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
   434
                                                    day.isocalendar()[1])
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   435
                current_row.append(WEEKNUM_CELL % weeklink)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   436
                rows.append(current_row)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   437
                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
   438
        current_row.extend([(NO_CELL, NO_CELL, NO_CELL)] * (6-day.weekday()))
3457
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   439
        url = self._cw.build_url(rql=rql, vid='ampmcalendarweek',
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   440
                                 year=day.year, week=day.isocalendar()[1])
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   441
        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
   442
                                            day.isocalendar()[1])
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   443
        current_row.append(WEEKNUM_CELL % weeklink)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   444
        rows.append(current_row)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   445
        # build two rows for each week: am & pm
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   446
        formatted_rows = []
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   447
        for row in rows:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   448
            week_title = row.pop()
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   449
            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
   450
            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
   451
            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
   452
            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
   453
            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
   454
            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
   455
        # tigh everything together
3457
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   456
        url = self._cw.build_url(rql=rql, vid='ampmcalendarmonth',
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   457
                                 year=first_day.year, month=first_day.month)
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   458
        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
   459
                                             umonth)
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   460
        return CALENDAR(self._cw) % (monthlink, '\n'.join(formatted_rows))
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   461
1700
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   462
b5b323f8a05b update old_calendar, more needed
sylvain.thenault@logilab.fr
parents: 1688
diff changeset
   463
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   464
class AMPMWeekCalendarView(WeekCalendarView):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   465
    """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
   466
    __regid__ = 'ampmcalendarweek'
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   467
    title = _('am/pm calendar (week)')
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   468
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   469
    def build_calendar(self, schedule, weeks):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   470
        rql = self.cw_rset.printable_rql()
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   471
        w = self.w
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   472
        _ = self._cw._
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   473
        for monday, sunday in weeks:
3457
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   474
            umonth = self._cw.format_date(monday, '%B %Y')
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   475
            url = self._cw.build_url(rql=rql, vid='ampmcalendarmonth',
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   476
                                     year=monday.year, month=monday.month)
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   477
            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
   478
            w(u'<tr>%s</tr>' % (
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   479
                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
   480
            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
   481
            for day in date_range(monday, sunday):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   482
                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
   483
                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
   484
                w(u'<tr class="%s">' % style)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   485
                if events:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   486
                    hours = events.keys()
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   487
                    hours.sort()
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   488
                    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
   489
                        len(hours), _(WEEKDAYS[day.weekday()]),
3457
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   490
                        self._cw.format_date(day)))
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   491
                    w(AMPM_WEEK_CELL % (
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   492
                        hours[0].hour, hours[0].minute,
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   493
                        '\n'.join(events[hours[0]])))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   494
                    w(u'</tr>')
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   495
                    for hour in hours[1:]:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   496
                        w(u'<tr class="%s">%s</tr>'% (
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   497
                            style, AMPM_WEEK_CELL % (hour.hour, hour.minute,
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   498
                                                     '\n'.join(events[hour]))))
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   499
                else:
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   500
                    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
   501
                        _(WEEKDAYS[day.weekday()]),
3457
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   502
                        self._cw.format_date(day)))
1688
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   503
                    w(WEEK_EMPTY_CELL)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   504
                    w(u'</tr>')
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
SMALL_CALENDARS_PAGE = u"""<table class="smallCalendars">
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   508
<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
   509
<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
   510
<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
   511
</table>
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   512
"""
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   513
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   514
BIG_CALENDARS_PAGE = u"""<table class="bigCalendars">
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   515
<tr><td class="calendar">%s</td></tr>
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   516
<tr><td class="calendar">%s</td></tr>
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   517
<tr><td class="calendar">%s</td></tr>
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   518
</table>
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   519
"""
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   520
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   521
WEEKNUM_CELL = u'<td class="weeknum">%s</td>'
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
def CALENDAR(req):
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   524
    _ = req._
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   525
    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
   526
    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
   527
                                               for day in WEEKDAYS])
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   528
    return u"""<table>
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   529
<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
   530
<tr>
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   531
  %s
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   532
</tr>
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   533
%%s
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   534
</table>
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   535
""" % (CAL_HEADER,)
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   536
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   537
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   538
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
   539
"""
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   540
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   541
NO_CELL = u'<td class="noday"></td>'
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   542
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
   543
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
   544
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   545
AMPM_DAY = u'<td class="cellDay">%d</td>'
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   546
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
   547
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
   548
1f16db872f92 Back to old_calendar for now.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff changeset
   549
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
   550
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
   551
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
   552
2996
866a2c135c33 B #345282 xhtml requires to use &#160; instead of &nbsp;
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2312
diff changeset
   553
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
   554
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
   555
AMPM_WEEK_CELL = u'<td class="ampmWeekCell"><div class="cellContent">%02d:%02d - %s</div></td>'