web/views/bookmark.py
author Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
Mon, 27 Feb 2012 17:02:31 +0100
changeset 8298 2a4bc6f75e9c
parent 8190 2a3c1b787688
child 8665 e65af61bde7d
permissions -rw-r--r--
[twisted] move out url logic from twisted (closes #2200593) Data, fck and static file are now served by cubicweb controller by default. Some hackish url rewriting is necessary to have them selected. This is necessary because cubicweb does not selection controller on multi level path. - 'Expires' header seems to conflict with Cache-Control set by HTTPCacheManger (don't know yet why HTTPCacheManager is involved here) mod_wsgi is now usable in simple cases (e.g. still requires persisten sessions).
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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/>.
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6039
diff changeset
    18
"""Primary view for bookmarks + user's bookmarks box"""
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    19
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    20
__docformat__ = "restructuredtext en"
6582
8eb7883b4223 [pylint] fix a bug of pylint detected errors and i18n pb (calling builtins._ instead of req._)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6548
diff changeset
    21
_ = unicode
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    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
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    24
8128
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6800
diff changeset
    25
from cubicweb import Unauthorized, typed_eid
8190
2a3c1b787688 [vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8128
diff changeset
    26
from cubicweb.predicates import is_instance, one_line_rset
6684
b8bd0ecced2e minor cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
    27
from cubicweb.web import (action, component, uicfg, htmlwidgets,
b8bd0ecced2e minor cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
    28
                          formwidgets as fw)
1639
375c857aa0f5 import from primary
sylvain.thenault@logilab.fr
parents: 1533
diff changeset
    29
from cubicweb.web.views import primary
8128
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6800
diff changeset
    30
from cubicweb.web.views.ajaxcontroller import ajaxfunc
1151
b20677336ee6 turn old __rtags__ the new way
sylvain.thenault@logilab.fr
parents: 939
diff changeset
    31
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
    32
_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
    33
_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
    34
_abaa.tag_object_of(('*', 'bookmarked_by', '*'), False)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    35
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
    36
_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
    37
_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
    38
_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
    39
_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
    40
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
    41
_affk = uicfg.autoform_field_kwargs
4311
e9e93967b7b5 oopb, widget has been renamed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4309
diff changeset
    42
_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
    43
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
    44
1321
c5655237f08a we have now actual classes in rwidgets
sylvain.thenault@logilab.fr
parents: 1153
diff changeset
    45
class FollowAction(action.Action):
3408
c92170fca813 [api] use __regid__ instead of deprecated id
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3247
diff changeset
    46
    __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
    47
    __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
    48
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
    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
    50
    category = 'mainactions'
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1321
diff changeset
    51
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
    52
    def url(self):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3408
diff changeset
    53
        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
    54
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
    55
1639
375c857aa0f5 import from primary
sylvain.thenault@logilab.fr
parents: 1533
diff changeset
    56
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
    57
    __select__ = is_instance('Bookmark')
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1321
diff changeset
    58
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    59
    def cell_call(self, row, col):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    60
        """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
    61
        entity = self.cw_rset.complete_entity(row, col)
2996
866a2c135c33 B #345282 xhtml requires to use &#160; instead of &nbsp;
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2476
diff changeset
    62
        self.w(u'&#160;')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    63
        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
    64
        self.w(u"%s : %s" % (self._cw._('Bookmark'), xml_escape(entity.title)))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    65
        self.w(u"</b></span>")
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    66
        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
    67
            xml_escape(entity.actual_url())))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    68
        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
    69
        self.w(u'<p>%s%s</p>' % (self._cw._('Used by:'), ', '.join(xml_escape(u.name())
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    70
                                                                   for u in entity.bookmarked_by)))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    71
        self.w(u'</div>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    72
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    73
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
    74
class BookmarksBox(component.CtxComponent):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    75
    """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
    76
    __regid__ = 'bookmarks_box'
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6039
diff changeset
    77
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6039
diff changeset
    78
    title = _('bookmarks')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    79
    order = 40
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    80
    rql = ('Any B,T,P ORDERBY lower(T) '
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    81
           'WHERE B is Bookmark,B title T, B path P, B bookmarked_by U, '
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    82
           'U eid %(x)s')
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1321
diff changeset
    83
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6039
diff changeset
    84
    def init_rendering(self):
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6039
diff changeset
    85
        ueid = self._cw.user.eid
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6039
diff changeset
    86
        self.bookmarks_rset = self._cw.execute(self.rql, {'x': ueid})
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6039
diff changeset
    87
        rschema = self._cw.vreg.schema.rschema('bookmarked_by')
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6039
diff changeset
    88
        eschema = self._cw.vreg.schema.eschema('Bookmark')
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6039
diff changeset
    89
        self.can_delete = rschema.has_perm(self._cw, 'delete', toeid=ueid)
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6039
diff changeset
    90
        self.can_edit = (eschema.has_perm(self._cw, 'add') and
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6039
diff changeset
    91
                         rschema.has_perm(self._cw, 'add', toeid=ueid))
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6039
diff changeset
    92
        if not self.bookmarks_rset and not self.can_edit:
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
    93
            raise component.EmptyComponent()
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6039
diff changeset
    94
        self.items = []
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1321
diff changeset
    95
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6039
diff changeset
    96
    def render_body(self, w):
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6039
diff changeset
    97
        ueid = self._cw.user.eid
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3408
diff changeset
    98
        req = self._cw
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6039
diff changeset
    99
        if self.can_delete:
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5426
diff changeset
   100
            req.add_js('cubicweb.ajax.js')
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6039
diff changeset
   101
        for bookmark in self.bookmarks_rset.entities():
6800
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6684
diff changeset
   102
            label = self.link(bookmark.title, bookmark.action_url())
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6039
diff changeset
   103
            if self.can_delete:
6548
fd36c1049eed [css] cleanup and fix by removing display: block on <a> in boxes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6141
diff changeset
   104
                dlink = u'[<a class="action" href="javascript:removeBookmark(%s)" title="%s">-</a>]' % (
6582
8eb7883b4223 [pylint] fix a bug of pylint detected errors and i18n pb (calling builtins._ instead of req._)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6548
diff changeset
   105
                    bookmark.eid, req._('delete this bookmark'))
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6039
diff changeset
   106
                label = '<div>%s %s</div>' % (dlink, label)
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6039
diff changeset
   107
            self.append(label)
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6039
diff changeset
   108
        if self.can_edit:
6684
b8bd0ecced2e minor cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
   109
            menu = htmlwidgets.BoxMenu(req._('manage bookmarks'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   110
            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
   111
            # use a relative path so that we can move the instance without
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   112
            # loosing bookmarks
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   113
            path = req.relative_path()
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6039
diff changeset
   114
            # XXX if vtitle specified in params, extract it and use it as
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6039
diff changeset
   115
            # default value for bookmark's title
6039
6e84db1b3e44 [view] deprecate create_url in favor of a cw_create_url class method on entity classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5877
diff changeset
   116
            url = req.vreg['etypes'].etype_class('Bookmark').cw_create_url(
6e84db1b3e44 [view] deprecate create_url in favor of a cw_create_url class method on entity classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5877
diff changeset
   117
                req, __linkto=linkto, path=path)
6800
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6684
diff changeset
   118
            menu.append(self.link(req._('bookmark this page'), url))
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6039
diff changeset
   119
            if self.bookmarks_rset:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   120
                if req.user.is_in_group('managers'):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   121
                    bookmarksrql = 'Bookmark B WHERE B bookmarked_by U, U eid %s' % ueid
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6039
diff changeset
   122
                    erset = self.bookmarks_rset
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   123
                else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   124
                    # we can't edit shared bookmarks we don't own
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   125
                    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
   126
                    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
   127
                                        build_descr=False)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   128
                    bookmarksrql %= {'x': ueid}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   129
                if erset:
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6039
diff changeset
   130
                    url = req.build_url(vid='muledit', rql=bookmarksrql)
6800
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6684
diff changeset
   131
                    menu.append(self.link(req._('edit bookmarks'), url))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   132
            url = req.user.absolute_url(vid='xaddrelation', rtype='bookmarked_by',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   133
                                        target='subject')
6800
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6684
diff changeset
   134
            menu.append(self.link(req._('pick existing bookmarks'), url))
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6039
diff changeset
   135
            self.append(menu)
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6039
diff changeset
   136
        self.render_items(w)
8128
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6800
diff changeset
   137
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6800
diff changeset
   138
@ajaxfunc
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6800
diff changeset
   139
def delete_bookmark(self, beid):
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6800
diff changeset
   140
    rql = 'DELETE B bookmarked_by U WHERE B eid %(b)s, U eid %(u)s'
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6800
diff changeset
   141
    self._cw.execute(rql, {'b': typed_eid(beid), 'u' : self._cw.user.eid})