Giter Site home page Giter Site logo

savoirfairelinux / django-tables2-reports Goto Github PK

View Code? Open in Web Editor NEW

This project forked from goinnn/django-tables2-reports

0.0 18.0 0.0 140 KB

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

Python 98.31% HTML 1.69%

django-tables2-reports's Introduction

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

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

This fork exists because, at the time of the fork, upstream seemed dead. We needed to update this package in order to keep up with Django 1.8+ (and thus, django-tables2 1.2+).

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

  • 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'

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

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!

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

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

django-tables2-reports's People

Contributors

goinnn avatar mpasternak avatar bitdeli-chef avatar daaray avatar paulgueltekin avatar sramana avatar armicron avatar

Watchers

Maxime Dupuis avatar Emmanuel Milou avatar Anton Samarchyan avatar  avatar James Cloos avatar Jérôme Oufella avatar Anthony Guimard avatar Alexandre Lision avatar Adonys Alea Boffill avatar Alexis Piéplu avatar Morgan Aubert avatar Philippe MOUCHEL avatar David Barbeau avatar Maxime Connolly avatar Ernesto Rodriguez Ortiz avatar Frédéric Guimont avatar Souleymane Sow avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.