web/views/idownloadable.py
changeset 249 5ab64969df20
parent 237 3df2e0ae2eba
child 326 44b6345ccd3c
equal deleted inserted replaced
248:ee6934a50d53 249:5ab64969df20
     9 from logilab.mtconverter import BINARY_ENCODINGS, TransformError, html_escape
     9 from logilab.mtconverter import BINARY_ENCODINGS, TransformError, html_escape
    10 
    10 
    11 from cubicweb.interfaces import IDownloadable
    11 from cubicweb.interfaces import IDownloadable
    12 from cubicweb.common.mttransforms import ENGINE
    12 from cubicweb.common.mttransforms import ENGINE
    13 from cubicweb.common.selectors import (one_line_rset, score_entity_selector,
    13 from cubicweb.common.selectors import (one_line_rset, score_entity_selector,
    14                                     interface_selector)
    14                                        interface_selector)
       
    15 from cubicweb.web.box import EntityBoxTemplate
    15 from cubicweb.web.views import baseviews
    16 from cubicweb.web.views import baseviews
    16 
    17 
    17 _ = unicode
    18 _ = unicode
    18 
    19 
    19 
    20 def download_box(w, entity, title=None, label=None):
    20 def download_box(w, entity):
    21     req = entity.req
    21     w(u'<div class="sideRelated">')
    22     w(u'<div class="sideRelated">')
    22     w(u'<div class="sideBoxTitle downloadBoxTitle"><span>%s</span></div>' % _('download'))
    23     if title is None:
       
    24         title = req._('download')
       
    25     w(u'<div class="sideBoxTitle downloadBoxTitle"><span>%s</span></div>'
       
    26       % html_escape(title))
    23     w(u'<div class="sideBox downloadBox"><div class="sideBoxBody">')
    27     w(u'<div class="sideBox downloadBox"><div class="sideBoxBody">')
    24     w(u'<a href="%s"><img src="%s" alt="%s"/> %s</a>'
    28     w(u'<a href="%s"><img src="%s" alt="%s"/> %s</a>'
    25       % (html_escape(entity.download_url()),
    29       % (html_escape(entity.download_url()),
    26          entity.req.external_resource('DOWNLOAD_ICON'),
    30          req.external_resource('DOWNLOAD_ICON'),
    27          _('download icon'), html_escape(entity.dc_title())))
    31          _('download icon'), html_escape(label or entity.dc_title())))
    28     w(u'</div>')
    32     w(u'</div>')
    29     w(u'</div>\n</div>\n')
    33     w(u'</div>\n</div>\n')
       
    34 
       
    35     
       
    36 class DownloadBox(EntityBoxTemplate):
       
    37     id = 'download_box'
       
    38     __selectors__ = (one_line_rset, interface_selector)
       
    39     accepts_interfaces = (IDownloadable,)
       
    40     order = 10
       
    41     def cell_call(self, row, col, title=None, label=None, **kwargs):
       
    42         entity = self.entity(row, col)
       
    43         download_box(self.w, entity, title, label)
       
    44 
    30 
    45 
    31 class DownloadView(baseviews.EntityView):
    46 class DownloadView(baseviews.EntityView):
    32     """this view is replacing the deprecated 'download' controller and allow downloading
    47     """this view is replacing the deprecated 'download' controller and allow downloading
    33     of entities providing the necessary interface
    48     of entities providing the necessary interface
    34     """
    49     """