author | David Douard <david.douard@logilab.fr> |
Tue, 19 Jul 2016 13:50:56 +0200 | |
branch | 3.20 |
changeset 11399 | 5149a4d4cf54 |
parent 9256 | 697a8181ba30 |
child 10666 | 7f6b5f023884 |
permissions | -rw-r--r-- |
8941
7b26fe71404f
drop xhtml content-type support (closes #2065651)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8307
diff
changeset
|
1 |
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
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
|
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 |
|
6736
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
23 |
import copy |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
24 |
from datetime import timedelta |
0 | 25 |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
26 |
from logilab.mtconverter import xml_escape |
6736
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
27 |
from logilab.common.date import todatetime |
0 | 28 |
|
8153
e225e70239ed
[views] calendar id in CalendarView must be unique (closes #2143864)
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
7183
diff
changeset
|
29 |
from cubicweb.utils import json_dumps, make_uid |
9256
697a8181ba30
remove 3.9 bw compat
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8941
diff
changeset
|
30 |
from cubicweb.predicates import adaptable |
697a8181ba30
remove 3.9 bw compat
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8941
diff
changeset
|
31 |
from cubicweb.view import EntityView, EntityAdapter |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
32 |
|
6736
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
33 |
# useful constants & functions ################################################ |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
34 |
|
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
35 |
ONEDAY = timedelta(1) |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
36 |
|
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
37 |
WEEKDAYS = (_("monday"), _("tuesday"), _("wednesday"), _("thursday"), |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
38 |
_("friday"), _("saturday"), _("sunday")) |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
39 |
MONTHNAMES = ( _('january'), _('february'), _('march'), _('april'), _('may'), |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
40 |
_('june'), _('july'), _('august'), _('september'), _('october'), |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
41 |
_('november'), _('december') |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
42 |
) |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
43 |
|
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
44 |
|
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
45 |
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
|
46 |
__needs_bw_compat__ = True |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
47 |
__regid__ = 'ICalendarable' |
9256
697a8181ba30
remove 3.9 bw compat
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8941
diff
changeset
|
48 |
__abstract__ = True |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
49 |
|
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
50 |
@property |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
51 |
def start(self): |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
52 |
"""return start date""" |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
53 |
raise NotImplementedError |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
54 |
|
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
55 |
@property |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
56 |
def stop(self): |
6736
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
57 |
"""return stop date""" |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
58 |
raise NotImplementedError |
0 | 59 |
|
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 |
|
148 |
||
0 | 149 |
class _TaskEntry(object): |
150 |
def __init__(self, task, color, index=0): |
|
151 |
self.task = task |
|
152 |
self.color = color |
|
153 |
self.index = index |
|
154 |
self.length = 1 |
|
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
155 |
icalendarable = task.cw_adapt_to('ICalendarable') |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
156 |
self.start = icalendarable.start |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
157 |
self.stop = icalendarable.stop |
0 | 158 |
|
1025 | 159 |
def in_working_hours(self): |
160 |
"""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
|
161 |
if todatetime(self.start).hour > 7 and todatetime(self.stop).hour < 20: |
1025 | 162 |
return True |
163 |
return False |
|
1604 | 164 |
|
1025 | 165 |
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
|
166 |
return self.start and self.stop and self.start.isocalendar() == self.stop.isocalendar() |
1604 | 167 |
|
168 |
||
6736
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
169 |
class CalendarView(EntityView): |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
170 |
__regid__ = 'calendar' |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
171 |
__select__ = adaptable('ICalendarable') |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
172 |
|
4244
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
173 |
paginable = False |
6736
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
174 |
title = _('calendar') |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
175 |
|
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
176 |
fullcalendar_options = { |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
177 |
'firstDay': 1, |
8287
2d660890d3e8
[js] translate calendar in french (closes #2167866)
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
8153
diff
changeset
|
178 |
'firstHour': 8, |
2d660890d3e8
[js] translate calendar in french (closes #2167866)
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
8153
diff
changeset
|
179 |
'defaultView': 'month', |
2d660890d3e8
[js] translate calendar in french (closes #2167866)
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
8153
diff
changeset
|
180 |
'editable': True, |
6736
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
181 |
'header': {'left': 'prev,next today', |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
182 |
'center': 'title', |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
183 |
'right': 'month,agendaWeek,agendaDay', |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
184 |
}, |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
185 |
} |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
186 |
|
0 | 187 |
def call(self): |
6736
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
188 |
self._cw.add_css(('fullcalendar.css', 'cubicweb.calendar.css')) |
8295
302dcb3c6858
[js] fix $.fullCalendar.regional call (closes #2232028)
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
8290
diff
changeset
|
189 |
self._cw.add_js(('jquery.ui.js', 'fullcalendar.min.js', 'jquery.qtip.min.js', 'fullcalendar.locale.js')) |
8153
e225e70239ed
[views] calendar id in CalendarView must be unique (closes #2143864)
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
7183
diff
changeset
|
190 |
self.calendar_id = 'cal' + make_uid('uid') |
6736
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
191 |
self.add_onload() |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
192 |
# write calendar div to load jquery fullcalendar object |
8153
e225e70239ed
[views] calendar id in CalendarView must be unique (closes #2143864)
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
7183
diff
changeset
|
193 |
self.w(u'<div id="%s"></div>' % self.calendar_id) |
1604 | 194 |
|
6736
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
195 |
def add_onload(self): |
8290
d07dadd8f664
fix events display in calendar (closes #2167866)
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
8287
diff
changeset
|
196 |
fullcalendar_options = self.fullcalendar_options.copy() |
d07dadd8f664
fix events display in calendar (closes #2167866)
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
8287
diff
changeset
|
197 |
fullcalendar_options['events'] = self.get_events() |
8287
2d660890d3e8
[js] translate calendar in french (closes #2167866)
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
8153
diff
changeset
|
198 |
# i18n |
6736
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
199 |
# js callback to add a tooltip and to put html in event's title |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
200 |
js = """ |
8287
2d660890d3e8
[js] translate calendar in french (closes #2167866)
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
8153
diff
changeset
|
201 |
var options = $.fullCalendar.regional('%s', %s); |
6736
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
202 |
options.eventRender = function(event, $element) { |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
203 |
// add a tooltip for each event |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
204 |
var div = '<div class="tooltip">'+ event.description+ '</div>'; |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
205 |
$element.append(div); |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
206 |
// allow to have html tags in event's title |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
207 |
$element.find('span.fc-event-title').html($element.find('span.fc-event-title').text()); |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
208 |
}; |
8153
e225e70239ed
[views] calendar id in CalendarView must be unique (closes #2143864)
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
7183
diff
changeset
|
209 |
$("#%s").fullCalendar(options); |
6736
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
210 |
""" #" |
8290
d07dadd8f664
fix events display in calendar (closes #2167866)
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
8287
diff
changeset
|
211 |
self._cw.add_onload(js % (self._cw.lang, json_dumps(fullcalendar_options), self.calendar_id)) |
1604 | 212 |
|
6736
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
213 |
def get_events(self): |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
214 |
events = [] |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
215 |
for entity in self.cw_rset.entities(): |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
216 |
icalendarable = entity.cw_adapt_to('ICalendarable') |
7183
5ea2bfd55399
[web] fix CalendarView : both icalendarable.start and icalendarable.stop dates can be None
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6882
diff
changeset
|
217 |
if not (icalendarable.start and icalendarable.stop): |
5ea2bfd55399
[web] fix CalendarView : both icalendarable.start and icalendarable.stop dates can be None
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6882
diff
changeset
|
218 |
continue |
5ea2bfd55399
[web] fix CalendarView : both icalendarable.start and icalendarable.stop dates can be None
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6882
diff
changeset
|
219 |
start_date = icalendarable.start or icalendarable.stop |
6736
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
220 |
event = {'eid': entity.eid, |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
221 |
'title': entity.view('calendaritem'), |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
222 |
'url': xml_escape(entity.absolute_url()), |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
223 |
'className': 'calevent', |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
224 |
'description': entity.view('tooltip'), |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
225 |
} |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
226 |
event['start'] = start_date.strftime('%Y-%m-%dT%H:%M') |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
227 |
event['allDay'] = True |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
228 |
if icalendarable.stop: |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
229 |
event['end'] = icalendarable.stop.strftime('%Y-%m-%dT%H:%M') |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
230 |
event['allDay'] = False |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
231 |
events.append(event) |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
232 |
return events |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
233 |
|
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
234 |
class OneMonthCal(CalendarView): |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
235 |
__regid__ = 'onemonthcal' |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
236 |
|
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
237 |
title = _('one month') |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
238 |
|
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
239 |
class OneWeekCal(CalendarView): |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
240 |
__regid__ = 'oneweekcal' |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
241 |
|
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
242 |
title = _('one week') |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
243 |
fullcalendar_options = CalendarView.fullcalendar_options.copy() |
36ed2bf7ad3d
[#615712] replace calendar views with views using fullcalendar jquery plugin (remove old_calendar)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
244 |
fullcalendar_options['defaultView'] = 'agendaWeek' |