author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 16 Feb 2010 10:33:48 +0100 | |
changeset 4595 | bb08a75832e6 |
parent 4311 | e9e93967b7b5 |
child 5113 | f8cbdb51e6d4 |
permissions | -rw-r--r-- |
0 | 1 |
"""Primary view for bookmarks + user's bookmarks box |
2 |
||
3 |
:organization: Logilab |
|
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3718
diff
changeset
|
4 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1739
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 7 |
""" |
8 |
__docformat__ = "restructuredtext en" |
|
9 |
||
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
10 |
from logilab.mtconverter import xml_escape |
0 | 11 |
|
12 |
from cubicweb import Unauthorized |
|
3718
ae49707df724
restrict follow action to one line rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3247
diff
changeset
|
13 |
from cubicweb.selectors import implements, one_line_rset |
0 | 14 |
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
|
15 |
from cubicweb.web import action, box, uicfg, formwidgets as fw |
1639 | 16 |
from cubicweb.web.views import primary |
1151 | 17 |
|
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
|
18 |
_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
|
19 |
_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
|
20 |
_abaa.tag_object_of(('*', 'bookmarked_by', '*'), False) |
0 | 21 |
|
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
|
22 |
_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
|
23 |
_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
|
24 |
_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
|
25 |
_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
|
26 |
|
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
|
27 |
_affk = uicfg.autoform_field_kwargs |
4311
e9e93967b7b5
oopb, widget has been renamed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4309
diff
changeset
|
28 |
_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
|
29 |
|
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
|
30 |
|
1321
c5655237f08a
we have now actual classes in rwidgets
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
31 |
class FollowAction(action.Action): |
3408
c92170fca813
[api] use __regid__ instead of deprecated id
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3247
diff
changeset
|
32 |
__regid__ = 'follow' |
3718
ae49707df724
restrict follow action to one line rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3247
diff
changeset
|
33 |
__select__ = one_line_rset() & implements('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
|
34 |
|
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
|
35 |
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
|
36 |
category = 'mainactions' |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1321
diff
changeset
|
37 |
|
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
|
38 |
def url(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3408
diff
changeset
|
39 |
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
|
40 |
|
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
|
41 |
|
1639 | 42 |
class BookmarkPrimaryView(primary.PrimaryView): |
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
43 |
__select__ = implements('Bookmark') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1321
diff
changeset
|
44 |
|
0 | 45 |
def cell_call(self, row, col): |
46 |
"""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
|
47 |
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
|
48 |
self.w(u' ') |
0 | 49 |
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
|
50 |
self.w(u"%s : %s" % (self._cw._('Bookmark'), xml_escape(entity.title))) |
0 | 51 |
self.w(u"</b></span>") |
52 |
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
|
53 |
xml_escape(entity.actual_url()))) |
0 | 54 |
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
|
55 |
self.w(u'<p>%s%s</p>' % (self._cw._('Used by:'), ', '.join(xml_escape(u.name()) |
0 | 56 |
for u in entity.bookmarked_by))) |
57 |
self.w(u'</div>') |
|
58 |
||
59 |
||
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1321
diff
changeset
|
60 |
class BookmarksBox(box.UserRQLBoxTemplate): |
0 | 61 |
"""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
|
62 |
__regid__ = 'bookmarks_box' |
0 | 63 |
order = 40 |
64 |
title = _('bookmarks') |
|
65 |
rql = ('Any B,T,P ORDERBY lower(T) ' |
|
66 |
'WHERE B is Bookmark,B title T, B path P, B bookmarked_by U, ' |
|
67 |
'U eid %(x)s') |
|
68 |
etype = 'Bookmark' |
|
69 |
rtype = 'bookmarked_by' |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1321
diff
changeset
|
70 |
|
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1321
diff
changeset
|
71 |
|
0 | 72 |
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
|
73 |
req = self._cw |
0 | 74 |
ueid = req.user.eid |
75 |
try: |
|
76 |
rset = req.execute(self.rql, {'x': ueid}) |
|
77 |
except Unauthorized: |
|
78 |
# can't access to something in the query, forget this box |
|
79 |
return |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3408
diff
changeset
|
80 |
box = BoxWidget(req._(self.title), self.__regid__) |
0 | 81 |
box.listing_class = 'sideBox' |
4045
f4a52abb6f4f
cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3720
diff
changeset
|
82 |
rschema = self._cw.vreg.schema.rschema(self.rtype) |
f4a52abb6f4f
cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3720
diff
changeset
|
83 |
eschema = self._cw.vreg.schema.eschema(self.etype) |
0 | 84 |
candelete = rschema.has_perm(req, 'delete', toeid=ueid) |
85 |
if candelete: |
|
86 |
req.add_js( ('cubicweb.ajax.js', 'cubicweb.bookmarks.js') ) |
|
87 |
else: |
|
88 |
dlink = None |
|
89 |
for bookmark in rset.entities(): |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
90 |
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
|
91 |
xml_escape(bookmark.title)) |
0 | 92 |
if candelete: |
93 |
dlink = u'[<a href="javascript:removeBookmark(%s)" title="%s">-</a>]' % ( |
|
94 |
bookmark.eid, _('delete this bookmark')) |
|
95 |
label = '%s %s' % (dlink, label) |
|
852
105893288777
simplify css style
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
0
diff
changeset
|
96 |
box.append(RawBoxItem(label)) |
0 | 97 |
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
|
98 |
boxmenu = BoxMenu(req._('manage bookmarks')) |
0 | 99 |
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
|
100 |
# use a relative path so that we can move the instance without |
0 | 101 |
# loosing bookmarks |
102 |
path = req.relative_path() |
|
4309 | 103 |
# XXX if vtitle specified in params, extract it and use it as default value |
104 |
# for bookmark's title |
|
0 | 105 |
url = self.create_url(self.etype, __linkto=linkto, path=path) |
106 |
boxmenu.append(self.mk_action(req._('bookmark this page'), url, |
|
107 |
category='manage', id='bookmark')) |
|
108 |
if rset: |
|
109 |
if req.user.is_in_group('managers'): |
|
110 |
bookmarksrql = 'Bookmark B WHERE B bookmarked_by U, U eid %s' % ueid |
|
111 |
erset = rset |
|
112 |
else: |
|
113 |
# we can't edit shared bookmarks we don't own |
|
114 |
bookmarksrql = 'Bookmark B WHERE B bookmarked_by U, B owned_by U, U eid %(x)s' |
|
115 |
erset = req.execute(bookmarksrql, {'x': ueid}, 'x', |
|
116 |
build_descr=False) |
|
117 |
bookmarksrql %= {'x': ueid} |
|
118 |
if erset: |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3408
diff
changeset
|
119 |
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
|
120 |
boxmenu.append(self.mk_action(self._cw._('edit bookmarks'), url, category='manage')) |
0 | 121 |
url = req.user.absolute_url(vid='xaddrelation', rtype='bookmarked_by', |
122 |
target='subject') |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3408
diff
changeset
|
123 |
boxmenu.append(self.mk_action(self._cw._('pick existing bookmarks'), url, category='manage')) |
0 | 124 |
box.append(boxmenu) |
125 |
if not box.is_empty(): |
|
126 |
box.render(self.w) |