[FIX] report action management: correctly download reports
bzr revid: xmo@openerp.com-20110907072358-94qnrzx1ww951shv
This commit is contained in:
parent
1ffd3f324d
commit
0b17356d23
|
@ -23,8 +23,6 @@ openerpweb.nonliterals = web.common.nonliterals
|
||||||
|
|
||||||
from babel.messages.pofile import read_po
|
from babel.messages.pofile import read_po
|
||||||
|
|
||||||
_REPORT_POLLER_DELAY = 0.05
|
|
||||||
|
|
||||||
# Should move to openerpweb.Xml2Json
|
# Should move to openerpweb.Xml2Json
|
||||||
class Xml2Json:
|
class Xml2Json:
|
||||||
# xml2json-direct
|
# xml2json-direct
|
||||||
|
@ -1325,22 +1323,45 @@ class ExcelExport(Export):
|
||||||
|
|
||||||
class Reports(View):
|
class Reports(View):
|
||||||
_cp_path = "/web/report"
|
_cp_path = "/web/report"
|
||||||
|
POLLING_DELAY = 0.25
|
||||||
|
TYPES_MAPPING = {
|
||||||
|
'doc': 'application/vnd.ms-word',
|
||||||
|
'html': 'text/html',
|
||||||
|
'odt': 'application/vnd.oasis.opendocument.text',
|
||||||
|
'pdf': 'application/pdf',
|
||||||
|
'sxw': 'application/vnd.sun.xml.writer',
|
||||||
|
'xls': 'application/vnd.ms-excel',
|
||||||
|
}
|
||||||
|
|
||||||
|
@openerpweb.httprequest
|
||||||
|
def index(self, req, action, token):
|
||||||
|
action = simplejson.loads(action)
|
||||||
|
|
||||||
@openerpweb.jsonrequest
|
|
||||||
def get_report(self, req, action):
|
|
||||||
report_srv = req.session.proxy("report")
|
report_srv = req.session.proxy("report")
|
||||||
context = req.session.eval_context(openerpweb.nonliterals.CompoundContext(req.context, \
|
context = req.session.eval_context(
|
||||||
action["context"]))
|
openerpweb.nonliterals.CompoundContext(
|
||||||
|
req.context or {}, action[ "context"]))
|
||||||
args = [req.session._db, req.session._uid, req.session._password, action["report_name"], context["active_ids"], {"id": context["active_id"], "model": context["active_model"], "report_type": action["report_type"]}, context]
|
report_id = report_srv.report(
|
||||||
report_id = report_srv.report(*args)
|
req.session._db, req.session._uid, req.session._password,
|
||||||
report = None
|
action["report_name"], context["active_ids"],
|
||||||
|
{"id": context["active_id"],
|
||||||
|
"model": context["active_model"],
|
||||||
|
"report_type": action["report_type"]},
|
||||||
|
context)
|
||||||
|
report_struct = None
|
||||||
while True:
|
while True:
|
||||||
args2 = [req.session._db, req.session._uid, req.session._password, report_id]
|
report_struct = report_srv.report_get(
|
||||||
report = report_srv.report_get(*args2)
|
req.session._db, req.session._uid, req.session._password, report_id)
|
||||||
if report["state"]:
|
if report_struct["state"]:
|
||||||
break
|
break
|
||||||
time.sleep(_REPORT_POLLER_DELAY)
|
time.sleep(self.POLLING_DELAY)
|
||||||
|
|
||||||
#TODO: ok now we've got the report, and so what?
|
report = base64.b64decode(report_struct['result'])
|
||||||
return False
|
report_mimetype = self.TYPES_MAPPING.get(
|
||||||
|
report_struct['format'], 'octet-stream')
|
||||||
|
return req.make_response(report,
|
||||||
|
headers=[
|
||||||
|
('Content-Disposition', 'attachment; filename="%s.%s"' % (action['report_name'], action['report_type'])),
|
||||||
|
('Content-Type', report_mimetype),
|
||||||
|
('Content-Length', len(report))],
|
||||||
|
cookies={'fileToken': int(token)})
|
||||||
|
|
|
@ -125,11 +125,11 @@ openerp.web.ActionManager = openerp.web.Widget.extend({
|
||||||
(this.client_widget = new ClientWidget(this, action.params)).appendTo(this);
|
(this.client_widget = new ClientWidget(this, action.params)).appendTo(this);
|
||||||
},
|
},
|
||||||
ir_actions_report_xml: function(action) {
|
ir_actions_report_xml: function(action) {
|
||||||
this.rpc('/web/report/get_report', {
|
$.blockUI();
|
||||||
action: action,
|
this.session.get_file({
|
||||||
context: {}
|
url: '/web/report',
|
||||||
}).then(function(result) {
|
data: {action: JSON.stringify(action)},
|
||||||
debugger;
|
complete: $.unblockUI
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue