Merge lp:~ovnicraft/web-addons/6.1-web_report_name into lp:~webaddons-core-editors/web-addons/6.1

Proposed by Cristian Salamea
Status: Work in progress
Proposed branch: lp:~ovnicraft/web-addons/6.1-web_report_name
Merge into: lp:~webaddons-core-editors/web-addons/6.1
Diff against target: 173 lines (+150/-0)
4 files modified
web_report_name/__init__.py (+20/-0)
web_report_name/__openerp__.py (+41/-0)
web_report_name/controllers.py (+61/-0)
web_report_name/static/src/js/views.js (+28/-0)
To merge this branch: bzr merge lp:~ovnicraft/web-addons/6.1-web_report_name
Reviewer Review Type Date Requested Status
Holger Brunn (Therp) Needs Information
Web-Addons Core Editors Pending
Review via email: mp+169662@code.launchpad.net

Description of the change

Add module to change report file name, now system gives report.service.name i consider not user friendly and redefine index method to return Action Human-readable Name.pdf defined in report.

So i want help to test.

Regards,

To post a comment you must log in.
14. By Cristian Salamea

[IMP] function to define filename

15. By Cristian Salamea

[FIX] new cp_path report and filename function

Revision history for this message
Holger Brunn (Therp) (hbrunn) wrote :

index is mainly a copy of Reports' index. Is there a reason why you don't call super(...).index here and apply your changes in its return value?

Further: Why don't you hijack the original's _cp_path, as this would make the js-part unnecessary?

review: Needs Information
Revision history for this message
Cristian Salamea (ovnicraft) wrote :

Hi Holger,

I describe what i did:

Try 1. First redefine index module calling super w/o hijacking cp_path and w/o JS code, it does not works.
Try 2. redefine index module w/o JS code, hijack cp_path, does not work, obviously error.
Try 3. Code pushed here.

First code and error: https://gist.github.com/ovnicraft/5794893
I dont understand the error with args, i 'think' could be about decorator and try (stupid try) dont pass token and get this: https://gist.github.com/ovnicraft/5794916

The main problem what i found is index redefinition call does not works.

If you can guide to improve the code and get the goal will thank you.

Regards !

Revision history for this message
Holger Brunn (Therp) (hbrunn) wrote :

That's indeed tricky as we don't want to call the decorated version.
super(FileNameReports, self).index.__closure__[0].cell_contents(self, req, action, token)
should do it.

Revision history for this message
Cristian Salamea (ovnicraft) wrote :

I will give a try your call and see what happen, however i consider is not a very clear redefinition dont call the decorated version.

Thats why i choose redefine completely index method and hijack the cp_path.

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :
Revision history for this message
Cristian Salamea (ovnicraft) wrote :

I consider a dirty hack what i do, hope found a clearest way to do it.

Regards,

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Reading the discussions on this MP I feels that's still work in progress?
Is it true? If yes, can you change the state of the MP to the 'Work in progress' state please?

Unmerged revisions

15. By Cristian Salamea

[FIX] new cp_path report and filename function

14. By Cristian Salamea

[IMP] function to define filename

13. By Cristian Salamea

[IMP] module to add action name to file report instead report.service.name

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'web_report_name'
2=== added file 'web_report_name/__init__.py'
3--- web_report_name/__init__.py 1970-01-01 00:00:00 +0000
4+++ web_report_name/__init__.py 2013-06-16 03:45:31 +0000
5@@ -0,0 +1,20 @@
6+# -*- coding: utf-8 -*-
7+##############################################################################
8+#
9+# Copyright (C) 2013 Gnuthink Software Ci. Ltd. (<http://www.gnuthink.com>)
10+#
11+# This program is free software: you can redistribute it and/or modify
12+# it under the terms of the GNU Affero General Public License as published
13+# by the Free Software Foundation, either version 3 of the License, or
14+# (at your option) any later version.
15+#
16+# This program is distributed in the hope that it will be useful,
17+# but WITHOUT ANY WARRANTY; without even the implied warranty of
18+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+# GNU Affero General Public License for more details.
20+#
21+# You should have received a copy of the GNU Affero General Public License
22+# along with this program. If not, see <http://www.gnu.org/licenses/>.
23+#
24+##############################################################################
25+import controllers
26
27=== added file 'web_report_name/__openerp__.py'
28--- web_report_name/__openerp__.py 1970-01-01 00:00:00 +0000
29+++ web_report_name/__openerp__.py 2013-06-16 03:45:31 +0000
30@@ -0,0 +1,41 @@
31+# -*- coding: utf-8 -*-
32+##############################################################################
33+#
34+# Copyright (C) 2013 Gnuthink Software Ci. Ltd. (<http://www.gnuthink.com>)
35+#
36+# This program is free software: you can redistribute it and/or modify
37+# it under the terms of the GNU Affero General Public License as published
38+# by the Free Software Foundation, either version 3 of the License, or
39+# (at your option) any later version.
40+#
41+# This program is distributed in the hope that it will be useful,
42+# but WITHOUT ANY WARRANTY; without even the implied warranty of
43+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44+# GNU Affero General Public License for more details.
45+#
46+# You should have received a copy of the GNU Affero General Public License
47+# along with this program. If not, see <http://www.gnu.org/licenses/>.
48+#
49+##############################################################################
50+
51+{
52+ 'name': 'Report Name',
53+ 'version': '1.0',
54+ 'category': 'Web',
55+ 'description': """
56+WEB REPORT NAME
57+===============
58+
59+All reports are exported with my.model.name.pdf
60+We prefer call it Name Readable Report.pdf
61+""",
62+ 'author': 'Gnuthink Software Co. Ltd.',
63+ 'website': 'http://www.gnuthink.com',
64+ 'license': 'AGPL-3',
65+ 'depends': ['web'],
66+ 'data': [],
67+ 'js': ['static/src/js/views.js'],
68+ 'active': False,
69+ 'auto_install': False,
70+}
71+
72
73=== added file 'web_report_name/controllers.py'
74--- web_report_name/controllers.py 1970-01-01 00:00:00 +0000
75+++ web_report_name/controllers.py 2013-06-16 03:45:31 +0000
76@@ -0,0 +1,61 @@
77+import base64
78+import time
79+import simplejson
80+
81+from web import common
82+import web.common.http as openerpweb
83+from web.controllers.main import Reports
84+
85+class FileNameReports(Reports):
86+
87+ _cp_path = "/web/fn_report"
88+
89+ def get_filename_report(self, action, report_struct):
90+ filename = '%s %s.%s' %(action['name'], time.strftime('%Y-%m-%d %H%M%S'), report_struct['format'])
91+ return filename
92+
93+ @openerpweb.httprequest
94+ def index(self, req, action, token):
95+ action = simplejson.loads(action)
96+
97+ report_srv = req.session.proxy("report")
98+ context = req.session.eval_context(
99+ common.nonliterals.CompoundContext(
100+ req.context or {}, action[ "context"]))
101+
102+ report_data = {}
103+ report_ids = context["active_ids"]
104+ if 'report_type' in action:
105+ report_data['report_type'] = action['report_type']
106+ if 'datas' in action:
107+ if 'ids' in action['datas']:
108+ report_ids = action['datas'].pop('ids')
109+ report_data.update(action['datas'])
110+
111+ report_id = report_srv.report(
112+ req.session._db, req.session._uid, req.session._password,
113+ action["report_name"], report_ids,
114+ report_data, context)
115+
116+ report_struct = None
117+ while True:
118+ report_struct = report_srv.report_get(
119+ req.session._db, req.session._uid, req.session._password, report_id)
120+ if report_struct["state"]:
121+ break
122+
123+ time.sleep(self.POLLING_DELAY)
124+
125+ report = base64.b64decode(report_struct['result'])
126+ if report_struct.get('code') == 'zlib':
127+ report = zlib.decompress(report)
128+ report_mimetype = self.TYPES_MAPPING.get(
129+ report_struct['format'], 'octet-stream')
130+ return req.make_response(report,
131+ headers=[
132+ ('Content-Disposition', 'attachment; filename="%s"' % self.get_filename_report(action, report_struct)),
133+ ('Content-Type', report_mimetype),
134+ ('Content-Length', len(report))],
135+ cookies={'fileToken': int(token)})
136+
137+
138
139=== added directory 'web_report_name/static'
140=== added directory 'web_report_name/static/src'
141=== added directory 'web_report_name/static/src/js'
142=== added file 'web_report_name/static/src/js/views.js'
143--- web_report_name/static/src/js/views.js 1970-01-01 00:00:00 +0000
144+++ web_report_name/static/src/js/views.js 2013-06-16 03:45:31 +0000
145@@ -0,0 +1,28 @@
146+openerp.web_report_name = function(session) {
147+
148+ session.web.ActionManager = session.web.ActionManager.extend({
149+ ir_actions_report_xml: function(action, on_closed) {
150+ var self = this;
151+ $.blockUI();
152+ self.rpc("/web/session/eval_domain_and_context", {
153+ contexts: [action.context],
154+ domains: []
155+ }).then(function(res) {
156+ action = _.clone(action);
157+ action.context = res.context;
158+ self.session.get_file({
159+ url: '/web/fn_report',
160+ data: {action: JSON.stringify(action)},
161+ complete: $.unblockUI,
162+ success: function(){
163+ if (!self.dialog && on_closed) {
164+ on_closed();
165+ }
166+ self.dialog_stop();
167+ },
168+ error: session.webclient.crashmanager.on_rpc_error
169+ })
170+ });
171+ }
172+ });
173+}

Subscribers

People subscribed via source and target branches