{ "info": { "author": "Fusionbox, Inc.", "author_email": "programmers@fusionbox.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Programming Language :: Python", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.2", "Programming Language :: Python :: 3.3", "Topic :: Internet :: WWW/HTTP" ], "description": "django-separated\n================\n\n.. image:: https://api.travis-ci.org/fusionbox/django-separated.png\n :alt: Building Status\n :target: https://travis-ci.org/fusionbox/django-separated\n\nClass-based view and mixins for responding with CSV in Django. django-separated\nsupports Django 1.3+.\n\n\nInstallation\n------------\n\n::\n\n $ pip install django-separated\n\n\nDocumentation\n-------------\n\ndjango-separated provides many tools for generating CSV files based on\nquerysets.\n\nSerializer\n``````````\n\nseparated.utils.ColumnSerializer\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nYou can use the ColumnSerializer to generate CSV. It accepts a column\ndefinition, and returns a callable that you can use to serialize to CSV. ::\n\n from separated.utils import ColumnSerializer\n\n serialize_books = ColumnSerializer([\n ('title', 'Title'),\n ('pub_date', 'Publication Date'),\n ('isbn', 'ISBN'),\n ])\n with open('/tmp/books.csv', 'wb') as f:\n books = Book.objects.all()\n serialize_books(books, file=f)\n\nThe column definition is an iterable of 2-tuples where the first item is an\naccessor to get the value off of an object and the second item is the column\nheader.\n\nThe accessor can be a string or a callable. If it isn't a callable, it\nwill be passed into attrgetter to turn into a callable. If the accessor\nreturns a callable, it will be called. All of the following are valid\nexamples of accessors:\n\n- ``'first_name'``\n- ``'first_name.upper'``\n- ``'get_absolute_url'``\n- ``lambda x: x.upvotes.count() - x.downvotes.count()``\n\nYou can even stretch across relationships:\n\n- ``'author'``\n- ``'author.name'``\n- ``'author.book_count'``\n- ``'author.user.username'``\n\nThe header value is optional, if you want a header to be generated from the\naccessor, you can write a simpler ``columns`` definition::\n\n serialize_books = ColumnSerializer([\n 'title', # Header will be 'Title'\n 'pub_date', # Header will be 'Pub date'\n ])\n\nYou can mix and match the two styles as well.\n\nBy default, ``ColumnSerializer`` will output the headers as the first line. If\nyou want to suppress this behavior, set ``output_headers`` to ``False``.\n\nViews\n`````\n\nseparated.views.CsvView\n~~~~~~~~~~~~~~~~~~~~~~~\n\nA ListView that returns will present the user with a CSV file download. It\nrequires a column definition that will be passed to the ``ColumnSerializer`` ::\n\n class UserCsvView(CsvView):\n model = User\n columns = [\n ('first_name', 'First name'),\n ('last_name', 'Last name'),\n ('email', 'Email'),\n ]\n\nThere is a corresponding ``get_columns`` method if you need to have\nmore dynamic behavior.\n\nAdditionally, you can specify the filename of the CSV file that will be\ndownloaded. It will default to the model name + ``_list.csv`` if you don't\nprovide one. For example::\n\n class UserCsvView(CsvView):\n model = User\n\nwill have a filename of ``user_list.csv``. But you can override it by\nsettings the ``filename`` attribute. There is a corresponding\n``get_filename`` that you can override for more complicated behavior.\n\nCsvView will forward the value of ``output_headers`` to the\n``ColumnSerializer``. To turn off the headers, you can do this::\n\n class UserCsvView(CsvView):\n model = False\n output_headers = False\n\nseparated.views.CsvResponseMixin\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nA MultipleObjectMixin subclass that returns a ``CsvResponse``.\n\nThis is useful in instances where you want to substitute BaseListView for a\nListView of your own. ``CsvResponseMixin`` supports all the behavior\nmentioned in ``CsvView``, the only machinery you need to hook it up is a\nView class that calls ``render_to_response`` with a context that has a\nqueryset available in the ``object_list`` key. ::\n\n class MyWeirdBaseListView(View):\n def get(self, request, *args, **kwargs):\n return self.render_to_response({\n 'object_list': User.objects.all(),\n })\n\n class MyWeirdCsvView(CsvResponseMixin, MyWeirdBaseListView):\n pass\n\nseparated.views.CsvResponse\n~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nA subclass of HttpResponse that will download as CSV. ``CsvResponse``\nrequires a ``filename`` as the first argument of the constructor.\n\n\nAdmin\n`````\n\nYou can use django-separated in the admin center to export CSV from the admin\nsite. ::\n\n from separated.admin import CsvExportModelAdmin\n\n class NewsAdmin(CsvExportModelAdmin):\n csv_export_columns = [\n 'title',\n 'pub_date',\n 'author.full_name',\n ]\n\nThis adds an action to the change list.\n\n``csv_export_columns`` corresponds to the ``CsvView.columns`` attribute. If\nyou want more fine-grained control, you can override ``csv_export_view_class``\ninstead::\n\n from datetime import datetime\n\n from separated.admin import CsvExportModelAdmin\n from separated.views import CsvView\n\n class NewsCsvView(CsvView):\n columns = [\n 'title',\n 'pub_date',\n 'author.full_name',\n ]\n output_headers = False\n\n def get_filename(self, model):\n return '%s-news-export.csv' % datetime.today().strftime('Y-m-d')\n\n class NewsAdmin(CsvExportModelAdmin):\n csv_export_view_class = NewsCsvView\n\n``csv_export_columns`` and ``csv_export_view_class`` also exist as methods\n(``get_csv_export_columns`` and ``get_csv_export_view_class`` respectively) if\nyou need change them based on request. ::\n\n\n from separated.admin import CsvExportModelAdmin\n\n class NewsAdmin(CsvExportModelAdmin):\n staff_export_columns = (\n 'title',\n 'pub_date',\n 'author.full_name',\n )\n\n superuser_export_columns = staff_export_columns + (\n 'secret_column',\n )\n\n def get_csv_export_columns(self, request):\n if request.user.is_superuser:\n return self.superuser_export_columns\n else:\n return self.staff_export_columns\n\n\nGetters\n```````\ndjango-separated provides a couple of helpers for normalizing the data that\ncomes off of the model before sending it to the CSV writer. These are all\nbased on a ``Getter`` class which handles the different types of accessors.\n\n\nseparated.utils.BooleanGetter\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nIf you have a boolean value that you wish to be transformed into ``Yes`` or\n``No``, you can use the ``BooleanGetter``::\n\n from separated.utils import BooleanGetter\n\n user_serializer = ColumnSerializer([\n BooleanGetter('is_admin'),\n ])\n\nseparated.utils.DisplayGetter\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nIf you have a model field that has choices and you want the human readable\ndisplay to appear in the CSV, you can use the ``DisplayGetter``::\n\n from separated.utils import BooleanGetter\n\n class User(models.Model):\n favorite_color = models.CharField(max_length=255,\n choices=(\n ('blue', 'Blue'),\n ('green', 'Green'),\n ('red', 'Red'),\n ))\n\n user_serializer = ColumnSerializer([\n DisplayGetter('favorite_color'),\n ])\n\nThis will end up using the ``get_favorite_color_display`` method that Django\nautomatically adds.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/fusionbox/django-separated", "keywords": "django csv class-based views", "license": "UNKNOWN", "maintainer": null, "maintainer_email": null, "name": "django-separated", "package_url": "https://pypi.org/project/django-separated/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-separated/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/fusionbox/django-separated" }, "release_url": "https://pypi.org/project/django-separated/1.1.0/", "requires_dist": null, "requires_python": null, "summary": "Class-based view and mixins for handling CSV with Django.", "version": "1.1.0" }, "last_serial": 2066231, "releases": { "0.9.0": [ { "comment_text": "", "digests": { "md5": "e445d8175c24d46da2d8fd72e29aa6ad", "sha256": "045265d669c903790005b0e86bed7c1e951585f10bbed22faf03cfc74456f705" }, "downloads": -1, "filename": "django-separated-0.9.0.tar.gz", "has_sig": false, "md5_digest": "e445d8175c24d46da2d8fd72e29aa6ad", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7122, "upload_time": "2013-08-14T19:45:35", "url": "https://files.pythonhosted.org/packages/8e/75/970ce5f1781e2c42acb8fcd8874d262b92e5a33dbf86e218d88721fab5ae/django-separated-0.9.0.tar.gz" } ], "1.0.0": [ { "comment_text": "", "digests": { "md5": "9ba8621bb629eb43d72dffdb9e35f3a3", "sha256": "32158626db372b40b605f1f812ea9e40af29dd36fcacd22997667e3e72a3983e" }, "downloads": -1, "filename": "django-separated-1.0.0.tar.gz", "has_sig": false, "md5_digest": "9ba8621bb629eb43d72dffdb9e35f3a3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8340, "upload_time": "2014-01-03T05:02:55", "url": "https://files.pythonhosted.org/packages/5a/12/acba2cc3a7c23f0f0cbf75d5f00e6dbf9ec788d88dba2d39bcd441b0e8f2/django-separated-1.0.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "d3cb77f422f3382c18cea82c46d099c0", "sha256": "70c8dc19b2f6fd81627ee4ca6e177d2afebfe407fd9197724d1f9784c34d9eab" }, "downloads": -1, "filename": "django-separated-1.0.1.tar.gz", "has_sig": false, "md5_digest": "d3cb77f422f3382c18cea82c46d099c0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8518, "upload_time": "2014-01-03T05:53:21", "url": "https://files.pythonhosted.org/packages/81/a6/a33851c26f3f2b4e5aeedffea92cdcb06dcc067b3040a3622ae5dc43200d/django-separated-1.0.1.tar.gz" } ], "1.0.2": [], "1.0.2a0": [ { "comment_text": "", "digests": { "md5": "d18692098eadfaa42970e7f990c27221", "sha256": "395c64baae98b12256a20921be2469a5da2993779039520f54a8d8afc4618259" }, "downloads": -1, "filename": "django-separated-1.0.2a0.tar.gz", "has_sig": false, "md5_digest": "d18692098eadfaa42970e7f990c27221", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10568, "upload_time": "2015-10-09T20:07:30", "url": "https://files.pythonhosted.org/packages/56/49/a0e630b773d3243bfccbdea3b7c14082b9004fe0de91ff61e38ded8c2501/django-separated-1.0.2a0.tar.gz" } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "1b6cbf90b9d505bb619e32a63d67659b", "sha256": "98d2d46067119c41e6694911654b12943b27c0a3688cb99552d78f0205eb492c" }, "downloads": -1, "filename": "django_separated-1.1.0-py2-none-any.whl", "has_sig": false, "md5_digest": "1b6cbf90b9d505bb619e32a63d67659b", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 12690, "upload_time": "2016-04-15T20:29:01", "url": "https://files.pythonhosted.org/packages/34/45/e774116dca335087cc08a96c6817e972343bd698cc1224526e1b977479fc/django_separated-1.1.0-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "9e0b8ccbd8752f7b3bd1d1e4d62c7950", "sha256": "d923ba0a961ec37163e3f250beb564fef9149c9059f6a7080666ef07ae13adf2" }, "downloads": -1, "filename": "django-separated-1.1.0.tar.gz", "has_sig": false, "md5_digest": "9e0b8ccbd8752f7b3bd1d1e4d62c7950", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11558, "upload_time": "2016-04-15T20:28:56", "url": "https://files.pythonhosted.org/packages/68/a5/12875a61158a88c40de31e41d2c79fd6a8ff5d9dbdb39d3ac93d9de6552a/django-separated-1.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "1b6cbf90b9d505bb619e32a63d67659b", "sha256": "98d2d46067119c41e6694911654b12943b27c0a3688cb99552d78f0205eb492c" }, "downloads": -1, "filename": "django_separated-1.1.0-py2-none-any.whl", "has_sig": false, "md5_digest": "1b6cbf90b9d505bb619e32a63d67659b", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 12690, "upload_time": "2016-04-15T20:29:01", "url": "https://files.pythonhosted.org/packages/34/45/e774116dca335087cc08a96c6817e972343bd698cc1224526e1b977479fc/django_separated-1.1.0-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "9e0b8ccbd8752f7b3bd1d1e4d62c7950", "sha256": "d923ba0a961ec37163e3f250beb564fef9149c9059f6a7080666ef07ae13adf2" }, "downloads": -1, "filename": "django-separated-1.1.0.tar.gz", "has_sig": false, "md5_digest": "9e0b8ccbd8752f7b3bd1d1e4d62c7950", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11558, "upload_time": "2016-04-15T20:28:56", "url": "https://files.pythonhosted.org/packages/68/a5/12875a61158a88c40de31e41d2c79fd6a8ff5d9dbdb39d3ac93d9de6552a/django-separated-1.1.0.tar.gz" } ] }