web/views/bookmark.py
branchtls-sprint
changeset 1498 2c6eec0b46b9
parent 1321 c5655237f08a
child 1533 bcd4bfff658b
equal deleted inserted replaced
1493:8270580b65a0 1498:2c6eec0b46b9
     9 from logilab.mtconverter import html_escape
     9 from logilab.mtconverter import html_escape
    10 
    10 
    11 from cubicweb import Unauthorized
    11 from cubicweb import Unauthorized
    12 from cubicweb.selectors import implements
    12 from cubicweb.selectors import implements
    13 from cubicweb.web.htmlwidgets import BoxWidget, BoxMenu, RawBoxItem
    13 from cubicweb.web.htmlwidgets import BoxWidget, BoxMenu, RawBoxItem
    14 from cubicweb.web import action, formwidgets
    14 from cubicweb.web import uicfg, action, box, formwidgets
    15 from cubicweb.web.box import UserRQLBoxTemplate
       
    16 from cubicweb.web.views.baseviews import PrimaryView
    15 from cubicweb.web.views.baseviews import PrimaryView
    17 from cubicweb.web.views.editforms import AutomaticEntityForm
       
    18 
    16 
    19 AutomaticEntityForm.rcategories.set_rtag('primary', 'path', 'subject', 'Bookmark')
    17 uicfg.rcategories.set_rtag('primary', 'path', 'subject', 'Bookmark')
    20 AutomaticEntityForm.rwidgets.set_rtag(formwidgets.TextInput, 'path', 'subject', 'Bookmark')
    18 uicfg.rwidgets.set_rtag(formwidgets.TextInput, 'path', 'subject', 'Bookmark')
    21 
    19 
    22 
    20 
    23 class FollowAction(action.Action):
    21 class FollowAction(action.Action):
    24     id = 'follow'
    22     id = 'follow'
    25     __select__ = implements('Bookmark')
    23     __select__ = implements('Bookmark')
    26 
    24 
    27     title = _('follow')
    25     title = _('follow')
    28     category = 'mainactions'
    26     category = 'mainactions'
    29     
    27 
    30     def url(self):
    28     def url(self):
    31         return self.rset.get_entity(self.row or 0, self.col or 0).actual_url()
    29         return self.rset.get_entity(self.row or 0, self.col or 0).actual_url()
    32 
    30 
    33 
    31 
    34 class BookmarkPrimaryView(PrimaryView):
    32 class BookmarkPrimaryView(PrimaryView):
    35     __select__ = implements('Bookmark')
    33     __select__ = implements('Bookmark')
    36         
    34 
    37     def cell_call(self, row, col):
    35     def cell_call(self, row, col):
    38         """the primary view for bookmark entity"""
    36         """the primary view for bookmark entity"""
    39         entity = self.complete_entity(row, col)
    37         entity = self.complete_entity(row, col)
    40         self.w(u' ')
    38         self.w(u' ')
    41         self.w(u"<span class='title'><b>")
    39         self.w(u"<span class='title'><b>")
    47         self.w(u'<p>%s%s</p>' % (self.req._('Used by:'), ', '.join(html_escape(u.name())
    45         self.w(u'<p>%s%s</p>' % (self.req._('Used by:'), ', '.join(html_escape(u.name())
    48                                                                    for u in entity.bookmarked_by)))
    46                                                                    for u in entity.bookmarked_by)))
    49         self.w(u'</div>')
    47         self.w(u'</div>')
    50 
    48 
    51 
    49 
    52 class BookmarksBox(UserRQLBoxTemplate):
    50 class BookmarksBox(box.UserRQLBoxTemplate):
    53     """display a box containing all user's bookmarks"""
    51     """display a box containing all user's bookmarks"""
    54     id = 'bookmarks_box'
    52     id = 'bookmarks_box'
    55     order = 40
    53     order = 40
    56     title = _('bookmarks')
    54     title = _('bookmarks')
    57     rql = ('Any B,T,P ORDERBY lower(T) '
    55     rql = ('Any B,T,P ORDERBY lower(T) '
    58            'WHERE B is Bookmark,B title T, B path P, B bookmarked_by U, '
    56            'WHERE B is Bookmark,B title T, B path P, B bookmarked_by U, '
    59            'U eid %(x)s')
    57            'U eid %(x)s')
    60     etype = 'Bookmark'
    58     etype = 'Bookmark'
    61     rtype = 'bookmarked_by'
    59     rtype = 'bookmarked_by'
    62     
    60 
    63     
    61 
    64     def call(self, **kwargs):
    62     def call(self, **kwargs):
    65         req = self.req
    63         req = self.req
    66         ueid = req.user.eid
    64         ueid = req.user.eid
    67         try:
    65         try:
    68             rset = req.execute(self.rql, {'x': ueid})
    66             rset = req.execute(self.rql, {'x': ueid})