equal
deleted
inserted
replaced
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
18 """Views, forms, actions... for the CubicWeb web client""" |
18 """Views, forms, actions... for the CubicWeb web client""" |
19 |
19 |
20 |
20 |
21 |
21 |
22 import os |
|
23 import sys |
22 import sys |
24 import tempfile |
|
25 |
|
26 from six import add_metaclass |
|
27 |
23 |
28 from rql import nodes |
24 from rql import nodes |
29 from logilab.mtconverter import xml_escape |
25 from logilab.mtconverter import xml_escape |
30 from logilab.common.deprecation import class_deprecated |
|
31 |
26 |
32 |
27 |
33 def need_table_view(rset, schema): |
28 def need_table_view(rset, schema): |
34 """return True if we think that a table view is more appropriate than a |
29 """return True if we think that a table view is more appropriate than a |
35 list or primary view to display the given result set |
30 list or primary view to display the given result set |
124 if eschema.has_perm(req, 'add'): |
119 if eschema.has_perm(req, 'add'): |
125 url = vreg['etypes'].etype_class(etype).cw_create_url(req, **urlkwargs) |
120 url = vreg['etypes'].etype_class(etype).cw_create_url(req, **urlkwargs) |
126 return u'<a href="%s" class="%s">%s</a>' % ( |
121 return u'<a href="%s" class="%s">%s</a>' % ( |
127 xml_escape(url), csscls, req.__('New %s' % etype)) |
122 xml_escape(url), csscls, req.__('New %s' % etype)) |
128 return u'' |
123 return u'' |
129 |
|
130 |
|
131 |
|
132 @add_metaclass(class_deprecated) |
|
133 class TmpFileViewMixin(object): |
|
134 __deprecation_warning__ = '[3.18] %(cls)s is deprecated' |
|
135 binary = True |
|
136 content_type = 'application/octet-stream' |
|
137 cache_max_age = 60*60*2 # stay in http cache for 2 hours by default |
|
138 |
|
139 def call(self): |
|
140 self.cell_call() |
|
141 |
|
142 def cell_call(self, row=0, col=0): |
|
143 self.cw_row, self.cw_col = row, col # in case one needs it |
|
144 fd, tmpfile = tempfile.mkstemp('.png') |
|
145 os.close(fd) |
|
146 self._generate(tmpfile) |
|
147 self.w(open(tmpfile, 'rb').read()) |
|
148 os.unlink(tmpfile) |
|