author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Tue, 21 Jul 2009 12:44:36 +0200 | |
changeset 2400 | 17b1f0b80fe8 |
parent 2312 | af4d8f75c5db |
child 2476 | 1294a6bdf3bf |
permissions | -rw-r--r-- |
0 | 1 |
"""Primary view for bookmarks + user's bookmarks box |
2 |
||
3 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1739
diff
changeset
|
4 |
:copyright: 2001-2009 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 |
|
692
800592b8d39b
replace deprecated cubicweb.common.selectors by its new module path (cubicweb.selectors)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
631
diff
changeset
|
13 |
from cubicweb.selectors import implements |
0 | 14 |
from cubicweb.web.htmlwidgets import BoxWidget, BoxMenu, RawBoxItem |
1739 | 15 |
from cubicweb.web import action, box |
1639 | 16 |
from cubicweb.web.views import primary |
1151 | 17 |
|
0 | 18 |
|
1321
c5655237f08a
we have now actual classes in rwidgets
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
19 |
class FollowAction(action.Action): |
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
|
20 |
id = 'follow' |
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
21 |
__select__ = 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
|
22 |
|
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
|
23 |
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
|
24 |
category = 'mainactions' |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1321
diff
changeset
|
25 |
|
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
|
26 |
def url(self): |
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
|
27 |
return self.rset.get_entity(self.row or 0, self.col or 0).actual_url() |
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
|
28 |
|
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
|
29 |
|
1639 | 30 |
class BookmarkPrimaryView(primary.PrimaryView): |
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
31 |
__select__ = implements('Bookmark') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1321
diff
changeset
|
32 |
|
0 | 33 |
def cell_call(self, row, col): |
34 |
"""the primary view for bookmark entity""" |
|
35 |
entity = self.complete_entity(row, col) |
|
36 |
self.w(u' ') |
|
37 |
self.w(u"<span class='title'><b>") |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
38 |
self.w(u"%s : %s" % (self.req._('Bookmark'), xml_escape(entity.title))) |
0 | 39 |
self.w(u"</b></span>") |
40 |
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
|
41 |
xml_escape(entity.actual_url()))) |
0 | 42 |
self.w(u'</a>') |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
43 |
self.w(u'<p>%s%s</p>' % (self.req._('Used by:'), ', '.join(xml_escape(u.name()) |
0 | 44 |
for u in entity.bookmarked_by))) |
45 |
self.w(u'</div>') |
|
46 |
||
47 |
||
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1321
diff
changeset
|
48 |
class BookmarksBox(box.UserRQLBoxTemplate): |
0 | 49 |
"""display a box containing all user's bookmarks""" |
50 |
id = 'bookmarks_box' |
|
51 |
order = 40 |
|
52 |
title = _('bookmarks') |
|
53 |
rql = ('Any B,T,P ORDERBY lower(T) ' |
|
54 |
'WHERE B is Bookmark,B title T, B path P, B bookmarked_by U, ' |
|
55 |
'U eid %(x)s') |
|
56 |
etype = 'Bookmark' |
|
57 |
rtype = 'bookmarked_by' |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1321
diff
changeset
|
58 |
|
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1321
diff
changeset
|
59 |
|
0 | 60 |
def call(self, **kwargs): |
61 |
req = self.req |
|
62 |
ueid = req.user.eid |
|
63 |
try: |
|
64 |
rset = req.execute(self.rql, {'x': ueid}) |
|
65 |
except Unauthorized: |
|
66 |
# can't access to something in the query, forget this box |
|
67 |
return |
|
68 |
box = BoxWidget(req._(self.title), self.id) |
|
69 |
box.listing_class = 'sideBox' |
|
70 |
rschema = self.schema.rschema(self.rtype) |
|
71 |
eschema = self.schema.eschema(self.etype) |
|
72 |
candelete = rschema.has_perm(req, 'delete', toeid=ueid) |
|
73 |
if candelete: |
|
74 |
req.add_js( ('cubicweb.ajax.js', 'cubicweb.bookmarks.js') ) |
|
75 |
else: |
|
76 |
dlink = None |
|
77 |
for bookmark in rset.entities(): |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
78 |
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
|
79 |
xml_escape(bookmark.title)) |
0 | 80 |
if candelete: |
81 |
dlink = u'[<a href="javascript:removeBookmark(%s)" title="%s">-</a>]' % ( |
|
82 |
bookmark.eid, _('delete this bookmark')) |
|
83 |
label = '%s %s' % (dlink, label) |
|
852
105893288777
simplify css style
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
0
diff
changeset
|
84 |
box.append(RawBoxItem(label)) |
0 | 85 |
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
|
86 |
boxmenu = BoxMenu(req._('manage bookmarks')) |
0 | 87 |
linkto = 'bookmarked_by:%s:subject' % ueid |
88 |
# use a relative path so that we can move the application without |
|
89 |
# loosing bookmarks |
|
90 |
path = req.relative_path() |
|
91 |
url = self.create_url(self.etype, __linkto=linkto, path=path) |
|
92 |
boxmenu.append(self.mk_action(req._('bookmark this page'), url, |
|
93 |
category='manage', id='bookmark')) |
|
94 |
if rset: |
|
95 |
if req.user.is_in_group('managers'): |
|
96 |
bookmarksrql = 'Bookmark B WHERE B bookmarked_by U, U eid %s' % ueid |
|
97 |
erset = rset |
|
98 |
else: |
|
99 |
# we can't edit shared bookmarks we don't own |
|
100 |
bookmarksrql = 'Bookmark B WHERE B bookmarked_by U, B owned_by U, U eid %(x)s' |
|
101 |
erset = req.execute(bookmarksrql, {'x': ueid}, 'x', |
|
102 |
build_descr=False) |
|
103 |
bookmarksrql %= {'x': ueid} |
|
104 |
if erset: |
|
105 |
url = self.build_url(vid='muledit', rql=bookmarksrql) |
|
106 |
boxmenu.append(self.mk_action(self.req._('edit bookmarks'), url, category='manage')) |
|
107 |
url = req.user.absolute_url(vid='xaddrelation', rtype='bookmarked_by', |
|
108 |
target='subject') |
|
109 |
boxmenu.append(self.mk_action(self.req._('pick existing bookmarks'), url, category='manage')) |
|
110 |
box.append(boxmenu) |
|
111 |
if not box.is_empty(): |
|
112 |
box.render(self.w) |