drfexts


Namedrfexts JSON
Version 3.9.0 PyPI version JSON
download
home_pagehttps://github.com/aiden520/drfexts
SummaryDjango Restframework Utils
upload_time2024-04-29 07:56:08
maintainerNone
docs_urlNone
authoraiden
requires_python<4.0.0,>=3.10
licenseApache-2.0
keywords django restframework
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            drfexts
=======

[![GitHub license](https://img.shields.io/github/license/aiden520/drfexts)](https://github.com/aiden520/drfexts/blob/master/LICENSE)
[![pypi-version](https://img.shields.io/pypi/v/drfexts.svg)](https://pypi.python.org/pypi/drfexts)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/drfexts)
[![PyPI - Django Version](https://img.shields.io/badge/django-%3E%3D3.0-44B78B)](https://www.djangoproject.com/)
[![PyPI - DRF Version](https://img.shields.io/badge/djangorestframework-%3E%3D3.0-red)](https://www.django-rest-framework.org)
[![Build Status](https://app.travis-ci.com/aiden520/drfexts.svg?branch=master)](https://app.travis-ci.com/aiden520/drfexts)
[![Black code style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)


**Extensions for Django REST Framework**


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

``` {.bash}
$ pip install drfexts
```

Usage
-----

*views.py*

``` {.python}
from rest_framework.views import APIView
from rest_framework.settings import api_settings
from drfexts.viewsets import ExportMixin

class MyView (ExportMixin, APIView):
    ...
```

Ordered Fields
--------------

By default, a `CSVRenderer` will output fields in sorted order. To
specify an alternative field ordering you can override the `header`
attribute. There are two ways to do this:

1)  Create a new renderer class and override the `header` attribute
    directly:

    > ``` {.python}
    > class MyUserRenderer (CSVRenderer):
    >     header = ['first', 'last', 'email']
    >
    > @api_view(['GET'])
    > @renderer_classes((MyUserRenderer,))
    > def my_view(request):
    >     users = User.objects.filter(active=True)
    >     content = [{'first': user.first_name,
    >                 'last': user.last_name,
    >                 'email': user.email}
    >                for user in users]
    >     return Response(content)
    > ```

2)  Use the `renderer_context` to override the field ordering on the
    fly:

    > ``` {.python}
    > class MyView (APIView):
    >     renderer_classes = [CSVRenderer]
    >
    >     def get_renderer_context(self):
    >         context = super().get_renderer_context()
    >         context['header'] = (
    >             self.request.GET['fields'].split(',')
    >             if 'fields' in self.request.GET else None)
    >         return context
    >
    >     ...
    > ```

Labeled Fields
--------------

Custom labels can be applied to the `CSVRenderer` using the `labels`
dict attribute where each key corresponds to the header and the value
corresponds to the custom label for that header.

1\) Create a new renderer class and override the `header` and `labels`
attribute directly:

> ``` {.python}
> class MyBazRenderer (CSVRenderer):
>     header = ['foo.bar']
>     labels = {
>         'foo.bar': 'baz'
>     }
> ```


Pagination
----------

Using the renderer with paginated data is also possible with the new
[PaginatedCSVRenderer]{.title-ref} class and should be used with views
that paginate data

For more information about using renderers with Django REST Framework,
see the [API
Guide](http://django-rest-framework.org/api-guide/renderers/) or the
[Tutorial](http://django-rest-framework.org/tutorial/1-serialization/).


Running the tests
-----------------

To run the tests against the current environment:

``` {.bash}
$ ./manage.py test
```

### Changelog

1.0.0
-----


-   Initial release

## Thanks

[![PyCharm](docs/pycharm.svg)](https://www.jetbrains.com/?from=drfexts)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/aiden520/drfexts",
    "name": "drfexts",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0.0,>=3.10",
    "maintainer_email": null,
    "keywords": "django, restframework",
    "author": "aiden",
    "author_email": "allaher@icloud.com",
    "download_url": "https://files.pythonhosted.org/packages/85/84/ff91612e0c29de31c44d713a44f152b5c2bd7edb8fd521a023119627d9e0/drfexts-3.9.0.tar.gz",
    "platform": null,
    "description": "drfexts\n=======\n\n[![GitHub license](https://img.shields.io/github/license/aiden520/drfexts)](https://github.com/aiden520/drfexts/blob/master/LICENSE)\n[![pypi-version](https://img.shields.io/pypi/v/drfexts.svg)](https://pypi.python.org/pypi/drfexts)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/drfexts)\n[![PyPI - Django Version](https://img.shields.io/badge/django-%3E%3D3.0-44B78B)](https://www.djangoproject.com/)\n[![PyPI - DRF Version](https://img.shields.io/badge/djangorestframework-%3E%3D3.0-red)](https://www.django-rest-framework.org)\n[![Build Status](https://app.travis-ci.com/aiden520/drfexts.svg?branch=master)](https://app.travis-ci.com/aiden520/drfexts)\n[![Black code style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)\n\n\n**Extensions for Django REST Framework**\n\n\nInstallation\n------------\n\n``` {.bash}\n$ pip install drfexts\n```\n\nUsage\n-----\n\n*views.py*\n\n``` {.python}\nfrom rest_framework.views import APIView\nfrom rest_framework.settings import api_settings\nfrom drfexts.viewsets import ExportMixin\n\nclass MyView (ExportMixin, APIView):\n    ...\n```\n\nOrdered Fields\n--------------\n\nBy default, a `CSVRenderer` will output fields in sorted order. To\nspecify an alternative field ordering you can override the `header`\nattribute. There are two ways to do this:\n\n1)  Create a new renderer class and override the `header` attribute\n    directly:\n\n    > ``` {.python}\n    > class MyUserRenderer (CSVRenderer):\n    >     header = ['first', 'last', 'email']\n    >\n    > @api_view(['GET'])\n    > @renderer_classes((MyUserRenderer,))\n    > def my_view(request):\n    >     users = User.objects.filter(active=True)\n    >     content = [{'first': user.first_name,\n    >                 'last': user.last_name,\n    >                 'email': user.email}\n    >                for user in users]\n    >     return Response(content)\n    > ```\n\n2)  Use the `renderer_context` to override the field ordering on the\n    fly:\n\n    > ``` {.python}\n    > class MyView (APIView):\n    >     renderer_classes = [CSVRenderer]\n    >\n    >     def get_renderer_context(self):\n    >         context = super().get_renderer_context()\n    >         context['header'] = (\n    >             self.request.GET['fields'].split(',')\n    >             if 'fields' in self.request.GET else None)\n    >         return context\n    >\n    >     ...\n    > ```\n\nLabeled Fields\n--------------\n\nCustom labels can be applied to the `CSVRenderer` using the `labels`\ndict attribute where each key corresponds to the header and the value\ncorresponds to the custom label for that header.\n\n1\\) Create a new renderer class and override the `header` and `labels`\nattribute directly:\n\n> ``` {.python}\n> class MyBazRenderer (CSVRenderer):\n>     header = ['foo.bar']\n>     labels = {\n>         'foo.bar': 'baz'\n>     }\n> ```\n\n\nPagination\n----------\n\nUsing the renderer with paginated data is also possible with the new\n[PaginatedCSVRenderer]{.title-ref} class and should be used with views\nthat paginate data\n\nFor more information about using renderers with Django REST Framework,\nsee the [API\nGuide](http://django-rest-framework.org/api-guide/renderers/) or the\n[Tutorial](http://django-rest-framework.org/tutorial/1-serialization/).\n\n\nRunning the tests\n-----------------\n\nTo run the tests against the current environment:\n\n``` {.bash}\n$ ./manage.py test\n```\n\n### Changelog\n\n1.0.0\n-----\n\n\n-   Initial release\n\n## Thanks\n\n[![PyCharm](docs/pycharm.svg)](https://www.jetbrains.com/?from=drfexts)\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Django Restframework Utils",
    "version": "3.9.0",
    "project_urls": {
        "Homepage": "https://github.com/aiden520/drfexts",
        "Repository": "https://github.com/aiden520/drfexts"
    },
    "split_keywords": [
        "django",
        " restframework"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2822c6b9f9fb0f1f07613202dddbe42088cd7a9b593f458f787e184f19cd51b7",
                "md5": "d7d22f61ceefc6b14725ebe4daa004fd",
                "sha256": "d1af1c3504d69f68eb61c7be3edc94afecca72b9564592ec436730e9a16ef099"
            },
            "downloads": -1,
            "filename": "drfexts-3.9.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d7d22f61ceefc6b14725ebe4daa004fd",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0.0,>=3.10",
            "size": 47484,
            "upload_time": "2024-04-29T07:56:05",
            "upload_time_iso_8601": "2024-04-29T07:56:05.094916Z",
            "url": "https://files.pythonhosted.org/packages/28/22/c6b9f9fb0f1f07613202dddbe42088cd7a9b593f458f787e184f19cd51b7/drfexts-3.9.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8584ff91612e0c29de31c44d713a44f152b5c2bd7edb8fd521a023119627d9e0",
                "md5": "50994af8729dd86b5f04066125a1a6eb",
                "sha256": "b6ce2e214e6db6d612b96dab0fff1e42b2d028e3a56106061e59a700a4037708"
            },
            "downloads": -1,
            "filename": "drfexts-3.9.0.tar.gz",
            "has_sig": false,
            "md5_digest": "50994af8729dd86b5f04066125a1a6eb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0.0,>=3.10",
            "size": 36688,
            "upload_time": "2024-04-29T07:56:08",
            "upload_time_iso_8601": "2024-04-29T07:56:08.611091Z",
            "url": "https://files.pythonhosted.org/packages/85/84/ff91612e0c29de31c44d713a44f152b5c2bd7edb8fd521a023119627d9e0/drfexts-3.9.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-29 07:56:08",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "aiden520",
    "github_project": "drfexts",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "drfexts"
}
        
Elapsed time: 0.24953s