Metadata-Version: 1.1
Name: django-csvexport
Version: 1.0.5
Summary: Simple model to csv conversions for Django.
Home-page: https://github.com/marteinn/django-csvexport
Author: Martin Sandström
Author-email: martin@marteinn.se
License: MIT
Description: |Build Status|
        
        Django-CSVExport
        ================
        
        This is a django extension that simplifies model to csv conversions.
        
        Requirements
        ------------
        
        -  Python 2.7
        -  Django 1.6+
        
        Example:
        --------
        
        Simple usage:
        ~~~~~~~~~~~~~
        
        Generate csv string from a model:
        
        .. code:: python
        
            from csvexport.exports import ModelCSVExporter
        
            records = Record.objects.all()
            exp = ModelExporter(queryset=records)
            f = exp.to_string()
        
        With specified fields
        ~~~~~~~~~~~~~~~~~~~~~
        
        Same as the previous example, but only expose certain fields:
        
        .. code:: python
        
            from csvexport.exports import ModelCSVExporter
        
            class RecordExporter(ModelCSVExporter):
                class Meta:
                    fields = ["album", "slug"]
                    exclude = ["id"]
        
        
            records = Record.objects.all()
            exp = RecordExporter(queryset=records)
            f = exp.to_string()
        
        Generating a csv from a view:
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        
        This is a example how you could generate a downloadable csv by
        requesting a view, using the ``render_to_csv`` helper.
        
        **urls.py**
        
        .. code:: python
        
            url(r'^csv/$', 'app.views.gen_csv'),
        
        **views.py**
        
        .. code:: python
        
            def gen_csv(request):
                from csvexport.exporters import ModelExporter
                from csvexport.utils import render_to_csv
                records = Record.objects.all()
                exp = ModelExporter(queryset=records)
                return render_to_csv(exp)
        
        With custom hydration
        ~~~~~~~~~~~~~~~~~~~~~
        
        It is also possible to create a custom csv object:
        
        .. code:: python
        
            class RecordExporter(ModelExporter):
                class Meta:
                    fields = ["artist", "title", "release_year", "format", "quality",
                              "record_label", "comment", "venue", "url"]
        
                def hydrate_entry(self, entry):
                    venue_name = ""
        
                    if entry.venue:
                        venue_name = entry.venue.name
        
                    return {
                        "artist": entry.album.artist.name,
                        "title": entry.album.name,
                        "release_year": entry.album.release_year,
                        "format": entry.format,
                        "quality": entry.quality,
                        "record_label": entry.record_label,
                        "comment": entry.comment,
                        "venue": venue_name,
                    }
        
        
            records = Record.objects.all()
            exp = RecordExporter(queryset=records)
            f = exp.to_string()
        
        Installation
        ------------
        
        Genres can easily be installed through pip.
        
        ::
        
            $ pip install django-csvexport
        
        Tests
        -----
        
        This library include tests, just run ``python runtests.py``.
        
        You can also run separate test cases: ``runtests.py tests.ViewTestCase``
        
        Contributing
        ------------
        
        Want to contribute? Awesome. Just send a pull request.
        
        License
        -------
        
        Django-CSVExport is released under the `MIT
        License <http://www.opensource.org/licenses/MIT>`__.
        
        .. |Build Status| image:: https://travis-ci.org/marteinn/django-csvexport.svg?branch=master
           :target: https://travis-ci.org/marteinn/django-csvexport
        
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Web Environment
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.7
Classifier: Framework :: Django
Classifier: Topic :: Utilities
