author | Alexandre Fayolle <alexandre.fayolle@logilab.fr> |
Wed, 16 Mar 2011 09:37:46 +0100 | |
branch | oldstable |
changeset 7083 | b8e35cde46e9 |
parent 6864 | ea95004494a2 |
child 6882 | b5e34836f84e |
permissions | -rw-r--r-- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4582
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:
4582
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:
4582
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:
4582
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:
4582
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:
4582
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:
4582
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:
4582
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:
4582
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:
4582
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:
4582
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:
4582
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:
4582
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:
4582
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:
4582
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:
4582
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""" |
0 | 19 |
|
1881
75540944ae18
fix dc_description format arg
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1802
diff
changeset
|
20 |
__docformat__ = "restructuredtext en" |
75540944ae18
fix dc_description format arg
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1802
diff
changeset
|
21 |
_ = unicode |
0 | 22 |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
767
diff
changeset
|
23 |
from datetime import datetime, date, timedelta |
0 | 24 |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
25 |
from logilab.mtconverter import xml_escape |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
26 |
from logilab.common.date import ONEDAY, strptime, date_range, todate, todatetime |
0 | 27 |
|
28 |
from cubicweb.interfaces import ICalendarable |
|
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
29 |
from cubicweb.selectors import implements, adaptable |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
30 |
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
|
31 |
|
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
32 |
|
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
33 |
class ICalendarableAdapter(EntityAdapter): |
6864
ea95004494a2
[adapters] fix #1424467 caused by precedence of bw compat method while the adapter is concret for a given class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5895
diff
changeset
|
34 |
__needs_bw_compat__ = True |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
35 |
__regid__ = 'ICalendarable' |
5895
6a3f776292a5
[selectors] avoid spurious warning when using implements by design
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5726
diff
changeset
|
36 |
__select__ = implements(ICalendarable, warn=False) # XXX for bw compat, should be abstract |
5556
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 |
@property |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
39 |
@implements_adapter_compat('ICalendarable') |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
40 |
def start(self): |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
41 |
"""return start date""" |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
42 |
raise NotImplementedError |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
43 |
|
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
44 |
@property |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
45 |
@implements_adapter_compat('ICalendarable') |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
46 |
def stop(self): |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
47 |
"""return stop state""" |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
48 |
raise NotImplementedError |
0 | 49 |
|
50 |
||
1025 | 51 |
# useful constants & functions ################################################ |
0 | 52 |
|
1033
f5be65616a31
more datetime fixes and cleanup
sylvain.thenault@logilab.fr
parents:
1025
diff
changeset
|
53 |
ONEDAY = timedelta(1) |
1025 | 54 |
|
0 | 55 |
WEEKDAYS = (_("monday"), _("tuesday"), _("wednesday"), _("thursday"), |
56 |
_("friday"), _("saturday"), _("sunday")) |
|
57 |
MONTHNAMES = ( _('january'), _('february'), _('march'), _('april'), _('may'), |
|
58 |
_('june'), _('july'), _('august'), _('september'), _('october'), |
|
59 |
_('november'), _('december') |
|
60 |
) |
|
1604 | 61 |
|
1025 | 62 |
# Calendar views ############################################################## |
0 | 63 |
|
1644 | 64 |
try: |
65 |
from vobject import iCalendar |
|
0 | 66 |
|
1644 | 67 |
class iCalView(EntityView): |
68 |
"""A calendar view that generates a iCalendar file (RFC 2445) |
|
0 | 69 |
|
1644 | 70 |
Does apply to ICalendarable compatible entities |
71 |
""" |
|
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
72 |
__select__ = adaptable('ICalendarable') |
4244
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
73 |
paginable = False |
1644 | 74 |
content_type = 'text/calendar' |
75 |
title = _('iCalendar') |
|
76 |
templatable = False |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
77 |
__regid__ = 'ical' |
0 | 78 |
|
1644 | 79 |
def call(self): |
80 |
ical = iCalendar() |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
81 |
for i in range(len(self.cw_rset.rows)): |
3457
0924d0d08d60
[api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
82 |
task = self.cw_rset.complete_entity(i, 0) |
1644 | 83 |
event = ical.add('vevent') |
84 |
event.add('summary').value = task.dc_title() |
|
85 |
event.add('description').value = task.dc_description() |
|
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
86 |
icalendarable = task.cw_adapt_to('ICalendarable') |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
87 |
if icalendarable.start: |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
88 |
event.add('dtstart').value = icalendarable.start |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
89 |
if icalendarable.stop: |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
90 |
event.add('dtend').value = icalendarable.stop |
0 | 91 |
|
1644 | 92 |
buff = ical.serialize() |
93 |
if not isinstance(buff, unicode): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
94 |
buff = unicode(buff, self._cw.encoding) |
1644 | 95 |
self.w(buff) |
96 |
||
97 |
except ImportError: |
|
98 |
pass |
|
0 | 99 |
|
100 |
class hCalView(EntityView): |
|
101 |
"""A calendar view that generates a hCalendar file |
|
102 |
||
103 |
Does apply to ICalendarable compatible entities |
|
104 |
""" |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
105 |
__regid__ = 'hcal' |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
106 |
__select__ = adaptable('ICalendarable') |
4244
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
107 |
paginable = False |
0 | 108 |
title = _('hCalendar') |
524
eee3983e29e9
hcal is a microformat and can be inserted in html
sylvain.thenault@logilab.fr
parents:
431
diff
changeset
|
109 |
#templatable = False |
0 | 110 |
|
111 |
def call(self): |
|
112 |
self.w(u'<div class="hcalendar">') |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
113 |
for i in range(len(self.cw_rset.rows)): |
3457
0924d0d08d60
[api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
114 |
task = self.cw_rset.complete_entity(i, 0) |
0 | 115 |
self.w(u'<div class="vevent">') |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
116 |
self.w(u'<h3 class="summary">%s</h3>' % xml_escape(task.dc_title())) |
1881
75540944ae18
fix dc_description format arg
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1802
diff
changeset
|
117 |
self.w(u'<div class="description">%s</div>' |
75540944ae18
fix dc_description format arg
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1802
diff
changeset
|
118 |
% task.dc_description(format='text/html')) |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
119 |
icalendarable = task.cw_adapt_to('ICalendarable') |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
120 |
if icalendarable.start: |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
121 |
self.w(u'<abbr class="dtstart" title="%s">%s</abbr>' |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
122 |
% (icalendarable.start.isoformat(), |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
123 |
self._cw.format_date(icalendarable.start))) |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
124 |
if icalendarable.stop: |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
125 |
self.w(u'<abbr class="dtstop" title="%s">%s</abbr>' |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
126 |
% (icalendarable.stop.isoformat(), |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
127 |
self._cw.format_date(icalendarable.stop))) |
0 | 128 |
self.w(u'</div>') |
129 |
self.w(u'</div>') |
|
130 |
||
1025 | 131 |
|
132 |
class CalendarItemView(EntityView): |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
133 |
__regid__ = 'calendaritem' |
1025 | 134 |
|
135 |
def cell_call(self, row, col, dates=False): |
|
3457
0924d0d08d60
[api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
136 |
task = self.cw_rset.complete_entity(row, 0) |
1025 | 137 |
task.view('oneline', w=self.w) |
138 |
if dates: |
|
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
139 |
icalendarable = task.cw_adapt_to('ICalendarable') |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
140 |
if icalendarable.start and icalendarable.stop: |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
141 |
self.w('<br/> %s' % self._cw._('from %(date)s') |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
142 |
% {'date': self._cw.format_date(icalendarable.start)}) |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
143 |
self.w('<br/> %s' % self._cw._('to %(date)s') |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
144 |
% {'date': self._cw.format_date(icalendarable.stop)}) |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
145 |
else: |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
146 |
self.w('<br/>%s'%self._cw.format_date(icalendarable.start |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
147 |
or icalendarable.stop)) |
1604 | 148 |
|
1025 | 149 |
class CalendarLargeItemView(CalendarItemView): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
150 |
__regid__ = 'calendarlargeitem' |
1025 | 151 |
|
1604 | 152 |
|
0 | 153 |
class _TaskEntry(object): |
154 |
def __init__(self, task, color, index=0): |
|
155 |
self.task = task |
|
156 |
self.color = color |
|
157 |
self.index = index |
|
158 |
self.length = 1 |
|
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
159 |
icalendarable = task.cw_adapt_to('ICalendarable') |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
160 |
self.start = icalendarable.start |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
161 |
self.stop = icalendarable.stop |
0 | 162 |
|
1025 | 163 |
def in_working_hours(self): |
164 |
"""predicate returning True is the task is in working hours""" |
|
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
165 |
if todatetime(self.start).hour > 7 and todatetime(self.stop).hour < 20: |
1025 | 166 |
return True |
167 |
return False |
|
1604 | 168 |
|
1025 | 169 |
def is_one_day_task(self): |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
170 |
return self.start and self.stop and self.start.isocalendar() == self.stop.isocalendar() |
1604 | 171 |
|
172 |
||
0 | 173 |
class OneMonthCal(EntityView): |
174 |
"""At some point, this view will probably replace ampm calendars""" |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
175 |
__regid__ = 'onemonthcal' |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
176 |
__select__ = adaptable('ICalendarable') |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
177 |
|
4244
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
178 |
paginable = False |
0 | 179 |
title = _('one month') |
180 |
||
181 |
def call(self): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
182 |
self._cw.add_js('cubicweb.ajax.js') |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
183 |
self._cw.add_css('cubicweb.calendar.css') |
0 | 184 |
# XXX: restrict courses directy with RQL |
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
767
diff
changeset
|
185 |
_today = datetime.today() |
0 | 186 |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
187 |
if 'year' in self._cw.form: |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
188 |
year = int(self._cw.form['year']) |
0 | 189 |
else: |
190 |
year = _today.year |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
191 |
if 'month' in self._cw.form: |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
192 |
month = int(self._cw.form['month']) |
0 | 193 |
else: |
194 |
month = _today.month |
|
195 |
||
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
767
diff
changeset
|
196 |
first_day_of_month = date(year, month, 1) |
1033
f5be65616a31
more datetime fixes and cleanup
sylvain.thenault@logilab.fr
parents:
1025
diff
changeset
|
197 |
firstday = first_day_of_month - timedelta(first_day_of_month.weekday()) |
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
767
diff
changeset
|
198 |
if month >= 12: |
1033
f5be65616a31
more datetime fixes and cleanup
sylvain.thenault@logilab.fr
parents:
1025
diff
changeset
|
199 |
last_day_of_month = date(year + 1, 1, 1) - timedelta(1) |
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
767
diff
changeset
|
200 |
else: |
1033
f5be65616a31
more datetime fixes and cleanup
sylvain.thenault@logilab.fr
parents:
1025
diff
changeset
|
201 |
last_day_of_month = date(year, month + 1, 1) - timedelta(1) |
4582
d12b81facd1d
[calendar view] fix related to the date_range mess (max value exclusion). Calendar views authors should check if more similar fixes needed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
202 |
# date range exclude last day so we should at least add one day, hence |
d12b81facd1d
[calendar view] fix related to the date_range mess (max value exclusion). Calendar views authors should check if more similar fixes needed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
203 |
# the 7 |
d12b81facd1d
[calendar view] fix related to the date_range mess (max value exclusion). Calendar views authors should check if more similar fixes needed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
204 |
lastday = last_day_of_month + timedelta(7 - last_day_of_month.weekday()) |
0 | 205 |
month_dates = list(date_range(firstday, lastday)) |
206 |
dates = {} |
|
207 |
task_max = 0 |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
208 |
for row in xrange(self.cw_rset.rowcount): |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
209 |
task = self.cw_rset.get_entity(row, 0) |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
210 |
if len(self.cw_rset[row]) > 1 and self.cw_rset.description[row][1] == 'CWUser': |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
211 |
user = self.cw_rset.get_entity(row, 1) |
0 | 212 |
else: |
213 |
user = None |
|
214 |
the_dates = [] |
|
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
215 |
icalendarable = task.cw_adapt_to('ICalendarable') |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
216 |
tstart = icalendarable.start |
1025 | 217 |
if tstart: |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
218 |
tstart = todate(icalendarable.start) |
1025 | 219 |
if tstart > lastday: |
0 | 220 |
continue |
1025 | 221 |
the_dates = [tstart] |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
222 |
tstop = icalendarable.stop |
1025 | 223 |
if tstop: |
1800
05c36cf3c813
[calendar] ensure task.start / task.stop are available before calling todate()
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1799
diff
changeset
|
224 |
tstop = todate(tstop) |
1025 | 225 |
if tstop < firstday: |
0 | 226 |
continue |
1025 | 227 |
the_dates = [tstop] |
228 |
if tstart and tstop: |
|
229 |
if tstart.isocalendar() == tstop.isocalendar(): |
|
230 |
if firstday <= tstart <= lastday: |
|
231 |
the_dates = [tstart] |
|
0 | 232 |
else: |
1025 | 233 |
the_dates = date_range(max(tstart, firstday), |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
234 |
min(tstop + ONEDAY, lastday)) |
0 | 235 |
if not the_dates: |
236 |
continue |
|
1604 | 237 |
|
0 | 238 |
for d in the_dates: |
239 |
d_tasks = dates.setdefault((d.year, d.month, d.day), {}) |
|
1132 | 240 |
t_users = d_tasks.setdefault(task, set()) |
0 | 241 |
t_users.add( user ) |
1132 | 242 |
if len(d_tasks) > task_max: |
0 | 243 |
task_max = len(d_tasks) |
244 |
||
245 |
days = [] |
|
1132 | 246 |
nrows = max(3, task_max) |
0 | 247 |
# colors here are class names defined in cubicweb.css |
1132 | 248 |
colors = [ "col%x" % i for i in range(12) ] |
0 | 249 |
next_color_index = 0 |
250 |
||
251 |
visited_tasks = {} # holds a description of a task |
|
252 |
task_colors = {} # remember a color assigned to a task |
|
1025 | 253 |
for mdate in month_dates: |
254 |
d_tasks = dates.get((mdate.year, mdate.month, mdate.day), {}) |
|
0 | 255 |
rows = [None] * nrows |
256 |
# every task that is "visited" for the first time |
|
257 |
# require a special treatment, so we put them in |
|
258 |
# 'postpone' |
|
259 |
postpone = [] |
|
260 |
for task in d_tasks: |
|
261 |
if task in visited_tasks: |
|
262 |
task_descr = visited_tasks[ task ] |
|
263 |
rows[task_descr.index] = task_descr |
|
264 |
else: |
|
265 |
postpone.append(task) |
|
266 |
for task in postpone: |
|
267 |
# to every 'new' task we must affect a color |
|
268 |
# (which must be the same for every user concerned |
|
269 |
# by the task) |
|
1132 | 270 |
for i, t in enumerate(rows): |
0 | 271 |
if t is None: |
272 |
if task in task_colors: |
|
273 |
color = task_colors[task] |
|
274 |
else: |
|
275 |
color = colors[next_color_index] |
|
276 |
next_color_index = (next_color_index+1)%len(colors) |
|
277 |
task_colors[task] = color |
|
278 |
task_descr = _TaskEntry(task, color, i) |
|
279 |
rows[i] = task_descr |
|
280 |
visited_tasks[task] = task_descr |
|
281 |
break |
|
282 |
else: |
|
283 |
raise RuntimeError("is it possible we got it wrong?") |
|
284 |
||
285 |
days.append( rows ) |
|
286 |
||
287 |
curdate = first_day_of_month |
|
288 |
self.w(u'<div id="onemonthcalid">') |
|
289 |
# build schedule |
|
290 |
self.w(u'<table class="omcalendar">') |
|
291 |
prevlink, nextlink = self._prevnext_links(curdate) # XXX |
|
292 |
self.w(u'<tr><th><a href="%s"><<</a></th><th colspan="5">%s %s</th>' |
|
293 |
u'<th><a href="%s">>></a></th></tr>' % |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
294 |
(xml_escape(prevlink), self._cw._(curdate.strftime('%B').lower()), |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
295 |
curdate.year, xml_escape(nextlink))) |
0 | 296 |
|
297 |
# output header |
|
298 |
self.w(u'<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>' % |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
299 |
tuple(self._cw._(day) for day in WEEKDAYS)) |
0 | 300 |
# build calendar |
1025 | 301 |
for mdate, task_rows in zip(month_dates, days): |
302 |
if mdate.weekday() == 0: |
|
0 | 303 |
self.w(u'<tr>') |
1025 | 304 |
self._build_calendar_cell(mdate, task_rows, curdate) |
305 |
if mdate.weekday() == 6: |
|
0 | 306 |
self.w(u'</tr>') |
307 |
self.w(u'</table></div>') |
|
308 |
||
309 |
def _prevnext_links(self, curdate): |
|
1033
f5be65616a31
more datetime fixes and cleanup
sylvain.thenault@logilab.fr
parents:
1025
diff
changeset
|
310 |
prevdate = curdate - timedelta(31) |
f5be65616a31
more datetime fixes and cleanup
sylvain.thenault@logilab.fr
parents:
1025
diff
changeset
|
311 |
nextdate = curdate + timedelta(31) |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
312 |
rql = self.cw_rset.printable_rql() |
5713
605f571198eb
[web] ajax_replace_url superseed build_ajax_replace_url, more generic and relying on the json controller (closes #750090)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
313 |
prevlink = self._cw.ajax_replace_url('onemonthcalid', rql=rql, |
605f571198eb
[web] ajax_replace_url superseed build_ajax_replace_url, more generic and relying on the json controller (closes #750090)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
314 |
vid='onemonthcal', |
605f571198eb
[web] ajax_replace_url superseed build_ajax_replace_url, more generic and relying on the json controller (closes #750090)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
315 |
year=prevdate.year, |
605f571198eb
[web] ajax_replace_url superseed build_ajax_replace_url, more generic and relying on the json controller (closes #750090)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
316 |
month=prevdate.month) |
605f571198eb
[web] ajax_replace_url superseed build_ajax_replace_url, more generic and relying on the json controller (closes #750090)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
317 |
nextlink = self._cw.ajax_replace_url('onemonthcalid', rql=rql, |
605f571198eb
[web] ajax_replace_url superseed build_ajax_replace_url, more generic and relying on the json controller (closes #750090)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
318 |
vid='onemonthcal', |
605f571198eb
[web] ajax_replace_url superseed build_ajax_replace_url, more generic and relying on the json controller (closes #750090)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
319 |
year=nextdate.year, |
605f571198eb
[web] ajax_replace_url superseed build_ajax_replace_url, more generic and relying on the json controller (closes #750090)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
320 |
month=nextdate.month) |
0 | 321 |
return prevlink, nextlink |
322 |
||
1149 | 323 |
def _build_calendar_cell(self, celldate, rows, curdate): |
0 | 324 |
curmonth = curdate.month |
325 |
classes = "" |
|
1149 | 326 |
if celldate.month != curmonth: |
0 | 327 |
classes += " outOfRange" |
1149 | 328 |
if celldate == date.today(): |
0 | 329 |
classes += " today" |
330 |
self.w(u'<td class="cell%s">' % classes) |
|
331 |
self.w(u'<div class="calCellTitle%s">' % classes) |
|
1149 | 332 |
self.w(u'<div class="day">%s</div>' % celldate.day) |
1604 | 333 |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
334 |
if len(self.cw_rset.column_types(0)) == 1: |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
335 |
etype = list(self.cw_rset.column_types(0))[0] |
3460
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3457
diff
changeset
|
336 |
url = self._cw.build_url(vid='creation', etype=etype, |
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3457
diff
changeset
|
337 |
schedule=True, |
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3457
diff
changeset
|
338 |
start=self._cw.format_date(celldate), stop=self._cw.format_date(celldate), |
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3457
diff
changeset
|
339 |
__redirectrql=self.cw_rset.printable_rql(), |
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3457
diff
changeset
|
340 |
__redirectparams=self._cw.build_url_params(year=curdate.year, month=curmonth), |
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3457
diff
changeset
|
341 |
__redirectvid=self.__regid__ |
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3457
diff
changeset
|
342 |
) |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
343 |
self.w(u'<div class="cmd"><a href="%s">%s</a></div>' % (xml_escape(url), self._cw._(u'add'))) |
2996
866a2c135c33
B #345282 xhtml requires to use   instead of
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2312
diff
changeset
|
344 |
self.w(u' ') |
0 | 345 |
self.w(u'</div>') |
346 |
self.w(u'<div class="cellContent">') |
|
347 |
for task_descr in rows: |
|
348 |
if task_descr: |
|
349 |
task = task_descr.task |
|
350 |
self.w(u'<div class="task %s">' % task_descr.color) |
|
351 |
task.view('calendaritem', w=self.w ) |
|
352 |
url = task.absolute_url(vid='edition', |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
353 |
__redirectrql=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
|
354 |
__redirectparams=self._cw.build_url_params(year=curdate.year, month=curmonth), |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
355 |
__redirectvid=self.__regid__ |
0 | 356 |
) |
357 |
||
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
358 |
self.w(u'<div class="tooltip" ondblclick="stopPropagation(event); window.location.assign(\'%s\'); return false;">' % xml_escape(url)) |
0 | 359 |
task.view('tooltip', w=self.w ) |
360 |
self.w(u'</div>') |
|
361 |
else: |
|
362 |
self.w(u'<div class="task">') |
|
2996
866a2c135c33
B #345282 xhtml requires to use   instead of
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2312
diff
changeset
|
363 |
self.w(u" ") |
0 | 364 |
self.w(u'</div>') |
365 |
self.w(u'</div>') |
|
366 |
self.w(u'</td>') |
|
367 |
||
368 |
||
369 |
class OneWeekCal(EntityView): |
|
370 |
"""At some point, this view will probably replace ampm calendars""" |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
371 |
__regid__ = 'oneweekcal' |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
372 |
__select__ = adaptable('ICalendarable') |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
373 |
|
4244
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
374 |
paginable = False |
0 | 375 |
title = _('one week') |
1604 | 376 |
|
0 | 377 |
def call(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
378 |
self._cw.add_js( ('cubicweb.ajax.js', 'cubicweb.calendar.js') ) |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
379 |
self._cw.add_css('cubicweb.calendar.css') |
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
767
diff
changeset
|
380 |
# XXX: restrict directly with RQL |
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
767
diff
changeset
|
381 |
_today = datetime.today() |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
382 |
if 'year' in self._cw.form: |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
383 |
year = int(self._cw.form['year']) |
0 | 384 |
else: |
385 |
year = _today.year |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
386 |
if 'week' in self._cw.form: |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
387 |
week = int(self._cw.form['week']) |
0 | 388 |
else: |
1604 | 389 |
week = _today.isocalendar()[1] |
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
767
diff
changeset
|
390 |
# week - 1 since we get week number > 0 while we want it to start from 0 |
1033
f5be65616a31
more datetime fixes and cleanup
sylvain.thenault@logilab.fr
parents:
1025
diff
changeset
|
391 |
first_day_of_week = todate(strptime('%s-%s-1' % (year, week - 1), '%Y-%U-%w')) |
f5be65616a31
more datetime fixes and cleanup
sylvain.thenault@logilab.fr
parents:
1025
diff
changeset
|
392 |
lastday = first_day_of_week + timedelta(6) |
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
767
diff
changeset
|
393 |
firstday = first_day_of_week |
0 | 394 |
dates = [[] for i in range(7)] |
395 |
task_colors = {} # remember a color assigned to a task |
|
396 |
# colors here are class names defined in cubicweb.css |
|
1132 | 397 |
colors = [ "col%x" % i for i in range(12) ] |
0 | 398 |
next_color_index = 0 |
5726
c3b99606644d
[json] fix json serialization for recent simplejson implementation, and test encoding of entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5713
diff
changeset
|
399 |
done_tasks = set() |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
400 |
for row in xrange(self.cw_rset.rowcount): |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
401 |
task = self.cw_rset.get_entity(row, 0) |
5726
c3b99606644d
[json] fix json serialization for recent simplejson implementation, and test encoding of entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5713
diff
changeset
|
402 |
if task.eid in done_tasks: |
0 | 403 |
continue |
5726
c3b99606644d
[json] fix json serialization for recent simplejson implementation, and test encoding of entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5713
diff
changeset
|
404 |
done_tasks.add(task.eid) |
0 | 405 |
the_dates = [] |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
406 |
icalendarable = task.cw_adapt_to('ICalendarable') |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
407 |
tstart = icalendarable.start |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
408 |
tstop = icalendarable.stop |
1025 | 409 |
if tstart: |
1800
05c36cf3c813
[calendar] ensure task.start / task.stop are available before calling todate()
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1799
diff
changeset
|
410 |
tstart = todate(tstart) |
1025 | 411 |
if tstart > lastday: |
0 | 412 |
continue |
1025 | 413 |
the_dates = [tstart] |
414 |
if tstop: |
|
1800
05c36cf3c813
[calendar] ensure task.start / task.stop are available before calling todate()
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1799
diff
changeset
|
415 |
tstop = todate(tstop) |
1025 | 416 |
if tstop < firstday: |
0 | 417 |
continue |
1025 | 418 |
the_dates = [tstop] |
419 |
if tstart and tstop: |
|
420 |
the_dates = date_range(max(tstart, firstday), |
|
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
421 |
min(tstop + ONEDAY, lastday)) |
0 | 422 |
if not the_dates: |
423 |
continue |
|
1604 | 424 |
|
0 | 425 |
if task not in task_colors: |
426 |
task_colors[task] = colors[next_color_index] |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
767
diff
changeset
|
427 |
next_color_index = (next_color_index+1) % len(colors) |
1604 | 428 |
|
0 | 429 |
for d in the_dates: |
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
767
diff
changeset
|
430 |
day = d.weekday() |
1604 | 431 |
task_descr = _TaskEntry(task, task_colors[task]) |
0 | 432 |
dates[day].append(task_descr) |
1604 | 433 |
|
0 | 434 |
self.w(u'<div id="oneweekcalid">') |
435 |
# build schedule |
|
436 |
self.w(u'<table class="omcalendar" id="week">') |
|
437 |
prevlink, nextlink = self._prevnext_links(first_day_of_week) # XXX |
|
438 |
self.w(u'<tr><th class="transparent"></th>') |
|
439 |
self.w(u'<th><a href="%s"><<</a></th><th colspan="5">%s %s %s</th>' |
|
440 |
u'<th><a href="%s">>></a></th></tr>' % |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
441 |
(xml_escape(prevlink), first_day_of_week.year, |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
442 |
self._cw._(u'week'), first_day_of_week.isocalendar()[1], |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
443 |
xml_escape(nextlink))) |
0 | 444 |
|
445 |
# output header |
|
446 |
self.w(u'<tr>') |
|
447 |
self.w(u'<th class="transparent"></th>') # column for hours |
|
1033
f5be65616a31
more datetime fixes and cleanup
sylvain.thenault@logilab.fr
parents:
1025
diff
changeset
|
448 |
_today = date.today() |
0 | 449 |
for i, day in enumerate(WEEKDAYS): |
1033
f5be65616a31
more datetime fixes and cleanup
sylvain.thenault@logilab.fr
parents:
1025
diff
changeset
|
450 |
wdate = first_day_of_week + timedelta(i) |
f5be65616a31
more datetime fixes and cleanup
sylvain.thenault@logilab.fr
parents:
1025
diff
changeset
|
451 |
if wdate.isocalendar() == _today.isocalendar(): |
3457
0924d0d08d60
[api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
452 |
self.w(u'<th class="today">%s<br/>%s</th>' % (self._cw._(day), self._cw.format_date(wdate))) |
0 | 453 |
else: |
3457
0924d0d08d60
[api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
454 |
self.w(u'<th>%s<br/>%s</th>' % (self._cw._(day), self._cw.format_date(wdate))) |
0 | 455 |
self.w(u'</tr>') |
1604 | 456 |
|
0 | 457 |
# build week calendar |
458 |
self.w(u'<tr>') |
|
459 |
self.w(u'<td style="width:5em;">') # column for hours |
|
460 |
extra = "" |
|
461 |
for h in range(8, 20): |
|
462 |
self.w(u'<div class="hour" %s>'%extra) |
|
463 |
self.w(u'%02d:00'%h) |
|
1604 | 464 |
self.w(u'</div>') |
0 | 465 |
self.w(u'</td>') |
1604 | 466 |
|
0 | 467 |
for i, day in enumerate(WEEKDAYS): |
1033
f5be65616a31
more datetime fixes and cleanup
sylvain.thenault@logilab.fr
parents:
1025
diff
changeset
|
468 |
wdate = first_day_of_week + timedelta(i) |
0 | 469 |
classes = "" |
1033
f5be65616a31
more datetime fixes and cleanup
sylvain.thenault@logilab.fr
parents:
1025
diff
changeset
|
470 |
if wdate.isocalendar() == _today.isocalendar(): |
0 | 471 |
classes = " today" |
1033
f5be65616a31
more datetime fixes and cleanup
sylvain.thenault@logilab.fr
parents:
1025
diff
changeset
|
472 |
self.w(u'<td class="column %s" id="%s">' % (classes, day)) |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
473 |
if len(self.cw_rset.column_types(0)) == 1: |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
474 |
etype = list(self.cw_rset.column_types(0))[0] |
3460
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3457
diff
changeset
|
475 |
url = self._cw.build_url(vid='creation', etype=etype, |
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3457
diff
changeset
|
476 |
schedule=True, |
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3457
diff
changeset
|
477 |
__redirectrql=self.cw_rset.printable_rql(), |
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3457
diff
changeset
|
478 |
__redirectparams=self._cw.build_url_params(year=year, week=week), |
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3457
diff
changeset
|
479 |
__redirectvid=self.__regid__ |
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3457
diff
changeset
|
480 |
) |
1033
f5be65616a31
more datetime fixes and cleanup
sylvain.thenault@logilab.fr
parents:
1025
diff
changeset
|
481 |
extra = ' ondblclick="addCalendarItem(event, hmin=8, hmax=20, year=%s, month=%s, day=%s, duration=2, baseurl=\'%s\')"' % ( |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
482 |
wdate.year, wdate.month, wdate.day, xml_escape(url)) |
0 | 483 |
else: |
484 |
extra = "" |
|
485 |
self.w(u'<div class="columndiv"%s>'% extra) |
|
486 |
for h in range(8, 20): |
|
487 |
self.w(u'<div class="hourline" style="top:%sex;">'%((h-7)*8)) |
|
1604 | 488 |
self.w(u'</div>') |
0 | 489 |
if dates[i]: |
1033
f5be65616a31
more datetime fixes and cleanup
sylvain.thenault@logilab.fr
parents:
1025
diff
changeset
|
490 |
self._build_calendar_cell(wdate, dates[i]) |
0 | 491 |
self.w(u'</div>') |
492 |
self.w(u'</td>') |
|
493 |
self.w(u'</tr>') |
|
494 |
self.w(u'</table></div>') |
|
495 |
self.w(u'<div id="coord"></div>') |
|
2996
866a2c135c33
B #345282 xhtml requires to use   instead of
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2312
diff
changeset
|
496 |
self.w(u'<div id="debug"> </div>') |
1604 | 497 |
|
0 | 498 |
def _build_calendar_cell(self, date, task_descrs): |
1025 | 499 |
inday_tasks = [t for t in task_descrs if t.is_one_day_task() and t.in_working_hours()] |
500 |
wholeday_tasks = [t for t in task_descrs if not t.is_one_day_task()] |
|
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
501 |
inday_tasks.sort(key=lambda t:t.start) |
0 | 502 |
sorted_tasks = [] |
503 |
for i, t in enumerate(wholeday_tasks): |
|
504 |
t.index = i |
|
505 |
ncols = len(wholeday_tasks) |
|
506 |
while inday_tasks: |
|
507 |
t = inday_tasks.pop(0) |
|
508 |
for i, c in enumerate(sorted_tasks): |
|
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
509 |
if not c or c[-1].stop <= t.start: |
0 | 510 |
c.append(t) |
511 |
t.index = i+ncols |
|
512 |
break |
|
513 |
else: |
|
514 |
t.index = len(sorted_tasks) + ncols |
|
515 |
sorted_tasks.append([t]) |
|
516 |
ncols += len(sorted_tasks) |
|
517 |
if ncols == 0: |
|
518 |
return |
|
519 |
||
520 |
inday_tasks = [] |
|
521 |
for tasklist in sorted_tasks: |
|
522 |
inday_tasks += tasklist |
|
523 |
width = 100.0/ncols |
|
524 |
for task_desc in wholeday_tasks + inday_tasks: |
|
525 |
task = task_desc.task |
|
526 |
start_hour = 8 |
|
527 |
start_min = 0 |
|
528 |
stop_hour = 20 |
|
529 |
stop_min = 0 |
|
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
530 |
if task_desc.start: |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
531 |
if date < todate(task_desc.start) < date + ONEDAY: |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
532 |
start_hour = max(8, task_desc.start.hour) |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
533 |
start_min = task_desc.start.minute |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
534 |
if task_desc.stop: |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
535 |
if date < todate(task_desc.stop) < date + ONEDAY: |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
536 |
stop_hour = min(20, task_desc.stop.hour) |
0 | 537 |
if stop_hour < 20: |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
538 |
stop_min = task_desc.stop.minute |
1604 | 539 |
|
0 | 540 |
height = 100.0*(stop_hour+stop_min/60.0-start_hour-start_min/60.0)/(20-8) |
541 |
top = 100.0*(start_hour+start_min/60.0-8)/(20-8) |
|
542 |
left = width*task_desc.index |
|
543 |
style = "height: %s%%; width: %s%%; top: %s%%; left: %s%%; " % \ |
|
544 |
(height, width, top, left) |
|
545 |
self.w(u'<div class="task %s" style="%s">' % \ |
|
546 |
(task_desc.color, style)) |
|
547 |
task.view('calendaritem', dates=False, w=self.w) |
|
548 |
url = task.absolute_url(vid='edition', |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
549 |
__redirectrql=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
|
550 |
__redirectparams=self._cw.build_url_params(year=date.year, week=date.isocalendar()[1]), |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
551 |
__redirectvid=self.__regid__ |
0 | 552 |
) |
553 |
||
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
554 |
self.w(u'<div class="tooltip" ondblclick="stopPropagation(event); window.location.assign(\'%s\'); return false;">' % xml_escape(url)) |
0 | 555 |
task.view('tooltip', w=self.w) |
556 |
self.w(u'</div>') |
|
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
557 |
if task_desc.start is None: |
0 | 558 |
self.w(u'<div class="bottommarker">') |
559 |
self.w(u'<div class="bottommarkerline" style="margin: 0px 3px 0px 3px; height: 1px;">') |
|
560 |
self.w(u'</div>') |
|
561 |
self.w(u'<div class="bottommarkerline" style="margin: 0px 2px 0px 2px; height: 1px;">') |
|
562 |
self.w(u'</div>') |
|
563 |
self.w(u'<div class="bottommarkerline" style="margin: 0px 1px 0px 1px; height: 3ex; color: white; font-size: x-small; vertical-align: center; text-align: center;">') |
|
564 |
self.w(u'end') |
|
565 |
self.w(u'</div>') |
|
566 |
self.w(u'</div>') |
|
567 |
self.w(u'</div>') |
|
568 |
||
1604 | 569 |
|
0 | 570 |
def _prevnext_links(self, curdate): |
1033
f5be65616a31
more datetime fixes and cleanup
sylvain.thenault@logilab.fr
parents:
1025
diff
changeset
|
571 |
prevdate = curdate - timedelta(7) |
f5be65616a31
more datetime fixes and cleanup
sylvain.thenault@logilab.fr
parents:
1025
diff
changeset
|
572 |
nextdate = curdate + timedelta(7) |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
573 |
rql = self.cw_rset.printable_rql() |
5713
605f571198eb
[web] ajax_replace_url superseed build_ajax_replace_url, more generic and relying on the json controller (closes #750090)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
574 |
prevlink = self._cw.ajax_replace_url('oneweekcalid', rql=rql, |
605f571198eb
[web] ajax_replace_url superseed build_ajax_replace_url, more generic and relying on the json controller (closes #750090)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
575 |
vid='oneweekcal', |
605f571198eb
[web] ajax_replace_url superseed build_ajax_replace_url, more generic and relying on the json controller (closes #750090)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
576 |
year=prevdate.year, |
605f571198eb
[web] ajax_replace_url superseed build_ajax_replace_url, more generic and relying on the json controller (closes #750090)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
577 |
week=prevdate.isocalendar()[1]) |
605f571198eb
[web] ajax_replace_url superseed build_ajax_replace_url, more generic and relying on the json controller (closes #750090)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
578 |
nextlink = self._cw.ajax_replace_url('oneweekcalid', rql=rql, |
605f571198eb
[web] ajax_replace_url superseed build_ajax_replace_url, more generic and relying on the json controller (closes #750090)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
579 |
vid='oneweekcal', |
605f571198eb
[web] ajax_replace_url superseed build_ajax_replace_url, more generic and relying on the json controller (closes #750090)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
580 |
year=nextdate.year, |
605f571198eb
[web] ajax_replace_url superseed build_ajax_replace_url, more generic and relying on the json controller (closes #750090)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
581 |
week=nextdate.isocalendar()[1]) |
0 | 582 |
return prevlink, nextlink |