Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exporting tabes data with render_FOO column #458

Closed
jacopsd opened this issue Jun 26, 2017 · 9 comments · Fixed by Karaage-Cluster/karaage#311, mozilla/addons-server#5788, rlmv/doc-trips#90 or drummonds/bene#50

Comments

@jacopsd
Copy link

jacopsd commented Jun 26, 2017

When exporting a table using this approach
https://github.com/bradleyayers/django-tables2/blob/master/docs/pages/export.rst

... a field rendered with the render_FOO technique remains empty in the export.

@jieter
Copy link
Owner

jieter commented Jun 27, 2017

Yes, you are right. Should be fixed (and tested).

@jieter jieter added the bug label Jun 27, 2017
@jieter
Copy link
Owner

jieter commented Jun 27, 2017

Just pushed ecfe1c4, which adds this logic:

  • If value_<name> is defined, use that method to get the value
  • If render_<name> is defined, use that method to get the value
  • Finally, use the column's value()-method.

please test branch master by installing it using the zip file github provides:

pip install -U https://github.com/bradleyayers/django-tables2/archive/master.zip

@jieter jieter added the bugfix label Jun 28, 2017
@jacopsd
Copy link
Author

jacopsd commented Jun 28, 2017

Works fine, except when unicode characters are in the table (running under python 2.7 & django 1.8.16)

In that case, following error occurs:

UnicodeDecodeError at
'ascii' codec can't decode byte 0xc3 in position 9: ordinal not in range(128)
Request Method: GET
Request URL: ?_export=xlsx
Django Version: 1.8.16
Exception Type: UnicodeDecodeError
Exception Value:
'ascii' codec can't decode byte 0xc3 in position 9: ordinal not in range(128)
Exception Location: /venv/lib/python2.7/site-packages/tablib/formats/_xlsx.py in dset_sheet, line 123
Python Executable: /venv/bin/python
Python Version: 2.7.10

@jieter
Copy link
Owner

jieter commented Jun 28, 2017

Interesting.

I just added '毛泽东' to a table and tried exporting to csv, xls and xlsx. It just works. Can you provide some more detail? I tried with these versions:

django-tables2: current master.
python 2.7.10
Django==1.8.16
tablib==0.11.4

@jacopsd
Copy link
Author

jacopsd commented Jun 29, 2017 via email

@jieter
Copy link
Owner

jieter commented Jun 29, 2017

Ah, I didn't try adding unicode to the headers. This is a failing test:

def test_exporting_unicode_header():
    class Table(tables.Table):
        name = tables.Column(verbose_name='hé')

    exporter = TableExport('xls', Table([]))
    exporter.export()

@jieter
Copy link
Owner

jieter commented Jun 29, 2017

Fixed in master (f44ebf2).

@jacopsd can you verify?

@jacopsd
Copy link
Author

jacopsd commented Jun 29, 2017

Verified, OK
Thank you for the fix!

@jieter
Copy link
Owner

jieter commented Jun 29, 2017

thanks for checking, released 1.9.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment