Merge lp:~domsense/web-addons/adding_web_export_view into lp:~webaddons-core-editors/web-addons/6.1

Proposed by Lorenzo Battistini
Status: Merged
Merged at revision: 9
Proposed branch: lp:~domsense/web-addons/adding_web_export_view
Merge into: lp:~webaddons-core-editors/web-addons/6.1
Diff against target: 270 lines (+243/-0)
5 files modified
web_export_view/AUTHORS.txt (+6/-0)
web_export_view/__init__.py (+21/-0)
web_export_view/__openerp__.py (+53/-0)
web_export_view/controllers.py (+46/-0)
web_export_view/static/js/web_advanced_export.js (+117/-0)
To merge this branch: bzr merge lp:~domsense/web-addons/adding_web_export_view
Reviewer Review Type Date Requested Status
Nicolas Bessi - Camptocamp (community) Needs Information
Guewen Baconnier @ Camptocamp no test, code review Approve
Alexandre Fayolle - camptocamp Approve
Review via email: mp+144022@code.launchpad.net

Description of the change

web_export_view module.

After you installed it, you’ll find an additional link ‘Export current view’ right below the ‘Export’ one. By clicking on it you’ll get a XLS file contains the same data of the tree view you are looking at, headers included

To post a comment you must log in.
7. By Lorenzo Battistini

[DEL] README.rst

Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

Stefan Rijnhart is mentionned (without email) in the AUTHORS.txt but not in the headers of the added files. Is this intended?

apart from this, LGTM.

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

Looks fine to me

review: Approve (no test, code review)
Revision history for this message
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote :

Hello,

Would it not be cleaner to use the "dataset"/"Model" records, data, etc. properties of the view to get data to send to server instead of parsing HTML?

I'm not familiarized with the new WebClient API yet and maybe I missed some point of view_list.js but it seems possible to do it this way.

On the other hand, It is also True that the base API relies a lot on CSS selector.

Any opinions ??

Regards

Nicolas

review: Needs Information
8. By Lorenzo Battistini

[ADD] copyright header

Revision history for this message
Lorenzo Battistini (elbati) wrote :

On 01/21/2013 09:41 AM, Alexandre Fayolle @ camptocamp wrote:
>
> Stefan Rijnhart is mentionned (without email) in the AUTHORS.txt but not in the headers of the added files. Is this intended?

Added copyright header.

About email: Stefan, do you want to tell me the address to use? (I just
tested and manually copied this patch
<http://bazaar.launchpad.net/%7Etherp-nl/domsense-agilebg-web-addons/6.1-export_first_list__in_form_view/revision/18>.)

Thanks

Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Hi Lorenzo,

a pleasant surprise to see our small contribution merged spontaneously. Thanks for the attribution too. For the email address, you can almost always get the committers email from the source branch' log. In this case, get my address from

    bzr log -r -1 http://bazaar.launchpad.net/%7Etherp-nl/domsense-agilebg-web-addons/6.1-export_first_list__in_form_view

Cheers,
Stefan.

9. By Lorenzo Battistini

[FIX] authors

Revision history for this message
Lorenzo Battistini (elbati) wrote :

On 01/28/2013 06:28 PM, Stefan Rijnhart (Therp) wrote:
> Hi Lorenzo,
>
> a pleasant surprise to see our small contribution merged spontaneously. Thanks for the attribution too. For the email address, you can almost always get the committers email from the source branch' log. In this case, get my address from
>
> bzr log -r -1 http://bazaar.launchpad.net/%7Etherp-nl/domsense-agilebg-web-addons/6.1-export_first_list__in_form_view

Right, thanks :-)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'web_export_view'
2=== added file 'web_export_view/AUTHORS.txt'
3--- web_export_view/AUTHORS.txt 1970-01-01 00:00:00 +0000
4+++ web_export_view/AUTHORS.txt 2013-01-28 18:37:22 +0000
5@@ -0,0 +1,6 @@
6+Authors
7+=======
8+
9+Simone Orsi <simone.orsi@domsense.com> [simahawk]
10+Lorenzo Battistini <lorenzo.battistini@agilebg.com>
11+Stefan Rijnhart <stefan@therp.nl>
12
13=== added file 'web_export_view/__init__.py'
14--- web_export_view/__init__.py 1970-01-01 00:00:00 +0000
15+++ web_export_view/__init__.py 2013-01-28 18:37:22 +0000
16@@ -0,0 +1,21 @@
17+# -*- coding: utf-8 -*-
18+##############################################################################
19+#
20+# Copyright (C) 2012 Agile Business Group sagl (<http://www.agilebg.com>)
21+# Copyright (C) 2012 Domsense srl (<http://www.domsense.com>)
22+#
23+# This program is free software: you can redistribute it and/or modify
24+# it under the terms of the GNU Affero General Public License as published
25+# by the Free Software Foundation, either version 3 of the License, or
26+# (at your option) any later version.
27+#
28+# This program is distributed in the hope that it will be useful,
29+# but WITHOUT ANY WARRANTY; without even the implied warranty of
30+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31+# GNU Affero General Public License for more details.
32+#
33+# You should have received a copy of the GNU Affero General Public License
34+# along with this program. If not, see <http://www.gnu.org/licenses/>.
35+#
36+##############################################################################
37+import controllers
38
39=== added file 'web_export_view/__openerp__.py'
40--- web_export_view/__openerp__.py 1970-01-01 00:00:00 +0000
41+++ web_export_view/__openerp__.py 2013-01-28 18:37:22 +0000
42@@ -0,0 +1,53 @@
43+# -*- coding: utf-8 -*-
44+##############################################################################
45+#
46+# Copyright (C) 2012 Domsense srl (<http://www.domsense.com>)
47+# Copyright (C) 2012-2013 Agile Business Group sagl
48+# (<http://www.agilebg.com>)
49+#
50+# This program is free software: you can redistribute it and/or modify
51+# it under the terms of the GNU Affero General Public License as published
52+# by the Free Software Foundation, either version 3 of the License, or
53+# (at your option) any later version.
54+#
55+# This program is distributed in the hope that it will be useful,
56+# but WITHOUT ANY WARRANTY; without even the implied warranty of
57+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
58+# GNU Affero General Public License for more details.
59+#
60+# You should have received a copy of the GNU Affero General Public License
61+# along with this program. If not, see <http://www.gnu.org/licenses/>.
62+#
63+##############################################################################
64+
65+{
66+ 'name': 'Export Current View',
67+ 'version': '1.0',
68+ 'category': 'Web',
69+ 'description': """
70+WEB EXPORT VIEW
71+===============
72+
73+One of the best OpenERP’s features is exporting custom data to CSV/XLS. You can do it by clicking on the export link in the sidebar. The export action allows use to configure what to be exported by selecting fields, etc, and allows you to save your export as a template so that you can export it once again without having to configure it again.
74+
75+That feature is as great and advanced as limited for an everyday-customer-experience. A lot of customers want simply to export the tree view they are looking to.
76+
77+If you miss this feature as us, probably you’ll find an answer into our web_export_view module.
78+
79+After you installed it, you’ll find an additional link ‘Export current view’ right below the ‘Export’ one. By clicking on it you’ll get a XLS file contains the same data of the tree view you are looking at, headers included.
80+""",
81+ 'author': 'Agile Business Group',
82+ 'website': 'http://www.agilebg.com',
83+ 'license': 'AGPL-3',
84+ 'depends': ['web'],
85+ 'external_dependencies' : {
86+ 'python' : ['xlwt'],
87+ },
88+ 'data': [],
89+ 'active': False,
90+ 'auto_install': False,
91+ 'js': [
92+ 'static/js/web_advanced_export.js',
93+ ],
94+}
95+
96
97=== added file 'web_export_view/controllers.py'
98--- web_export_view/controllers.py 1970-01-01 00:00:00 +0000
99+++ web_export_view/controllers.py 2013-01-28 18:37:22 +0000
100@@ -0,0 +1,46 @@
101+# -*- coding: utf-8 -*-
102+##############################################################################
103+#
104+# Copyright (C) 2012 Agile Business Group sagl (<http://www.agilebg.com>)
105+# Copyright (C) 2012 Domsense srl (<http://www.domsense.com>)
106+#
107+# This program is free software: you can redistribute it and/or modify
108+# it under the terms of the GNU Affero General Public License as published
109+# by the Free Software Foundation, either version 3 of the License, or
110+# (at your option) any later version.
111+#
112+# This program is distributed in the hope that it will be useful,
113+# but WITHOUT ANY WARRANTY; without even the implied warranty of
114+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
115+# GNU Affero General Public License for more details.
116+#
117+# You should have received a copy of the GNU Affero General Public License
118+# along with this program. If not, see <http://www.gnu.org/licenses/>.
119+#
120+##############################################################################
121+try:
122+ import json
123+except ImportError:
124+ import simplejson as json
125+
126+import web.common.http as openerpweb
127+
128+from web.controllers.main import ExcelExport
129+
130+
131+class ExcelExportView(ExcelExport):
132+ _cp_path = '/web/export/xls_view'
133+
134+ @openerpweb.httprequest
135+ def index(self, req, data, token):
136+ data = json.loads(data)
137+ model = data.get('model',[])
138+ columns_headers = data.get('headers',[])
139+ rows = data.get('rows',[])
140+
141+ context = req.session.eval_context(req.context)
142+
143+ return req.make_response(self.from_data(columns_headers, rows),
144+ headers=[('Content-Disposition', 'attachment; filename="%s"' % self.filename(model)),
145+ ('Content-Type', self.content_type)],
146+ cookies={'fileToken': int(token)})
147
148=== added directory 'web_export_view/static'
149=== added directory 'web_export_view/static/js'
150=== added file 'web_export_view/static/js/web_advanced_export.js'
151--- web_export_view/static/js/web_advanced_export.js 1970-01-01 00:00:00 +0000
152+++ web_export_view/static/js/web_advanced_export.js 2013-01-28 18:37:22 +0000
153@@ -0,0 +1,117 @@
154+// @@@ web_export_view custom JS @@@
155+//#############################################################################
156+//
157+// Copyright (C) 2012 Agile Business Group sagl (<http://www.agilebg.com>)
158+// Copyright (C) 2012 Therp BV (<http://therp.nl>)
159+//
160+// This program is free software: you can redistribute it and/or modify
161+// it under the terms of the GNU Affero General Public License as published
162+// by the Free Software Foundation, either version 3 of the License, or
163+// (at your option) any later version.
164+//
165+// This program is distributed in the hope that it will be useful,
166+// but WITHOUT ANY WARRANTY; without even the implied warranty of
167+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
168+// GNU Affero General Public License for more details.
169+//
170+// You should have received a copy of the GNU Affero General Public License
171+// along with this program. If not, see <http://www.gnu.org/licenses/>.
172+//
173+//#############################################################################
174+
175+openerp.web_export_view = function(openerp) {
176+
177+ _t = openerp.web._t;
178+
179+ openerp.web.Sidebar = openerp.web.Sidebar.extend({
180+
181+ add_default_sections: function() {
182+ // IMHO sections should be registered objects
183+ // as views and retrieved using a specific registry
184+ // so that we don't have to override this
185+
186+ var self = this,
187+ view = this.widget_parent,
188+ view_manager = view.widget_parent,
189+ action = view_manager.action;
190+ if (this.session.uid === 1) {
191+ this.add_section(_t('Customize'), 'customize');
192+ this.add_items('customize', [{
193+ label: _t("Translate"),
194+ callback: view.on_sidebar_translate,
195+ title: _t("Technical translation")
196+ }]);
197+ }
198+
199+ this.add_section(_t('Other Options'), 'other');
200+ this.add_items('other', [
201+ {
202+ label: _t("Import"),
203+ callback: view.on_sidebar_import
204+ }, {
205+ label: _t("Export"),
206+ callback: view.on_sidebar_export
207+ },
208+ {
209+ label: _t("Export current view"),
210+ callback: this.on_sidebar_export_view
211+ }
212+ ]);
213+ },
214+
215+ on_sidebar_export_view: function() {
216+ // Select the first list of the current (form) view
217+ // or assume the main view is a list view and use that
218+ var self = this,
219+ view = this.widget_parent; // valid for list view
220+ if (view.widget_children) {
221+ view.widget_children.every(function(child) {
222+ if (child.field && (
223+ child.field.type == 'many2many'
224+ || child.field.type == 'one2many')) {
225+ view = child.viewmanager.views.list.controller;
226+ return false; // break out of the loop
227+ }
228+ return true;
229+ });
230+ }
231+ var columns = view.visible_columns;
232+ export_columns_keys = [];
233+ export_columns_names = [];
234+ $.each(columns,function(){
235+ if(this.tag=='field'){
236+ // non-fields like `_group` or buttons
237+ export_columns_keys.push(this.id);
238+ export_columns_names.push(this.string);
239+ }
240+ });
241+ rows = view.$element.find('.ui-widget-content tr');
242+ export_rows = [];
243+ $.each(rows,function(){
244+ $row = $(this);
245+ // find only rows with data
246+ if($row.attr('data-id')){
247+ export_row = [];
248+ $.each(export_columns_keys,function(){
249+ cell = $row.find('td[data-field="'+this+'"]').get(0);
250+ text = cell.text || cell.textContent || cell.innerHTML || "";
251+ export_row.push(text.trim());
252+ });
253+ export_rows.push(export_row);
254+ }
255+ });
256+ $.blockUI();
257+ view.session.get_file({
258+ url: '/web/export/xls_view',
259+ data: {data: JSON.stringify({
260+ model : view.model,
261+ headers : export_columns_names,
262+ rows : export_rows,
263+ })},
264+ complete: $.unblockUI
265+ });
266+ },
267+
268+ });
269+
270+}

Subscribers

People subscribed via source and target branches