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