author | sylvain.thenault@logilab.fr |
Fri, 17 Apr 2009 18:45:06 +0200 | |
branch | tls-sprint |
changeset 1402 | 04b7afb14b50 |
parent 1321 | c5655237f08a |
child 1498 | 2c6eec0b46b9 |
permissions | -rw-r--r-- |
0 | 1 |
"""Primary view for bookmarks + user's bookmarks box |
2 |
||
3 |
:organization: Logilab |
|
1151 | 4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
0 | 5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
6 |
""" |
|
7 |
__docformat__ = "restructuredtext en" |
|
8 |
||
9 |
from logilab.mtconverter import html_escape |
|
10 |
||
11 |
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
|
12 |
from cubicweb.selectors import implements |
0 | 13 |
from cubicweb.web.htmlwidgets import BoxWidget, BoxMenu, RawBoxItem |
1321
c5655237f08a
we have now actual classes in rwidgets
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
14 |
from cubicweb.web import action, formwidgets |
0 | 15 |
from cubicweb.web.box import UserRQLBoxTemplate |
16 |
from cubicweb.web.views.baseviews import PrimaryView |
|
1153 | 17 |
from cubicweb.web.views.editforms import AutomaticEntityForm |
1151 | 18 |
|
19 |
AutomaticEntityForm.rcategories.set_rtag('primary', 'path', 'subject', 'Bookmark') |
|
1321
c5655237f08a
we have now actual classes in rwidgets
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
20 |
AutomaticEntityForm.rwidgets.set_rtag(formwidgets.TextInput, 'path', 'subject', 'Bookmark') |
0 | 21 |
|
22 |
||
1321
c5655237f08a
we have now actual classes in rwidgets
sylvain.thenault@logilab.fr
parents:
1153
diff
changeset
|
23 |
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
|
24 |
id = 'follow' |
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
25 |
__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
|
26 |
|
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 |
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
|
28 |
category = 'mainactions' |
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 |
|
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
|
30 |
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
|
31 |
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
|
32 |
|
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
|
33 |
|
0 | 34 |
class BookmarkPrimaryView(PrimaryView): |
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
35 |
__select__ = implements('Bookmark') |
0 | 36 |
|
37 |
def cell_call(self, row, col): |
|
38 |
"""the primary view for bookmark entity""" |
|
39 |
entity = self.complete_entity(row, col) |
|
40 |
self.w(u' ') |
|
41 |
self.w(u"<span class='title'><b>") |
|
42 |
self.w(u"%s : %s" % (self.req._('Bookmark'), html_escape(entity.title))) |
|
43 |
self.w(u"</b></span>") |
|
44 |
self.w(u'<br/><br/><div class="content"><a href="%s">' % ( |
|
45 |
html_escape(entity.actual_url()))) |
|
46 |
self.w(u'</a>') |
|
47 |
self.w(u'<p>%s%s</p>' % (self.req._('Used by:'), ', '.join(html_escape(u.name()) |
|
48 |
for u in entity.bookmarked_by))) |
|
49 |
self.w(u'</div>') |
|
50 |
||
51 |
||
52 |
class BookmarksBox(UserRQLBoxTemplate): |
|
53 |
"""display a box containing all user's bookmarks""" |
|
54 |
id = 'bookmarks_box' |
|
55 |
order = 40 |
|
56 |
title = _('bookmarks') |
|
57 |
rql = ('Any B,T,P ORDERBY lower(T) ' |
|
58 |
'WHERE B is Bookmark,B title T, B path P, B bookmarked_by U, ' |
|
59 |
'U eid %(x)s') |
|
60 |
etype = 'Bookmark' |
|
61 |
rtype = 'bookmarked_by' |
|
62 |
||
63 |
||
64 |
def call(self, **kwargs): |
|
65 |
req = self.req |
|
66 |
ueid = req.user.eid |
|
67 |
try: |
|
68 |
rset = req.execute(self.rql, {'x': ueid}) |
|
69 |
except Unauthorized: |
|
70 |
# can't access to something in the query, forget this box |
|
71 |
return |
|
72 |
box = BoxWidget(req._(self.title), self.id) |
|
73 |
box.listing_class = 'sideBox' |
|
74 |
rschema = self.schema.rschema(self.rtype) |
|
75 |
eschema = self.schema.eschema(self.etype) |
|
76 |
candelete = rschema.has_perm(req, 'delete', toeid=ueid) |
|
77 |
if candelete: |
|
78 |
req.add_js( ('cubicweb.ajax.js', 'cubicweb.bookmarks.js') ) |
|
79 |
else: |
|
80 |
dlink = None |
|
81 |
for bookmark in rset.entities(): |
|
82 |
label = '<a href="%s">%s</a>' % (html_escape(bookmark.action_url()), |
|
83 |
html_escape(bookmark.title)) |
|
84 |
if candelete: |
|
85 |
dlink = u'[<a href="javascript:removeBookmark(%s)" title="%s">-</a>]' % ( |
|
86 |
bookmark.eid, _('delete this bookmark')) |
|
87 |
label = '%s %s' % (dlink, label) |
|
852
105893288777
simplify css style
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
0
diff
changeset
|
88 |
box.append(RawBoxItem(label)) |
0 | 89 |
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
|
90 |
boxmenu = BoxMenu(req._('manage bookmarks')) |
0 | 91 |
linkto = 'bookmarked_by:%s:subject' % ueid |
92 |
# use a relative path so that we can move the application without |
|
93 |
# loosing bookmarks |
|
94 |
path = req.relative_path() |
|
95 |
url = self.create_url(self.etype, __linkto=linkto, path=path) |
|
96 |
boxmenu.append(self.mk_action(req._('bookmark this page'), url, |
|
97 |
category='manage', id='bookmark')) |
|
98 |
if rset: |
|
99 |
if req.user.is_in_group('managers'): |
|
100 |
bookmarksrql = 'Bookmark B WHERE B bookmarked_by U, U eid %s' % ueid |
|
101 |
erset = rset |
|
102 |
else: |
|
103 |
# we can't edit shared bookmarks we don't own |
|
104 |
bookmarksrql = 'Bookmark B WHERE B bookmarked_by U, B owned_by U, U eid %(x)s' |
|
105 |
erset = req.execute(bookmarksrql, {'x': ueid}, 'x', |
|
106 |
build_descr=False) |
|
107 |
bookmarksrql %= {'x': ueid} |
|
108 |
if erset: |
|
109 |
url = self.build_url(vid='muledit', rql=bookmarksrql) |
|
110 |
boxmenu.append(self.mk_action(self.req._('edit bookmarks'), url, category='manage')) |
|
111 |
url = req.user.absolute_url(vid='xaddrelation', rtype='bookmarked_by', |
|
112 |
target='subject') |
|
113 |
boxmenu.append(self.mk_action(self.req._('pick existing bookmarks'), url, category='manage')) |
|
114 |
box.append(boxmenu) |
|
115 |
if not box.is_empty(): |
|
116 |
box.render(self.w) |