{"id":20609523,"url":"https://github.com/wccdev/drfexts","last_synced_at":"2025-04-15T04:31:07.747Z","repository":{"id":37299374,"uuid":"277761781","full_name":"wccdev/drfexts","owner":"wccdev","description":"extensions for django drf restframework","archived":false,"fork":false,"pushed_at":"2024-11-16T09:44:37.000Z","size":463,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-04-10T10:03:13.883Z","etag":null,"topics":["django-rest-framework","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wccdev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-07T08:33:55.000Z","updated_at":"2024-09-19T09:35:49.000Z","dependencies_parsed_at":"2024-06-11T07:31:40.564Z","dependency_job_id":"be2c5cf6-0964-4ce7-8dee-16101472a954","html_url":"https://github.com/wccdev/drfexts","commit_stats":{"total_commits":105,"total_committers":4,"mean_commits":26.25,"dds":0.1428571428571429,"last_synced_commit":"3289d25478474b84a534b5d83940d3d6314097e8"},"previous_names":["aiden520/drfexts"],"tags_count":126,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wccdev%2Fdrfexts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wccdev%2Fdrfexts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wccdev%2Fdrfexts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wccdev%2Fdrfexts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wccdev","download_url":"https://codeload.github.com/wccdev/drfexts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249006384,"owners_count":21197263,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django-rest-framework","python"],"created_at":"2024-11-16T10:13:49.161Z","updated_at":"2025-04-15T04:31:07.730Z","avatar_url":"https://github.com/wccdev.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"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[![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json)](https://python-poetry.org/)\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    \u003e ``` {.python}\n    \u003e class MyUserRenderer (CSVRenderer):\n    \u003e     header = ['first', 'last', 'email']\n    \u003e\n    \u003e @api_view(['GET'])\n    \u003e @renderer_classes((MyUserRenderer,))\n    \u003e def my_view(request):\n    \u003e     users = User.objects.filter(active=True)\n    \u003e     content = [{'first': user.first_name,\n    \u003e                 'last': user.last_name,\n    \u003e                 'email': user.email}\n    \u003e                for user in users]\n    \u003e     return Response(content)\n    \u003e ```\n\n2)  Use the `renderer_context` to override the field ordering on the\n    fly:\n\n    \u003e ``` {.python}\n    \u003e class MyView (APIView):\n    \u003e     renderer_classes = [CSVRenderer]\n    \u003e\n    \u003e     def get_renderer_context(self):\n    \u003e         context = super().get_renderer_context()\n    \u003e         context['header'] = (\n    \u003e             self.request.GET['fields'].split(',')\n    \u003e             if 'fields' in self.request.GET else None)\n    \u003e         return context\n    \u003e\n    \u003e     ...\n    \u003e ```\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\u003e ``` {.python}\n\u003e class MyBazRenderer (CSVRenderer):\n\u003e     header = ['foo.bar']\n\u003e     labels = {\n\u003e         'foo.bar': 'baz'\n\u003e     }\n\u003e ```\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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwccdev%2Fdrfexts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwccdev%2Fdrfexts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwccdev%2Fdrfexts/lists"}