[FIX] mail: fixed download_attachment controller

bzr revid: tde@openerp.com-20140124160457-hofozo85ebzbogu7
This commit is contained in:
Thibault Delavallée 2014-01-24 17:04:57 +01:00
parent 79fc8d3d20
commit 33d349f33b
1 changed files with 8 additions and 6 deletions

View File

@ -4,6 +4,7 @@ import psycopg2
import openerp
from openerp import SUPERUSER_ID
from openerp import http
from openerp.http import request
from openerp.addons.web.controllers.main import content_disposition
@ -11,18 +12,19 @@ class MailController(http.Controller):
_cp_path = '/mail'
@http.route('/mail/download_attachment', type='http', auth='user')
def download_attachment(self, req, model, id, method, attachment_id, **kw):
def download_attachment(self, model, id, method, attachment_id, **kw):
# FIXME use /web/binary/saveas directly
Model = req.session.model(model)
res = getattr(Model, method)(int(id), int(attachment_id))
Model = request.registry.get(model)
res = getattr(Model, method)(request.cr, request.uid, int(id), int(attachment_id))
if res:
filecontent = base64.b64decode(res.get('base64'))
filename = res.get('filename')
if filecontent and filename:
return req.make_response(filecontent,
return request.make_response(
filecontent,
headers=[('Content-Type', 'application/octet-stream'),
('Content-Disposition', content_disposition(filename))])
return req.not_found()
('Content-Disposition', content_disposition(filename))])
return request.not_found()
@http.route('/mail/receive', type='json', auth='none')
def receive(self, req):