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