33 w(u'</div>\n</div>\n') |
33 w(u'</div>\n</div>\n') |
34 |
34 |
35 |
35 |
36 class DownloadBox(EntityBoxTemplate): |
36 class DownloadBox(EntityBoxTemplate): |
37 id = 'download_box' |
37 id = 'download_box' |
38 __selectors__ = (one_line_rset, implement_interface, match_context_prop) |
38 # XXX primary_view selector ? |
|
39 __selectors__ = (one_line_rset, implement_interface, match_context_prop, score_entity_selector) |
39 accepts_interfaces = (IDownloadable,) |
40 accepts_interfaces = (IDownloadable,) |
40 order = 10 |
41 order = 10 |
|
42 |
|
43 @classmethod |
|
44 def score_entity(cls, entity): |
|
45 mt = entity.download_content_type() |
|
46 # no download box for images |
|
47 if mt and mt.startswith('image/'): |
|
48 return 0 |
|
49 return 1 |
|
50 |
41 def cell_call(self, row, col, title=None, label=None, **kwargs): |
51 def cell_call(self, row, col, title=None, label=None, **kwargs): |
42 entity = self.entity(row, col) |
52 entity = self.entity(row, col) |
43 download_box(self.w, entity, title, label) |
53 download_box(self.w, entity, title, label) |
44 |
54 |
45 |
55 |
88 |
98 |
89 |
99 |
90 |
100 |
91 class IDownloadablePrimaryView(baseviews.PrimaryView): |
101 class IDownloadablePrimaryView(baseviews.PrimaryView): |
92 __selectors__ = (implement_interface,) |
102 __selectors__ = (implement_interface,) |
93 #skip_attrs = ('eid', 'data',) # XXX |
|
94 accepts_interfaces = (IDownloadable,) |
103 accepts_interfaces = (IDownloadable,) |
|
104 # XXX File/Image attributes but this is not specified in the IDownloadable interface |
|
105 skip_attrs = baseviews.PrimaryView.skip_attrs + ('data', 'name') |
95 |
106 |
96 def render_entity_title(self, entity): |
107 def render_entity_title(self, entity): |
97 self.w(u'<h1>%s %s</h1>' |
108 self.w(u'<h1>%s %s</h1>' |
98 % (entity.dc_type().capitalize(), |
109 % (entity.dc_type().capitalize(), |
99 html_escape(entity.dc_title()))) |
110 html_escape(entity.dc_title()))) |
100 |
111 |
101 def render_entity_attributes(self, entity, siderelations): |
112 def render_entity_attributes(self, entity, siderelations): |
102 super(IDownloadablePrimaryView, self).render_entity_attributes(entity, siderelations) |
113 super(IDownloadablePrimaryView, self).render_entity_attributes(entity, siderelations) |
103 self.wview('downloadlink', entity.rset, title=self.req._('download'), row=entity.row) |
|
104 self.w(u'<div class="content">') |
114 self.w(u'<div class="content">') |
105 contenttype = entity.download_content_type() |
115 contenttype = entity.download_content_type() |
106 if contenttype.startswith('image/'): |
116 if contenttype.startswith('image/'): |
107 self.wview('image', entity.rset, row=entity.row) |
117 self.wview('image', entity.rset, row=entity.row) |
108 else: |
118 else: |
|
119 self.wview('downloadlink', entity.rset, title=self.req._('download'), row=entity.row) |
109 try: |
120 try: |
110 if ENGINE.has_input(contenttype): |
121 if ENGINE.has_input(contenttype): |
111 self.w(entity.printable_value('data')) |
122 self.w(entity.printable_value('data')) |
112 except TransformError: |
123 except TransformError: |
113 pass |
124 pass |