openerp-community-reviewer team mailing list archive
-
openerp-community-reviewer team
-
Mailing list archive
-
Message #08083
[Merge] lp:~therp-nl/ocb-web/6.1-content_type_bwrsandman into lp:ocb-web/6.1
Stefan Rijnhart (Therp) has proposed merging lp:~therp-nl/ocb-web/6.1-content_type_bwrsandman into lp:ocb-web/6.1.
Requested reviews:
OpenERP Community Backports (ocb)
For more details, see:
https://code.launchpad.net/~therp-nl/ocb-web/6.1-content_type_bwrsandman/+merge/248786
Add the corresponding content type of downloaded documents.
The content type is available for documents that have been uploaded after
the document module was installed.
Backport of https://github.com/odoo/odoo/pull/4294/files by Sandy Carter. This fix is merged in master.
--
Your team OpenERP Community Backports is requested to review the proposed merge of lp:~therp-nl/ocb-web/6.1-content_type_bwrsandman into lp:ocb-web/6.1.
=== modified file 'addons/web/controllers/main.py'
--- addons/web/controllers/main.py 2014-07-11 16:21:56 +0000
+++ addons/web/controllers/main.py 2015-02-05 16:12:54 +0000
@@ -1427,10 +1427,14 @@
Model = req.session.model(model)
context = req.session.eval_context(req.context)
fields = [field]
+ content_type = 'application/octet-stream'
if filename_field:
fields.append(filename_field)
if id:
+ fields.append('file_type')
res = Model.read([int(id)], fields, context)[0]
+ if res.get('file_type'):
+ content_type = res['file_type']
else:
res = Model.default_get(fields, context)
filecontent = base64.b64decode(res.get(field, ''))
@@ -1441,7 +1445,7 @@
if filename_field:
filename = res.get(filename_field, '') or filename
return req.make_response(filecontent,
- [('Content-Type', 'application/octet-stream'),
+ [('Content-Type', content_type),
('Content-Disposition', self.content_disposition(filename, req))])
@openerpweb.httprequest
@@ -1452,6 +1456,7 @@
id = jdata.get('id', None)
filename_field = jdata.get('filename_field', None)
context = jdata.get('context', dict())
+ content_type = 'application/octet-stream'
context = req.session.eval_context(context)
Model = req.session.model(model)
@@ -1459,7 +1464,10 @@
if filename_field:
fields.append(filename_field)
if id:
+ fields.append('file_type')
res = Model.read([int(id)], fields, context)[0]
+ if res.get('file_type'):
+ content_type = res['file_type']
else:
res = Model.default_get(fields, context)
filecontent = base64.b64decode(res.get(field, ''))
@@ -1471,7 +1479,7 @@
if filename_field:
filename = res.get(filename_field, '') or filename
return req.make_response(filecontent,
- headers=[('Content-Type', 'application/octet-stream'),
+ headers=[('Content-Type', content_type),
('Content-Disposition', self.content_disposition(filename, req))],
cookies={'fileToken': int(token)})
Follow ups