Metadata-Version: 2.1
Name: unicef-rest-export
Version: 0.6
Summary: Django package that handles exporting of data
Home-page: https://github.com/unicef/unicef-rest-export
Author: UNICEF
Author-email: dev@unicef.org
License: Apache 2 License
Platform: any
Classifier: Environment :: Web Environment
Classifier: Programming Language :: Python :: 3.9
Classifier: Framework :: Django
Classifier: Framework :: Django :: 3.2
Classifier: Framework :: Django :: 4.0
Classifier: Intended Audience :: Developers
License-File: LICENSE
Requires-Dist: django
Requires-Dist: djangorestframework-csv
Requires-Dist: djangorestframework
Requires-Dist: lxml
Requires-Dist: python-docx
Requires-Dist: pytz
Requires-Dist: pyyaml
Requires-Dist: reportlab
Requires-Dist: tablib[html,xls,xlsx]
Requires-Dist: xlrd
Requires-Dist: xlwt
Provides-Extra: test
Requires-Dist: coverage ; extra == 'test'
Requires-Dist: factory-boy ; extra == 'test'
Requires-Dist: faker ; extra == 'test'
Requires-Dist: flake8 ; extra == 'test'
Requires-Dist: isort ; extra == 'test'
Requires-Dist: pytest-cov ; extra == 'test'
Requires-Dist: pytest-django ; extra == 'test'
Requires-Dist: pytest-echo ; extra == 'test'
Requires-Dist: pytest-pythonpath ; extra == 'test'
Requires-Dist: pytest ; extra == 'test'
Requires-Dist: psycopg2 ; extra == 'test'

UNICEF Rest Export
==================

Django Rest Framework data export package that handles export/rendering to JSON, CSV, XLS, and HTML


Installation
------------

.. code-block:: bash

    pip install unicef-rest-export


Setup
-----

Add ``unicef_rest_export`` to ``INSTALLED_APPS`` in settings


.. code-block:: bash

    INSTALLED_APPS = [
        ...
        'unicef_rest_export',
    ]


Usage
-----

A sample model view;

.. code-block:: bash

    class AuthorView(ExportView):
        queryset = Author.objects.all()
        serializer_class = serializers.AuthorSerializer


A sample model viewset;

.. code-block:: bash

    class AuthorViewSet(ExportViewSet):
        queryset = Author.objects.all()
        serializer_class = serializers.AuthorSerializer


To override or limit the renderers allowed, add ``EXPORT_RENDERERS`` to settings.
The current default is;

.. code-block:: bash

    EXPORT_RENDERERS = (
        "unicef_rest_export.renderers.ExportHTMLRenderer",
        "unicef_rest_export.renderers.ExportCSVRenderer",
        "unicef_rest_export.renderers.ExportJSONRenderer",
        "unicef_rest_export.renderers.ExportExcelRenderer",
    )

The following is a sample of transforming data;

.. code-block:: bash

    class AuthorTransformView(ExportView):
        queryset = Author.objects.all()
        serializer_class = serializers.AuthorSerializer

        def transform_books(self, data):
            return [d["name"] for d in data]

        def transform_dataset(self, dataset):
            dataset.add_formatter("books", self.transform_books)
            return dataset


Contributing
------------

Environment Setup
~~~~~~~~~~~~~~~~~

To install the necessary libraries

.. code-block:: bash

    $ make install


Coding Standards
~~~~~~~~~~~~~~~~
See [PEP 8 Style Guide for Python Code](https://www.python.org/dev/peps/pep-0008/) for complete details on the coding standards.

To run checks on the code to ensure code is in compliance

.. code-block:: bash

    $ make lint


Testing
~~~~~~~

Testing is important and tests are located in `tests/` directory and can be run with;

.. code-block:: bash

    $ make test

Coverage report is viewable in `build/coverage` directory, and can be generated with;


Project Links
~~~~~~~~~~~~~

 - Continuos Integration - https://circleci.com/gh/unicef/unicef-rest-export/tree/develop
 - Source Code - https://github.com/unicef/unicef-rest-export


Thanks to
---------

[django-rest-pandas](https://github.com/wq/django-rest-pandas) as a lot of the code was borrowed from that package.


