web/views/idownloadable.py
author sylvain.thenault@logilab.fr
Thu, 30 Apr 2009 00:41:52 +0200
branchtls-sprint
changeset 1554 3a3263df6cdd
parent 1498 2c6eec0b46b9
child 1639 375c857aa0f5
permissions -rw-r--r--
new primary view using uicfg.rdisplay (major api cleanup)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     1
"""Specific views for entities implementing IDownloadable
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     2
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     3
:organization: Logilab
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: 431
diff changeset
     4
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     5
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     6
"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     7
__docformat__ = "restructuredtext en"
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     8
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     9
from logilab.mtconverter import BINARY_ENCODINGS, TransformError, html_escape
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    10
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
    11
from cubicweb.selectors import (one_line_rset, score_entity,
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
                                implements, match_context_prop)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    13
from cubicweb.interfaces import IDownloadable
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    14
from cubicweb.common.mttransforms import ENGINE
249
5ab64969df20 define an actual download box, keeping download_box function for bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 237
diff changeset
    15
from cubicweb.web.box import EntityBoxTemplate
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    16
from cubicweb.web.views import baseviews
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    17
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    18
_ = unicode
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    19
985
6a25c58a1c23 backport stable branch, take care a lot of conflicts occured, this may be the revision you're looking for...
sylvain.thenault@logilab.fr
parents: 742 957
diff changeset
    20
def is_image(entity):
6a25c58a1c23 backport stable branch, take care a lot of conflicts occured, this may be the revision you're looking for...
sylvain.thenault@logilab.fr
parents: 742 957
diff changeset
    21
    mt = entity.download_content_type()
6a25c58a1c23 backport stable branch, take care a lot of conflicts occured, this may be the revision you're looking for...
sylvain.thenault@logilab.fr
parents: 742 957
diff changeset
    22
    if not (mt and mt.startswith('image/')):
6a25c58a1c23 backport stable branch, take care a lot of conflicts occured, this may be the revision you're looking for...
sylvain.thenault@logilab.fr
parents: 742 957
diff changeset
    23
        return 0
6a25c58a1c23 backport stable branch, take care a lot of conflicts occured, this may be the revision you're looking for...
sylvain.thenault@logilab.fr
parents: 742 957
diff changeset
    24
    return 1
6a25c58a1c23 backport stable branch, take care a lot of conflicts occured, this may be the revision you're looking for...
sylvain.thenault@logilab.fr
parents: 742 957
diff changeset
    25
249
5ab64969df20 define an actual download box, keeping download_box function for bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 237
diff changeset
    26
def download_box(w, entity, title=None, label=None):
5ab64969df20 define an actual download box, keeping download_box function for bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 237
diff changeset
    27
    req = entity.req
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    28
    w(u'<div class="sideRelated">')
249
5ab64969df20 define an actual download box, keeping download_box function for bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 237
diff changeset
    29
    if title is None:
5ab64969df20 define an actual download box, keeping download_box function for bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 237
diff changeset
    30
        title = req._('download')
5ab64969df20 define an actual download box, keeping download_box function for bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 237
diff changeset
    31
    w(u'<div class="sideBoxTitle downloadBoxTitle"><span>%s</span></div>'
5ab64969df20 define an actual download box, keeping download_box function for bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 237
diff changeset
    32
      % html_escape(title))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    33
    w(u'<div class="sideBox downloadBox"><div class="sideBoxBody">')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    34
    w(u'<a href="%s"><img src="%s" alt="%s"/> %s</a>'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    35
      % (html_escape(entity.download_url()),
249
5ab64969df20 define an actual download box, keeping download_box function for bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 237
diff changeset
    36
         req.external_resource('DOWNLOAD_ICON'),
5ab64969df20 define an actual download box, keeping download_box function for bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 237
diff changeset
    37
         _('download icon'), html_escape(label or entity.dc_title())))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    38
    w(u'</div>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    39
    w(u'</div>\n</div>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    40
985
6a25c58a1c23 backport stable branch, take care a lot of conflicts occured, this may be the revision you're looking for...
sylvain.thenault@logilab.fr
parents: 742 957
diff changeset
    41
249
5ab64969df20 define an actual download box, keeping download_box function for bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 237
diff changeset
    42
class DownloadBox(EntityBoxTemplate):
5ab64969df20 define an actual download box, keeping download_box function for bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 237
diff changeset
    43
    id = 'download_box'
985
6a25c58a1c23 backport stable branch, take care a lot of conflicts occured, this may be the revision you're looking for...
sylvain.thenault@logilab.fr
parents: 742 957
diff changeset
    44
    # no download box for images
957
b1f68f725fe9 don't show download box nor download link for images, by default hide name attribute even if not specified in the interface
sylvain.thenault@logilab.fr
parents: 431
diff changeset
    45
    # XXX primary_view selector ?
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 987
diff changeset
    46
    __select__ = (one_line_rset() & implements(IDownloadable) &
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 987
diff changeset
    47
                  match_context_prop() & ~score_entity(is_image))
249
5ab64969df20 define an actual download box, keeping download_box function for bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 237
diff changeset
    48
    order = 10
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 987
diff changeset
    49
249
5ab64969df20 define an actual download box, keeping download_box function for bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 237
diff changeset
    50
    def cell_call(self, row, col, title=None, label=None, **kwargs):
5ab64969df20 define an actual download box, keeping download_box function for bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 237
diff changeset
    51
        entity = self.entity(row, col)
5ab64969df20 define an actual download box, keeping download_box function for bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 237
diff changeset
    52
        download_box(self.w, entity, title, label)
5ab64969df20 define an actual download box, keeping download_box function for bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 237
diff changeset
    53
5ab64969df20 define an actual download box, keeping download_box function for bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 237
diff changeset
    54
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    55
class DownloadView(baseviews.EntityView):
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: 431
diff changeset
    56
    """this view is replacing the deprecated 'download' controller and allow
99f5852f8604 major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents: 431
diff changeset
    57
    downloading of entities providing the necessary interface
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    58
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    59
    id = 'download'
742
99115e029dca replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 692
diff changeset
    60
    __select__ = one_line_rset() & implements(IDownloadable)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    61
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    62
    templatable = False
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    63
    content_type = 'application/octet-stream'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    64
    binary = True
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    65
    add_to_breadcrumbs = False
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    66
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    67
    def set_request_content_type(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    68
        """overriden to set the correct filetype and filename"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    69
        entity = self.complete_entity(0)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    70
        encoding = entity.download_encoding()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    71
        if encoding in BINARY_ENCODINGS:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    72
            contenttype = 'application/%s' % encoding
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    73
            encoding = None
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    74
        else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    75
            contenttype = entity.download_content_type()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    76
        self.req.set_content_type(contenttype or self.content_type,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    77
                                  filename=entity.download_file_name(),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    78
                                  encoding=encoding)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    79
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    80
    def call(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    81
        self.w(self.complete_entity(0).download_data())
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    82
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    83
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    84
class DownloadLinkView(baseviews.EntityView):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    85
    """view displaying a link to download the file"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    86
    id = 'downloadlink'
742
99115e029dca replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 692
diff changeset
    87
    __select__ = implements(IDownloadable)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    88
    title = None # should not be listed in possible views
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    89
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 987
diff changeset
    90
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    91
    def cell_call(self, row, col, title=None, **kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    92
        entity = self.entity(row, col)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    93
        url = html_escape(entity.download_url())
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    94
        self.w(u'<a href="%s">%s</a>' % (url, html_escape(title or entity.dc_title())))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    95
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    96
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    97
class IDownloadablePrimaryView(baseviews.PrimaryView):
742
99115e029dca replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 692
diff changeset
    98
    __select__ = implements(IDownloadable)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    99
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1498
diff changeset
   100
    def render_entity_attributes(self, entity):
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1498
diff changeset
   101
        super(IDownloadablePrimaryView, self).render_entity_attributes(entity)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   102
        self.w(u'<div class="content">')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   103
        contenttype = entity.download_content_type()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   104
        if contenttype.startswith('image/'):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   105
            self.wview('image', entity.rset, row=entity.row)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   106
        else:
957
b1f68f725fe9 don't show download box nor download link for images, by default hide name attribute even if not specified in the interface
sylvain.thenault@logilab.fr
parents: 431
diff changeset
   107
            self.wview('downloadlink', entity.rset, title=self.req._('download'), row=entity.row)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   108
            try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   109
                if ENGINE.has_input(contenttype):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   110
                    self.w(entity.printable_value('data'))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   111
            except TransformError:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   112
                pass
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   113
            except Exception, ex:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   114
                msg = self.req._("can't display data, unexpected error: %s") % ex
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   115
                self.w('<div class="error">%s</div>' % msg)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   116
        self.w(u'</div>')
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 987
diff changeset
   117
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   118
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   119
class IDownloadableLineView(baseviews.OneLineView):
742
99115e029dca replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 692
diff changeset
   120
    __select__ = implements(IDownloadable)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   121
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   122
    def cell_call(self, row, col, title=None, **kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   123
        """the secondary view is a link to download the file"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   124
        entity = self.entity(row, col)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   125
        url = html_escape(entity.absolute_url())
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   126
        name = html_escape(entity.download_file_name())
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   127
        durl = html_escape(entity.download_url())
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   128
        self.w(u'<a href="%s">%s</a> [<a href="%s">%s</a>]' %
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   129
               (url, name, durl, self.req._('download')))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   130
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   131
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   132
class ImageView(baseviews.EntityView):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   133
    id = 'image'
742
99115e029dca replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 692
diff changeset
   134
    __select__ = implements(IDownloadable) & score_entity(is_image)
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 987
diff changeset
   135
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   136
    title = _('image')
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 987
diff changeset
   137
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   138
    def call(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   139
        rset = self.rset
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   140
        for i in xrange(len(rset)):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   141
            self.w(u'<div class="efile">')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   142
            self.wview(self.id, rset, row=i, col=0)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   143
            self.w(u'</div>')
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 987
diff changeset
   144
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   145
    def cell_call(self, row, col):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   146
        entity = self.entity(row, col)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   147
        #if entity.data_format.startswith('image/'):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   148
        self.w(u'<img src="%s" alt="%s"/>' % (html_escape(entity.download_url()),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   149
                                              html_escape(entity.download_file_name())))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   150