equal
deleted
inserted
replaced
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, contextprop_selector) |
14 implement_interface, match_context_prop) |
15 from cubicweb.web.box import EntityBoxTemplate |
15 from cubicweb.web.box import EntityBoxTemplate |
16 from cubicweb.web.views import baseviews |
16 from cubicweb.web.views import baseviews |
17 |
17 |
18 _ = unicode |
18 _ = unicode |
19 |
19 |
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, interface_selector, contextprop_selector) |
38 __selectors__ = (one_line_rset, implement_interface, match_context_prop) |
39 accepts_interfaces = (IDownloadable,) |
39 accepts_interfaces = (IDownloadable,) |
40 order = 10 |
40 order = 10 |
41 def cell_call(self, row, col, title=None, label=None, **kwargs): |
41 def cell_call(self, row, col, title=None, label=None, **kwargs): |
42 entity = self.entity(row, col) |
42 entity = self.entity(row, col) |
43 download_box(self.w, entity, title, label) |
43 download_box(self.w, entity, title, label) |
46 class DownloadView(baseviews.EntityView): |
46 class DownloadView(baseviews.EntityView): |
47 """this view is replacing the deprecated 'download' controller and allow downloading |
47 """this view is replacing the deprecated 'download' controller and allow downloading |
48 of entities providing the necessary interface |
48 of entities providing the necessary interface |
49 """ |
49 """ |
50 id = 'download' |
50 id = 'download' |
51 __selectors__ = (one_line_rset, interface_selector) |
51 __selectors__ = (one_line_rset, implement_interface) |
52 accepts_interfaces = (IDownloadable,) |
52 accepts_interfaces = (IDownloadable,) |
53 |
53 |
54 templatable = False |
54 templatable = False |
55 content_type = 'application/octet-stream' |
55 content_type = 'application/octet-stream' |
56 binary = True |
56 binary = True |
75 |
75 |
76 class DownloadLinkView(baseviews.EntityView): |
76 class DownloadLinkView(baseviews.EntityView): |
77 """view displaying a link to download the file""" |
77 """view displaying a link to download the file""" |
78 id = 'downloadlink' |
78 id = 'downloadlink' |
79 title = None # should not be listed in possible views |
79 title = None # should not be listed in possible views |
80 __selectors__ = (interface_selector,) |
80 __selectors__ = (implement_interface,) |
81 |
81 |
82 accepts_interfaces = (IDownloadable,) |
82 accepts_interfaces = (IDownloadable,) |
83 |
83 |
84 def cell_call(self, row, col, title=None, **kwargs): |
84 def cell_call(self, row, col, title=None, **kwargs): |
85 entity = self.entity(row, col) |
85 entity = self.entity(row, col) |
87 self.w(u'<a href="%s">%s</a>' % (url, html_escape(title or entity.dc_title()))) |
87 self.w(u'<a href="%s">%s</a>' % (url, html_escape(title or entity.dc_title()))) |
88 |
88 |
89 |
89 |
90 |
90 |
91 class IDownloadablePrimaryView(baseviews.PrimaryView): |
91 class IDownloadablePrimaryView(baseviews.PrimaryView): |
92 __selectors__ = (interface_selector,) |
92 __selectors__ = (implement_interface,) |
93 #skip_attrs = ('eid', 'data',) # XXX |
93 #skip_attrs = ('eid', 'data',) # XXX |
94 accepts_interfaces = (IDownloadable,) |
94 accepts_interfaces = (IDownloadable,) |
95 |
95 |
96 def render_entity_title(self, entity): |
96 def render_entity_title(self, entity): |
97 self.w(u'<h1>%s %s</h1>' |
97 self.w(u'<h1>%s %s</h1>' |
120 """display all relations as side related""" |
120 """display all relations as side related""" |
121 return True |
121 return True |
122 |
122 |
123 |
123 |
124 class IDownloadableLineView(baseviews.OneLineView): |
124 class IDownloadableLineView(baseviews.OneLineView): |
125 __selectors__ = (interface_selector,) |
125 __selectors__ = (implement_interface,) |
126 # don't kick default oneline view |
126 # don't kick default oneline view |
127 accepts_interfaces = (IDownloadable,) |
127 accepts_interfaces = (IDownloadable,) |
128 |
128 |
129 |
129 |
130 def cell_call(self, row, col, title=None, **kwargs): |
130 def cell_call(self, row, col, title=None, **kwargs): |
136 self.w(u'<a href="%s">%s</a> [<a href="%s">%s</a>]' % |
136 self.w(u'<a href="%s">%s</a> [<a href="%s">%s</a>]' % |
137 (url, name, durl, self.req._('download'))) |
137 (url, name, durl, self.req._('download'))) |
138 |
138 |
139 |
139 |
140 class ImageView(baseviews.EntityView): |
140 class ImageView(baseviews.EntityView): |
141 __selectors__ = (interface_selector, score_entity_selector) |
141 __selectors__ = (implement_interface, score_entity_selector) |
142 id = 'image' |
142 id = 'image' |
143 title = _('image') |
143 title = _('image') |
144 accepts_interfaces = (IDownloadable,) |
144 accepts_interfaces = (IDownloadable,) |
145 |
145 |
146 def call(self): |
146 def call(self): |