author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> |
Fri, 27 Aug 2010 13:44:55 +0200 | |
branch | stable |
changeset 6165 | 7da7c270bbbd |
parent 5877 | 0c7b7b76a84f |
child 6039 | 6e84db1b3e44 |
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:
5113
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:
5113
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:
5113
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:
5113
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:
5113
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:
5113
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:
5113
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:
5113
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:
5113
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:
5113
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:
5113
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:
5113
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:
5113
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:
5113
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:
5113
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:
5113
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
0 | 18 |
"""Primary view for bookmarks + user's bookmarks box |
19 |
||
20 |
""" |
|
21 |
__docformat__ = "restructuredtext en" |
|
22 |
||
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
23 |
from logilab.mtconverter import xml_escape |
0 | 24 |
|
25 |
from cubicweb import Unauthorized |
|
5877
0c7b7b76a84f
[selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5658
diff
changeset
|
26 |
from cubicweb.selectors import is_instance, one_line_rset |
0 | 27 |
from cubicweb.web.htmlwidgets import BoxWidget, BoxMenu, RawBoxItem |
4306
01e5efc0d823
move bookmark related uicfg stuff into bookmark specific module, use the EditableURLWidget widget for Bookmark.path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
28 |
from cubicweb.web import action, box, uicfg, formwidgets as fw |
1639 | 29 |
from cubicweb.web.views import primary |
1151 | 30 |
|
3247
a6243d9585ba
hide bookmarked_by relation from addrelated menu, we've a specific box for bookmarks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
31 |
_abaa = uicfg.actionbox_appearsin_addmenu |
a6243d9585ba
hide bookmarked_by relation from addrelated menu, we've a specific box for bookmarks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
32 |
_abaa.tag_subject_of(('*', 'bookmarked_by', '*'), False) |
a6243d9585ba
hide bookmarked_by relation from addrelated menu, we've a specific box for bookmarks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
33 |
_abaa.tag_object_of(('*', 'bookmarked_by', '*'), False) |
0 | 34 |
|
4306
01e5efc0d823
move bookmark related uicfg stuff into bookmark specific module, use the EditableURLWidget widget for Bookmark.path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
35 |
_afs = uicfg.autoform_section |
01e5efc0d823
move bookmark related uicfg stuff into bookmark specific module, use the EditableURLWidget widget for Bookmark.path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
36 |
_afs.tag_object_of(('*', 'bookmarked_by', 'CWUser'), 'main', 'metadata') |
01e5efc0d823
move bookmark related uicfg stuff into bookmark specific module, use the EditableURLWidget widget for Bookmark.path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
37 |
_afs.tag_attribute(('Bookmark', 'path'), 'main', 'attributes') |
01e5efc0d823
move bookmark related uicfg stuff into bookmark specific module, use the EditableURLWidget widget for Bookmark.path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
38 |
_afs.tag_attribute(('Bookmark', 'path'), 'muledit', 'attributes') |
01e5efc0d823
move bookmark related uicfg stuff into bookmark specific module, use the EditableURLWidget widget for Bookmark.path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
39 |
|
01e5efc0d823
move bookmark related uicfg stuff into bookmark specific module, use the EditableURLWidget widget for Bookmark.path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
40 |
_affk = uicfg.autoform_field_kwargs |
4311
e9e93967b7b5
oopb, widget has been renamed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4309
diff
changeset
|
41 |
_affk.tag_attribute(('Bookmark', 'path'), {'widget': fw.EditableURLWidget}) |
4306
01e5efc0d823
move bookmark related uicfg stuff into bookmark specific module, use the EditableURLWidget widget for Bookmark.path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
42 |
|
01e5efc0d823
move bookmark related uicfg stuff into bookmark specific module, use the EditableURLWidget widget for Bookmark.path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
43 |
|
1321
c5655237f08a
we have now actual classes in rwidgets
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
44 |
class FollowAction(action.Action): |
3408
c92170fca813
[api] use __regid__ instead of deprecated id
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3247
diff
changeset
|
45 |
__regid__ = 'follow' |
5877
0c7b7b76a84f
[selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5658
diff
changeset
|
46 |
__select__ = one_line_rset() & is_instance('Bookmark') |
631
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
47 |
|
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
48 |
title = _('follow') |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
49 |
category = 'mainactions' |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1321
diff
changeset
|
50 |
|
631
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
51 |
def url(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3408
diff
changeset
|
52 |
return self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0).actual_url() |
631
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
53 |
|
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
54 |
|
1639 | 55 |
class BookmarkPrimaryView(primary.PrimaryView): |
5877
0c7b7b76a84f
[selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5658
diff
changeset
|
56 |
__select__ = is_instance('Bookmark') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1321
diff
changeset
|
57 |
|
0 | 58 |
def cell_call(self, row, col): |
59 |
"""the primary view for bookmark entity""" |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3408
diff
changeset
|
60 |
entity = self.cw_rset.complete_entity(row, col) |
2996
866a2c135c33
B #345282 xhtml requires to use   instead of
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2476
diff
changeset
|
61 |
self.w(u' ') |
0 | 62 |
self.w(u"<span class='title'><b>") |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3408
diff
changeset
|
63 |
self.w(u"%s : %s" % (self._cw._('Bookmark'), xml_escape(entity.title))) |
0 | 64 |
self.w(u"</b></span>") |
65 |
self.w(u'<br/><br/><div class="content"><a href="%s">' % ( |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
66 |
xml_escape(entity.actual_url()))) |
0 | 67 |
self.w(u'</a>') |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3408
diff
changeset
|
68 |
self.w(u'<p>%s%s</p>' % (self._cw._('Used by:'), ', '.join(xml_escape(u.name()) |
0 | 69 |
for u in entity.bookmarked_by))) |
70 |
self.w(u'</div>') |
|
71 |
||
72 |
||
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1321
diff
changeset
|
73 |
class BookmarksBox(box.UserRQLBoxTemplate): |
0 | 74 |
"""display a box containing all user's bookmarks""" |
3408
c92170fca813
[api] use __regid__ instead of deprecated id
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3247
diff
changeset
|
75 |
__regid__ = 'bookmarks_box' |
0 | 76 |
order = 40 |
77 |
title = _('bookmarks') |
|
78 |
rql = ('Any B,T,P ORDERBY lower(T) ' |
|
79 |
'WHERE B is Bookmark,B title T, B path P, B bookmarked_by U, ' |
|
80 |
'U eid %(x)s') |
|
81 |
etype = 'Bookmark' |
|
82 |
rtype = 'bookmarked_by' |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1321
diff
changeset
|
83 |
|
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1321
diff
changeset
|
84 |
|
0 | 85 |
def call(self, **kwargs): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3408
diff
changeset
|
86 |
req = self._cw |
0 | 87 |
ueid = req.user.eid |
88 |
try: |
|
89 |
rset = req.execute(self.rql, {'x': ueid}) |
|
90 |
except Unauthorized: |
|
91 |
# can't access to something in the query, forget this box |
|
92 |
return |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3408
diff
changeset
|
93 |
box = BoxWidget(req._(self.title), self.__regid__) |
0 | 94 |
box.listing_class = 'sideBox' |
4045
f4a52abb6f4f
cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3720
diff
changeset
|
95 |
rschema = self._cw.vreg.schema.rschema(self.rtype) |
f4a52abb6f4f
cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3720
diff
changeset
|
96 |
eschema = self._cw.vreg.schema.eschema(self.etype) |
0 | 97 |
candelete = rschema.has_perm(req, 'delete', toeid=ueid) |
98 |
if candelete: |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5426
diff
changeset
|
99 |
req.add_js('cubicweb.ajax.js') |
0 | 100 |
else: |
101 |
dlink = None |
|
102 |
for bookmark in rset.entities(): |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
103 |
label = '<a href="%s">%s</a>' % (xml_escape(bookmark.action_url()), |
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
104 |
xml_escape(bookmark.title)) |
0 | 105 |
if candelete: |
106 |
dlink = u'[<a href="javascript:removeBookmark(%s)" title="%s">-</a>]' % ( |
|
107 |
bookmark.eid, _('delete this bookmark')) |
|
108 |
label = '%s %s' % (dlink, label) |
|
852
105893288777
simplify css style
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
0
diff
changeset
|
109 |
box.append(RawBoxItem(label)) |
0 | 110 |
if eschema.has_perm(req, 'add') and rschema.has_perm(req, 'add', toeid=ueid): |
852
105893288777
simplify css style
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
0
diff
changeset
|
111 |
boxmenu = BoxMenu(req._('manage bookmarks')) |
0 | 112 |
linkto = 'bookmarked_by:%s:subject' % ueid |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
113 |
# use a relative path so that we can move the instance without |
0 | 114 |
# loosing bookmarks |
115 |
path = req.relative_path() |
|
4309 | 116 |
# XXX if vtitle specified in params, extract it and use it as default value |
117 |
# for bookmark's title |
|
0 | 118 |
url = self.create_url(self.etype, __linkto=linkto, path=path) |
119 |
boxmenu.append(self.mk_action(req._('bookmark this page'), url, |
|
120 |
category='manage', id='bookmark')) |
|
121 |
if rset: |
|
122 |
if req.user.is_in_group('managers'): |
|
123 |
bookmarksrql = 'Bookmark B WHERE B bookmarked_by U, U eid %s' % ueid |
|
124 |
erset = rset |
|
125 |
else: |
|
126 |
# we can't edit shared bookmarks we don't own |
|
127 |
bookmarksrql = 'Bookmark B WHERE B bookmarked_by U, B owned_by U, U eid %(x)s' |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5113
diff
changeset
|
128 |
erset = req.execute(bookmarksrql, {'x': ueid}, |
5113
f8cbdb51e6d4
[cleanup] tb already printed by self.exception; add note
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4311
diff
changeset
|
129 |
build_descr=False) |
0 | 130 |
bookmarksrql %= {'x': ueid} |
131 |
if erset: |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3408
diff
changeset
|
132 |
url = self._cw.build_url(vid='muledit', rql=bookmarksrql) |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3408
diff
changeset
|
133 |
boxmenu.append(self.mk_action(self._cw._('edit bookmarks'), url, category='manage')) |
0 | 134 |
url = req.user.absolute_url(vid='xaddrelation', rtype='bookmarked_by', |
135 |
target='subject') |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3408
diff
changeset
|
136 |
boxmenu.append(self.mk_action(self._cw._('pick existing bookmarks'), url, category='manage')) |
0 | 137 |
box.append(boxmenu) |
138 |
if not box.is_empty(): |
|
139 |
box.render(self.w) |