[IMP] display a warning and disable excel export option when XLWT is not installed
lp bug: https://launchpad.net/bugs/915347 fixed bzr revid: xmo@openerp.com-20120113090611-lmiu5y7y7b9td8hg
This commit is contained in:
parent
4f57d12b65
commit
c89d45b658
|
@ -18,6 +18,10 @@ from cStringIO import StringIO
|
|||
|
||||
import babel.messages.pofile
|
||||
import werkzeug.utils
|
||||
try:
|
||||
import xlwt
|
||||
except ImportError:
|
||||
xlwt = None
|
||||
|
||||
import web.common
|
||||
openerpweb = web.common.http
|
||||
|
@ -1308,7 +1312,7 @@ class Export(View):
|
|||
for path, controller in openerpweb.controllers_path.iteritems()
|
||||
if path.startswith(self._cp_path)
|
||||
if hasattr(controller, 'fmt')
|
||||
], key=operator.itemgetter(1))
|
||||
], key=operator.itemgetter("label"))
|
||||
|
||||
def fields_get(self, req, model):
|
||||
Model = req.session.model(model)
|
||||
|
@ -1484,7 +1488,7 @@ class Export(View):
|
|||
|
||||
class CSVExport(Export):
|
||||
_cp_path = '/web/export/csv'
|
||||
fmt = ('csv', 'CSV')
|
||||
fmt = {'tag': 'csv', 'label': 'CSV'}
|
||||
|
||||
@property
|
||||
def content_type(self):
|
||||
|
@ -1519,7 +1523,11 @@ class CSVExport(Export):
|
|||
|
||||
class ExcelExport(Export):
|
||||
_cp_path = '/web/export/xls'
|
||||
fmt = ('xls', 'Excel')
|
||||
fmt = {
|
||||
'tag': 'xls',
|
||||
'label': 'Excel',
|
||||
'error': None if xlwt else "XLWT required"
|
||||
}
|
||||
|
||||
@property
|
||||
def content_type(self):
|
||||
|
@ -1529,8 +1537,6 @@ class ExcelExport(Export):
|
|||
return base + '.xls'
|
||||
|
||||
def from_data(self, fields, rows):
|
||||
import xlwt
|
||||
|
||||
workbook = xlwt.Workbook()
|
||||
worksheet = workbook.add_sheet('Sheet 1')
|
||||
|
||||
|
|
|
@ -63,7 +63,15 @@ openerp.web.DataExport = openerp.web.Dialog.extend({
|
|||
do_setup_export_formats: function (formats) {
|
||||
var $fmts = this.$element.find('#export_format');
|
||||
_(formats).each(function (format) {
|
||||
$fmts.append(new Option(format[1], format[0]));
|
||||
var opt = new Option(format.label, format.tag);
|
||||
if (format.error) {
|
||||
opt.disabled = true;
|
||||
opt.replaceChild(
|
||||
document.createTextNode(
|
||||
_.str.sprintf("%s — %s", format.label, format.error)),
|
||||
opt.childNodes[0])
|
||||
}
|
||||
$fmts.append(opt);
|
||||
});
|
||||
},
|
||||
show_exports_list: function() {
|
||||
|
|
Loading…
Reference in New Issue