Skip to main content

With django-tables2-reports you can get a report (CSV, XLS) of any django-tables2 with minimal changes to your project

Project description

django-tables2-reports

https://travis-ci.org/goinnn/django-tables2-reports.svg?branch=master https://coveralls.io/repos/goinnn/django-tables2-reports/badge.png?branch=master https://badge.fury.io/py/django-tables2-reports.svg

With django-tables2-reports you can get a report (CSV, XLS) of any table with minimal changes to your project

Requirements

Installation

  • In your settings:

INSTALLED_APPS = (

    'django_tables2_reports',
)


TEMPLATE_CONTEXT_PROCESSORS = (

    'django.core.context_processors.static',

)


# This is optional

EXCEL_SUPPORT = 'xlwt' # or 'openpyxl' or 'pyexcelerator'

Changes in your project

1.a Now your table should extend of ‘TableReport’

############### Before ###################

import django_tables2 as tables


class MyTable(tables.Table):

    ...

############### Now ######################

from django_tables2_reports.tables import TableReport


class MyTable(TableReport):

    ...

1.b If you want to exclude some columns from report (e.g. if it is a column of buttons), you should set ‘exclude_from_report’ - the names of columns (as well as property ‘exclude’ in table)

class MyTable(TableReport):

    class Meta:
        exclude_from_report = ('column1', ...)
    ...

2.a. If you use a traditional views, now you should use other RequestConfig and change a little your view:

############### Before ###################

from django_tables2 import RequestConfig


def my_view(request):
    objs = ....
    table = MyTable(objs)
    RequestConfig(request).configure(table)
    return render_to_response('app1/my_view.html',
                              {'table': table},
                              context_instance=RequestContext(request))

############### Now ######################

from django_tables2_reports.config import RequestConfigReport as RequestConfig
from django_tables2_reports.utils import create_report_http_response

def my_view(request):
    objs = ....
    table = MyTable(objs)
    table_to_report = RequestConfig(request).configure(table)
    if table_to_report:
        return create_report_http_response(table_to_report, request)
    return render_to_response('app1/my_view.html',
                              {'table': table},
                              context_instance=RequestContext(request))

If you have a lot of tables in your project, you can activate the middleware, and you do not have to change your views, only the RequestConfig import

# In your settings

MIDDLEWARE_CLASSES = (

    'django_tables2_reports.middleware.TableReportMiddleware',
)

############### Now (with middleware) ######################

from django_tables2_reports.config import RequestConfigReport as RequestConfig

def my_view(request):
    objs = ....
    table = MyTable(objs)
    RequestConfig(request).configure(table)
    return render_to_response('app1/my_view.html',
                              {'table': table},
                              context_instance=RequestContext(request))

2.b. If you use a Class-based views:

############### Before ###################

from django_tables2.views import SingleTableView


class PhaseChangeView(SingleTableView):
    table_class = MyTable
    model = MyModel


############### Now ######################

from django_tables2_reports.views import ReportTableView


class PhaseChangeView(ReportTableView):
    table_class = MyTable
    model = MyModel

Usage

Under the table appear a CSV icon (and XLS icon if you have xlwt, openpyxl or pyExcelerator in your python path), if you click in this icon, you get a CSV report (or xls report) with every item of the table (without pagination). The ordering works!

Development

You can get the last bleeding edge version of django-tables2-reports by doing a clone of its git repository:

git clone https://github.com/goinnn/django-tables2-reports

Test project

In the source tree, you will find a directory called ‘test_project’. It contains a readily setup project that uses django-tables2-reports. You can run it as usual:

python manage.py syncdb --noinput
python manage.py runserver

Releases

0.1.0 (2017-06-19)

  • maintenance release,

  • Django 1.8, 1.9, 1.10, 1.11 support,

  • openpyxl > 2.0.0 support,

  • recent django-tables2 support,

  • new maintainer Michał Pasternak

0.0.10 (2014-10-13)

  • Fixes for xlsx Content-Type:
    • django-tables2-reports throws 500 Sever Error when report format is not recognized. 404 is more appropriate in this case.

    • django-tables2-reports sets Content-Type to application/vnd.ms-excel for xlsx files which causes warnings in Firefox. application/vnd.openxmlformats-officedocument.spreadsheetml.sheet is the correct Content-Type for xlsx

  • Support to Django 1.7 (I’m sorry to the delay)

  • Adding new feature: exclude_from_report

  • And a little details

  • Thanks to:

0.0.9 (2013-11-30)

  • Compatible with the future version of Django (>=1.7)

  • Update the tests

  • Refactor the code

  • Fix a bug when the title of the sheet is longer than 31

  • Thanks to:

0.0.8 (2013-11-14)

0.0.7 (2013-08-29)

  • Russian translations

  • Thanks to:

0.0.6 (2013-08-22)

0.0.5 (2013-07-03)

0.0.4 (2013-05-17)

  • Escape csv data correctly during output

  • The fields with commas now are not split into multiple columns

  • Thanks to:

0.0.3 (2012-07-19)

  • Fix a little error, when a column has line breaks. Now these are changed to espaces

  • Details

0.0.2 (2012-07-18)

0.0.1 (2012-07-17)

  • Initial release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-tables2-reports-0.1.0.tar.gz (21.5 kB view details)

Uploaded Source

Built Distribution

django_tables2_reports-0.1.0-py2-none-any.whl (34.6 kB view details)

Uploaded Python 2

File details

Details for the file django-tables2-reports-0.1.0.tar.gz.

File metadata

File hashes

Hashes for django-tables2-reports-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4c565ee012bf523412e3ec771027974e5138a3748642fd917e749c3ebdd5ca93
MD5 7ef71997403b17b7f6d1d05397d11c78
BLAKE2b-256 2491e977fee8d873d41003930fd2ca5aa9ae099e1358a7ba817191bdd94fec18

See more details on using hashes here.

File details

Details for the file django_tables2_reports-0.1.0-py2-none-any.whl.

File metadata

File hashes

Hashes for django_tables2_reports-0.1.0-py2-none-any.whl
Algorithm Hash digest
SHA256 3305ccd376953a685121e2eb6f4d815d85ad85d1b47c01a0616da41698099a3e
MD5 7612ba00c0b144f0d26ec6d257e9c9c6
BLAKE2b-256 ad9464eab0bb55e1466f949340a213398980d5d30c14aa2f67e50f63696ee9f8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page