Browse Source

[add] web_export_view

pull/2/head
Lorenzo Battistini 12 years ago
parent
commit
45acc85b5c
  1. 4
      web_export_view/AUTHORS.txt
  2. 15
      web_export_view/README.rst
  3. 22
      web_export_view/__init__.py
  4. 52
      web_export_view/__openerp__.py
  5. 27
      web_export_view/controllers.py
  6. 85
      web_export_view/static/js/web_advanced_export.js

4
web_export_view/AUTHORS.txt

@ -0,0 +1,4 @@
Authors
=======
Simone Orsi <simone.orsi@domsense.com> [simahawk]

15
web_export_view/README.rst

@ -0,0 +1,15 @@
WEB EXPORT VIEW
===============
OpenERP module for that adds a link to the right toolbar for exporting current view (tree type only ATM) to XLS.
You can easuly export your tree/search view "as is": just select the filters you want and click on the export link.
Credits
=======
This product was developed by
.. image:: http://domsense.com/logo-txt.png
:alt: Domsense Website
:target: http://www.domsense.com/

22
web_export_view/__init__.py

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2012 Agile Business Group sagl (<http://www.agilebg.com>)
# Copyright (C) 2012 Domsense srl (<http://www.domsense.com>)
# All Rights Reserved
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import controllers

52
web_export_view/__openerp__.py

@ -0,0 +1,52 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2012 Agile Business Group sagl (<http://www.agilebg.com>)
# Copyright (C) 2012 Domsense srl (<http://www.domsense.com>)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'name': 'Export Current View',
'version': '1.0',
'category': 'Web',
'description': """
WEB EXPORT VIEW
===============
One of the best OpenERPs 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.
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.
If you miss this feature as us, probably youll find an answer into our web_export_view module.
After you installed it, youll find an additional link Export current view right below the Export one. By clicking on it youll get a XLS file contains the same data of the tree view you are looking at, headers included.
""",
'author': 'Agile Business Group',
'website': 'http://www.agilebg.com',
'license': 'AGPL-3',
'depends': ['web'],
'external_dependencies' : {
'python' : ['xlwt'],
},
'data': [],
'active': False,
'auto_install': False,
'js': [
'static/js/web_advanced_export.js',
],
}

27
web_export_view/controllers.py

@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
try:
import json
except ImportError:
import simplejson as json
import web.common.http as openerpweb
from web.controllers.main import ExcelExport
class ExcelExportView(ExcelExport):
_cp_path = '/web/export/xls_view'
@openerpweb.httprequest
def index(self, req, data, token):
data = json.loads(data)
model = data.get('model',[])
columns_headers = data.get('headers',[])
rows = data.get('rows',[])
context = req.session.eval_context(req.context)
return req.make_response(self.from_data(columns_headers, rows),
headers=[('Content-Disposition', 'attachment; filename="%s"' % self.filename(model)),
('Content-Type', self.content_type)],
cookies={'fileToken': int(token)})

85
web_export_view/static/js/web_advanced_export.js

@ -0,0 +1,85 @@
// @@@ web_export_view custom JS @@@
openerp.web_export_view = function(openerp) {
_t = openerp.web._t;
openerp.web.Sidebar = openerp.web.Sidebar.extend({
add_default_sections: function() {
// IMHO sections should be registered objects
// as views and retrieved using a specific registry
// so that we don't have to override this
var self = this,
view = this.widget_parent,
view_manager = view.widget_parent,
action = view_manager.action;
if (this.session.uid === 1) {
this.add_section(_t('Customize'), 'customize');
this.add_items('customize', [{
label: _t("Translate"),
callback: view.on_sidebar_translate,
title: _t("Technical translation")
}]);
}
this.add_section(_t('Other Options'), 'other');
this.add_items('other', [
{
label: _t("Import"),
callback: view.on_sidebar_import
}, {
label: _t("Export"),
callback: view.on_sidebar_export
},
{
label: _t("Export current view"),
callback: this.on_sidebar_export_view
}
]);
},
on_sidebar_export_view: function() {
var self = this,
view = this.widget_parent,
columns = view.visible_columns;
export_columns_keys = [];
export_columns_names = [];
$.each(columns,function(){
if(this.tag=='field'){
// non-fields like `_group` or buttons
export_columns_keys.push(this.id);
export_columns_names.push(this.string);
}
});
rows = view.$element.find('.ui-widget-content tr');
export_rows = [];
$.each(rows,function(){
$row = $(this);
// find only rows with data
if($row.attr('data-id')){
export_row = [];
$.each(export_columns_keys,function(){
cell = $row.find('td[data-field="'+this+'"]').get(0);
text = cell.text || cell.textContent || cell.innerHTML || "";
export_row.push(text.trim());
});
export_rows.push(export_row);
}
});
$.blockUI();
view.session.get_file({
url: '/web/export/xls_view',
data: {data: JSON.stringify({
model : view.model,
headers : export_columns_names,
rows : export_rows,
})},
complete: $.unblockUI
});
},
});
}
Loading…
Cancel
Save