Browse Source

[FIX] Protect import of unicodecsv

pull/359/head
Stefan Rijnhart 9 years ago
parent
commit
8567336609
  1. 7
      sql_view/wizards/sql_view_csv_preview.py

7
sql_view/wizards/sql_view_csv_preview.py

@ -22,9 +22,13 @@
import base64 import base64
from StringIO import StringIO from StringIO import StringIO
try:
import unicodecsv import unicodecsv
except ImportError:
unicodecsv = None
from openerp.osv import orm, fields from openerp.osv import orm, fields
from openerp.tools.translate import _
class SQLViewCSVPreview(orm.TransientModel): class SQLViewCSVPreview(orm.TransientModel):
@ -65,6 +69,9 @@ class SQLViewCSVPreview(orm.TransientModel):
headers = [desc[0] for desc in cr.description] headers = [desc[0] for desc in cr.description]
records = cr.fetchall() records = cr.fetchall()
filedata = StringIO() filedata = StringIO()
if not unicodecsv:
raise orm.except_orm(
_('Error'), _('Please install the unicodecsv library'))
try: try:
writer = unicodecsv.writer(filedata, encoding='utf-8') writer = unicodecsv.writer(filedata, encoding='utf-8')
writer.writerow(headers) writer.writerow(headers)

Loading…
Cancel
Save