41 |
41 |
42 class DownloadBox(EntityBoxTemplate): |
42 class DownloadBox(EntityBoxTemplate): |
43 id = 'download_box' |
43 id = 'download_box' |
44 # no download box for images |
44 # no download box for images |
45 # XXX primary_view selector ? |
45 # XXX primary_view selector ? |
46 __select__ = (one_line_rset() & implements(IDownloadable) & match_context_prop() & ~score_entity(is_image)) |
46 __select__ = (one_line_rset() & implements(IDownloadable) & |
|
47 match_context_prop() & ~score_entity(is_image)) |
47 order = 10 |
48 order = 10 |
48 |
49 |
49 def cell_call(self, row, col, title=None, label=None, **kwargs): |
50 def cell_call(self, row, col, title=None, label=None, **kwargs): |
50 entity = self.entity(row, col) |
51 entity = self.entity(row, col) |
51 download_box(self.w, entity, title, label) |
52 download_box(self.w, entity, title, label) |
52 |
53 |
53 |
54 |
84 """view displaying a link to download the file""" |
85 """view displaying a link to download the file""" |
85 id = 'downloadlink' |
86 id = 'downloadlink' |
86 __select__ = implements(IDownloadable) |
87 __select__ = implements(IDownloadable) |
87 title = None # should not be listed in possible views |
88 title = None # should not be listed in possible views |
88 |
89 |
89 |
90 |
90 def cell_call(self, row, col, title=None, **kwargs): |
91 def cell_call(self, row, col, title=None, **kwargs): |
91 entity = self.entity(row, col) |
92 entity = self.entity(row, col) |
92 url = html_escape(entity.download_url()) |
93 url = html_escape(entity.download_url()) |
93 self.w(u'<a href="%s">%s</a>' % (url, html_escape(title or entity.dc_title()))) |
94 self.w(u'<a href="%s">%s</a>' % (url, html_escape(title or entity.dc_title()))) |
94 |
95 |
95 |
96 |
96 |
97 |
97 class IDownloadablePrimaryView(baseviews.PrimaryView): |
98 class IDownloadablePrimaryView(baseviews.PrimaryView): |
98 __select__ = implements(IDownloadable) |
99 __select__ = implements(IDownloadable) |
99 # XXX File/Image attributes but this is not specified in the IDownloadable interface |
100 # XXX File/Image attributes but this is not specified in the IDownloadable interface |
100 skip_attrs = baseviews.PrimaryView.skip_attrs + ('data', 'name') |
101 skip_attrs = baseviews.PrimaryView.skip_attrs + ('data', 'name') |
101 |
102 |
102 def render_entity_title(self, entity): |
103 def render_entity_title(self, entity): |
103 self.w(u'<h1>%s %s</h1>' |
104 self.w(u'<h1>%s %s</h1>' |
104 % (entity.dc_type().capitalize(), |
105 % (entity.dc_type().capitalize(), |
105 html_escape(entity.dc_title()))) |
106 html_escape(entity.dc_title()))) |
106 |
107 |
107 def render_entity_attributes(self, entity, siderelations): |
108 def render_entity_attributes(self, entity, siderelations): |
108 super(IDownloadablePrimaryView, self).render_entity_attributes(entity, siderelations) |
109 super(IDownloadablePrimaryView, self).render_entity_attributes(entity, siderelations) |
109 self.w(u'<div class="content">') |
110 self.w(u'<div class="content">') |
110 contenttype = entity.download_content_type() |
111 contenttype = entity.download_content_type() |
111 if contenttype.startswith('image/'): |
112 if contenttype.startswith('image/'): |
119 pass |
120 pass |
120 except Exception, ex: |
121 except Exception, ex: |
121 msg = self.req._("can't display data, unexpected error: %s") % ex |
122 msg = self.req._("can't display data, unexpected error: %s") % ex |
122 self.w('<div class="error">%s</div>' % msg) |
123 self.w('<div class="error">%s</div>' % msg) |
123 self.w(u'</div>') |
124 self.w(u'</div>') |
124 |
125 |
125 def is_side_related(self, rschema, eschema): |
126 def is_side_related(self, rschema, eschema): |
126 """display all relations as side related""" |
127 """display all relations as side related""" |
127 return True |
128 return True |
128 |
129 |
129 |
130 |
141 |
142 |
142 |
143 |
143 class ImageView(baseviews.EntityView): |
144 class ImageView(baseviews.EntityView): |
144 id = 'image' |
145 id = 'image' |
145 __select__ = implements(IDownloadable) & score_entity(is_image) |
146 __select__ = implements(IDownloadable) & score_entity(is_image) |
146 |
147 |
147 title = _('image') |
148 title = _('image') |
148 |
149 |
149 def call(self): |
150 def call(self): |
150 rset = self.rset |
151 rset = self.rset |
151 for i in xrange(len(rset)): |
152 for i in xrange(len(rset)): |
152 self.w(u'<div class="efile">') |
153 self.w(u'<div class="efile">') |
153 self.wview(self.id, rset, row=i, col=0) |
154 self.wview(self.id, rset, row=i, col=0) |
154 self.w(u'</div>') |
155 self.w(u'</div>') |
155 |
156 |
156 def cell_call(self, row, col): |
157 def cell_call(self, row, col): |
157 entity = self.entity(row, col) |
158 entity = self.entity(row, col) |
158 #if entity.data_format.startswith('image/'): |
159 #if entity.data_format.startswith('image/'): |
159 self.w(u'<img src="%s" alt="%s"/>' % (html_escape(entity.download_url()), |
160 self.w(u'<img src="%s" alt="%s"/>' % (html_escape(entity.download_url()), |
160 html_escape(entity.download_file_name()))) |
161 html_escape(entity.download_file_name()))) |