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 report

https://badge.fury.io/py/django-tables2-reports.png https://pypip.in/d/django-tables2-reports/badge.png

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

Requeriments

  • django-tables2 (>=0.11.0, tested to 0.13.0)

  • xlwt or pyExcelerator (>=0.6.4a) or (>=7.2) (These are optionals, to export to xls. Default to xlwt if available)

If you use python3, and you want export to xls use this version of the xlwt (fork) if this pull request is not merged still.

Installation

  • In your settings:

INSTALLED_APPS = (

    'django_tables2_reports',
)


TEMPLATE_CONTEXT_PROCESSORS = (

    'django.core.context_processors.static',

)

Changes in your project

  1. 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):

    ...

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 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!

Releases

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.0.6.tar.gz (17.7 kB view details)

Uploaded Source

File details

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

File metadata

File hashes

Hashes for django-tables2-reports-0.0.6.tar.gz
Algorithm Hash digest
SHA256 18f432cf38e0a88bad56fe389a186ef91ecd35c2b6dd9fa1bd75508a3080b8cc
MD5 6f739ff1b320c45fc182cda692a13955
BLAKE2b-256 9c172e1074c754792f774468c6df1d0efe59f3ab1a85aa9059ed543787e97212

See more details on using hashes here.

Provenance

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