web/htmlwidgets.py
branchstable
changeset 2312 af4d8f75c5db
parent 1977 606923dff11b
child 2757 c8e28e1754f0
equal deleted inserted replaced
2311:f178182b1305 2312:af4d8f75c5db
     7 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
     7 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
     8 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     8 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     9 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
     9 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
    10 """
    10 """
    11 
    11 
    12 from logilab.mtconverter import html_escape
    12 from logilab.mtconverter import xml_escape
    13 
    13 
    14 from cubicweb.utils import UStringIO
    14 from cubicweb.utils import UStringIO
    15 from cubicweb.common.uilib import toggle_action
    15 from cubicweb.common.uilib import toggle_action
    16 
    16 
    17 # XXX HTMLWidgets should have access to req (for datadir / static urls,
    17 # XXX HTMLWidgets should have access to req (for datadir / static urls,
    79             self.w(u'<div class="%s" id="%s">' % (self._class, self.id))
    79             self.w(u'<div class="%s" id="%s">' % (self._class, self.id))
    80         else:
    80         else:
    81             self.w(u'<div class="%s">' % self._class)
    81             self.w(u'<div class="%s">' % self._class)
    82         if self.title:
    82         if self.title:
    83             if self.escape:
    83             if self.escape:
    84                 title = '<span>%s</span>' % html_escape(self.title)
    84                 title = '<span>%s</span>' % xml_escape(self.title)
    85             else:
    85             else:
    86                 title = '<span>%s</span>' % self.title
    86                 title = '<span>%s</span>' % self.title
    87             self.w(u'<div class="%s">%s</div>' % (self.title_class, title))
    87             self.w(u'<div class="%s">%s</div>' % (self.title_class, title))
    88         if self.items:
    88         if self.items:
    89             self.box_begin_content()
    89             self.box_begin_content()
   202 class BoxLink(HTMLWidget):
   202 class BoxLink(HTMLWidget):
   203     """a link in a box"""
   203     """a link in a box"""
   204     def __init__(self, href, label, _class='', title='', ident='', escape=False):
   204     def __init__(self, href, label, _class='', title='', ident='', escape=False):
   205         self.href = href
   205         self.href = href
   206         if escape:
   206         if escape:
   207             self.label = html_escape(label)
   207             self.label = xml_escape(label)
   208         else:
   208         else:
   209             self.label = label
   209             self.label = label
   210         self._class = _class or ''
   210         self._class = _class or ''
   211         self.title = title
   211         self.title = title
   212         self.ident = ident
   212         self.ident = ident
   213 
   213 
   214     def _render(self):
   214     def _render(self):
   215         link = u'<a href="%s" title="%s">%s</a>' % (
   215         link = u'<a href="%s" title="%s">%s</a>' % (
   216             html_escape(self.href), html_escape(self.title), self.label)
   216             xml_escape(self.href), xml_escape(self.title), self.label)
   217         if self.ident:
   217         if self.ident:
   218             self.w(u'<li id="%s" class="%s">%s</li>\n' % (self.ident, self._class, link))
   218             self.w(u'<li id="%s" class="%s">%s</li>\n' % (self.ident, self._class, link))
   219         else:
   219         else:
   220             self.w(u'<li class="%s">%s</li>\n' % (self._class, link))
   220             self.w(u'<li class="%s">%s</li>\n' % (self._class, link))
   221 
   221