equal
deleted
inserted
replaced
6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
7 """ |
7 """ |
8 __docformat__ = "restructuredtext en" |
8 __docformat__ = "restructuredtext en" |
9 _ = unicode |
9 _ = unicode |
10 |
10 |
11 from logilab.mtconverter import BINARY_ENCODINGS, TransformError, html_escape |
11 from logilab.mtconverter import BINARY_ENCODINGS, TransformError, xml_escape |
12 |
12 |
13 from cubicweb.view import EntityView |
13 from cubicweb.view import EntityView |
14 from cubicweb.selectors import (one_line_rset, score_entity, |
14 from cubicweb.selectors import (one_line_rset, score_entity, |
15 implements, match_context_prop) |
15 implements, match_context_prop) |
16 from cubicweb.interfaces import IDownloadable |
16 from cubicweb.interfaces import IDownloadable |
29 req = entity.req |
29 req = entity.req |
30 w(u'<div class="sideBox">') |
30 w(u'<div class="sideBox">') |
31 if title is None: |
31 if title is None: |
32 title = req._('download') |
32 title = req._('download') |
33 w(u'<div class="sideBoxTitle downloadBoxTitle"><span>%s</span></div>' |
33 w(u'<div class="sideBoxTitle downloadBoxTitle"><span>%s</span></div>' |
34 % html_escape(title)) |
34 % xml_escape(title)) |
35 w(u'<div class="sideBox downloadBox"><div class="sideBoxBody">') |
35 w(u'<div class="sideBox downloadBox"><div class="sideBoxBody">') |
36 w(u'<a href="%s"><img src="%s" alt="%s"/> %s</a>' |
36 w(u'<a href="%s"><img src="%s" alt="%s"/> %s</a>' |
37 % (html_escape(entity.download_url()), |
37 % (xml_escape(entity.download_url()), |
38 req.external_resource('DOWNLOAD_ICON'), |
38 req.external_resource('DOWNLOAD_ICON'), |
39 _('download icon'), html_escape(label or entity.dc_title()))) |
39 _('download icon'), xml_escape(label or entity.dc_title()))) |
40 w(u'</div>') |
40 w(u'</div>') |
41 w(u'</div>\n</div>\n') |
41 w(u'</div>\n</div>\n') |
42 |
42 |
43 |
43 |
44 class DownloadBox(EntityBoxTemplate): |
44 class DownloadBox(EntityBoxTemplate): |
90 title = None # should not be listed in possible views |
90 title = None # should not be listed in possible views |
91 |
91 |
92 |
92 |
93 def cell_call(self, row, col, title=None, **kwargs): |
93 def cell_call(self, row, col, title=None, **kwargs): |
94 entity = self.entity(row, col) |
94 entity = self.entity(row, col) |
95 url = html_escape(entity.download_url()) |
95 url = xml_escape(entity.download_url()) |
96 self.w(u'<a href="%s">%s</a>' % (url, html_escape(title or entity.dc_title()))) |
96 self.w(u'<a href="%s">%s</a>' % (url, xml_escape(title or entity.dc_title()))) |
97 |
97 |
98 |
98 |
99 class IDownloadablePrimaryView(primary.PrimaryView): |
99 class IDownloadablePrimaryView(primary.PrimaryView): |
100 __select__ = implements(IDownloadable) |
100 __select__ = implements(IDownloadable) |
101 |
101 |
122 __select__ = implements(IDownloadable) |
122 __select__ = implements(IDownloadable) |
123 |
123 |
124 def cell_call(self, row, col, title=None, **kwargs): |
124 def cell_call(self, row, col, title=None, **kwargs): |
125 """the secondary view is a link to download the file""" |
125 """the secondary view is a link to download the file""" |
126 entity = self.entity(row, col) |
126 entity = self.entity(row, col) |
127 url = html_escape(entity.absolute_url()) |
127 url = xml_escape(entity.absolute_url()) |
128 name = html_escape(title or entity.download_file_name()) |
128 name = xml_escape(title or entity.download_file_name()) |
129 durl = html_escape(entity.download_url()) |
129 durl = xml_escape(entity.download_url()) |
130 self.w(u'<a href="%s">%s</a> [<a href="%s">%s</a>]' % |
130 self.w(u'<a href="%s">%s</a> [<a href="%s">%s</a>]' % |
131 (url, name, durl, self.req._('download'))) |
131 (url, name, durl, self.req._('download'))) |
132 |
132 |
133 |
133 |
134 class ImageView(EntityView): |
134 class ImageView(EntityView): |
145 self.w(u'</div>') |
145 self.w(u'</div>') |
146 |
146 |
147 def cell_call(self, row, col): |
147 def cell_call(self, row, col): |
148 entity = self.entity(row, col) |
148 entity = self.entity(row, col) |
149 #if entity.data_format.startswith('image/'): |
149 #if entity.data_format.startswith('image/'): |
150 self.w(u'<img src="%s" alt="%s"/>' % (html_escape(entity.download_url()), |
150 self.w(u'<img src="%s" alt="%s"/>' % (xml_escape(entity.download_url()), |
151 html_escape(entity.download_file_name()))) |
151 xml_escape(entity.download_file_name()))) |
152 |
152 |