{ "info": { "author": "4teamwork AG", "author_email": "mailto:info@4teamwork.ch", "bugtrack_url": null, "classifiers": [ "Environment :: Web Environment", "Framework :: Plone", "Framework :: Plone :: 4.3", "Intended Audience :: Developers", "License :: OSI Approved :: GNU General Public License (GPL)", "Programming Language :: Python", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "``ftw.jsondump`` provides JSON representations for Plone objects.\nBy using adapters the JSON representation can easily be customized.\n\n.. contents:: Table of Contents\n\n\nInstallation\n============\n\nAdd the package as dependency to your setup.py:\n\n.. code:: python\n\n setup(...\n install_requires=[\n ...\n 'ftw.jsondump',\n ])\n\nor to your buildout configuration:\n\n.. code:: ini\n\n [instance]\n eggs += ftw.jsondump\n\nand rerun buildout.\n\n\nUsage\n=====\n\nFor extracting the JSON of an object, use the ``IJSONRepresentation`` adapter:\n\n.. code:: python\n\n from ftw.jsondump.interfaces import IJSONRepresentation\n from zope.component import getMultiAdapter\n\n json_representation = getMultiAdapter((context, request), IJSONRepresentation)\n print json_representation.json()\n\n\nPartials\n--------\n\nThe JSON is built using \"partials\", which are merged into one ``dict``.\n\nThere are various default partials:\n\n- ``metadata`` partial, providing infos such as ``_type`` and ``_class``\n- ``fields`` partial extracting Archetypes and Dexterity field data\n- ``uid`` partial, providing the UID in ``_uid``\n- ``localroles`` partial, extracting the local roles\n- ``workflow`` partial, providing the ``_workflow_chain`` and the ``_workflow_history``\n- ``properties`` partial, providing local properties in ``_properties``\n- ``interfaces`` partial, extracting the directly provided interfaces in ``_directly_provided``\n\n**Selecting partials**\n\nThe desired partials can be selected when extracting the JSON:\n\n.. code:: python\n\n from ftw.jsondump.interfaces import IJSONRepresentation\n from zope.component import getMultiAdapter\n\n json_representation = getMultiAdapter((context, request), IJSONRepresentation)\n print json_representation.json(only=['fields', 'metadata'])\n print json_representation.json(exclude=['localroles'])\n\n\n**File blob data**\nThe file data is extracted by default as base64 encoded string and embedded in the\nJSON document.\n\nThis fieldata can be excluded with the ``filedata`` configuration:\n\n.. code:: python\n\n from ftw.jsondump.interfaces import IJSONRepresentation\n from zope.component import getMultiAdapter\n\n json_representation = getMultiAdapter((context, request), IJSONRepresentation)\n print json_representation.json(filedata=False)\n\nFor doing custom things with the filedata, a callback can be used:\n\n.. code:: python\n\n from ftw.jsondump.interfaces import IJSONRepresentation\n from zope.component import getMultiAdapter\n\n def file_callback(context, key, fieldname, data, filename, mimetype, jsondata):\n with open('./tmp/' + filename, 'w+b') as target:\n target.write(data)\n\n json_representation = getMultiAdapter((context, request), IJSONRepresentation)\n print json_representation.json(file_callback=file_callback)\n\n\nCreating custom partials\n------------------------\n\nCustom partials can easily be registered as adapter:\n\n*configure.zcml:*\n\n.. code:: xml\n\n \n\n\n*partial.py:*\n\n.. code:: python\n\n from ftw.jsondump.interfaces import IPartial\n from my.package.interfaces import ICustomContent\n from zope.annotation import IAnnotations\n from zope.component import adapts\n from zope.interface import Interface\n from zope.interface import implements\n\n class CustomAnnotations(object):\n implements(IPartial)\n adapts(ICustomContent, Interface)\n\n\n def __init__(self, context, request):\n self.context = context\n self.request = request\n\n def __call__(self, config):\n annotations = IAnnotations(self.context)\n return {'_custom_annotations': dict(annotations.get('custom_config'))}\n\n\nField data extractors\n---------------------\n\nThe Archetypes and Dexterity partial use field data extractor adapters for extracting\nthe field data and converting it to a JSON serializable value.\n\nCustom extractors can easily be registered for custom fields:\n\n*configure.zcml:*\n\n.. code:: xml\n\n \n\n*extractor.py:*\n\n.. code:: python\n\n from ftw.jsondump.interfaces import IFieldExtractor\n from my.package import ICustomField\n from zope.component import adapts\n from zope.interface import implements\n from zope.interface import Interface\n\n\n class CustomFieldExtractor(object):\n implements(IFieldExtractor)\n adapts(Interface, Interface, ICustomField)\n\n def __init__(self, context, request, field):\n self.context = context\n self.request = request\n self.field = field\n\n def extract(self, name, data, config):\n value = self.field.get(self.context)\n value = value.prepare_for_serialization()\n data.update({name: value})\n\n\nLinks\n=====\n\n- Github: https://github.com/4teamwork/ftw.jsondump\n- Issues: https://github.com/4teamwork/ftw.jsondump/issues\n- Pypi: http://pypi.python.org/pypi/ftw.jsondump\n- Continuous integration: https://jenkins.4teamwork.ch/search?q=ftw.jsondump\n\nCopyright\n=========\n\nThis package is copyright by `4teamwork `_.\n\n``ftw.jsondump`` is licensed under GNU General Public License, version 2.\n\nChangelog\n=========\n\n1.1.0 (2015-10-11)\n------------------\n\n- Change file_callback signature to also include the key used in the dict.\n For dexterity content, the key is different than the fieldname because it\n is prefixed with the interface dottedname.\n\n - Old: ``file_callback(context, fieldname, data, filename, mimetype, jsondata)``\n - New: ``file_callback(context, key, fieldname, data, filename, mimetype, jsondata)``\n\n [jone]\n\n- Dexterity: support exporting RichTextValue objects.\n [jone]\n\n\n1.0.0 (2015-05-05)\n------------------\n\n- Initial implementation\n [maethu, jone]", "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/4teamwork/ftw.jsondump", "keywords": "ftw json representation serialize dump", "license": "GPL2", "maintainer": null, "maintainer_email": null, "name": "ftw.jsondump", "package_url": "https://pypi.org/project/ftw.jsondump/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/ftw.jsondump/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/4teamwork/ftw.jsondump" }, "release_url": "https://pypi.org/project/ftw.jsondump/1.1.0/", "requires_dist": null, "requires_python": null, "summary": "JSON representation for plone content", "version": "1.1.0" }, "last_serial": 5823568, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "b5f8a2436dde9d5ee0cc274084ca472d", "sha256": "a8a47a901585094166ea732fc966023b1a4b3fc7e2e36e0d7efaa2c20645aafc" }, "downloads": -1, "filename": "ftw.jsondump-1.0.0.zip", "has_sig": false, "md5_digest": "b5f8a2436dde9d5ee0cc274084ca472d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 46243, "upload_time": "2015-05-05T11:56:07", "url": "https://files.pythonhosted.org/packages/8a/83/9ac436089430f418e724e8f9da23f22c2a00286efbd54db08ff2ff9d9685/ftw.jsondump-1.0.0.zip" } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "b56976b804364098f2c11fd4f6f298ca", "sha256": "9b66c3a98752620e8d9790c5a55d453eaa2b1f7c7f3150d3767b4e57017939fa" }, "downloads": -1, "filename": "ftw.jsondump-1.1.0.tar.gz", "has_sig": false, "md5_digest": "b56976b804364098f2c11fd4f6f298ca", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 24361, "upload_time": "2015-10-11T12:37:00", "url": "https://files.pythonhosted.org/packages/05/4b/a38f4f4d5eb9fcb88146338d0fd1b35168b64aba0ac53bf392f0d308c4b4/ftw.jsondump-1.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "b56976b804364098f2c11fd4f6f298ca", "sha256": "9b66c3a98752620e8d9790c5a55d453eaa2b1f7c7f3150d3767b4e57017939fa" }, "downloads": -1, "filename": "ftw.jsondump-1.1.0.tar.gz", "has_sig": false, "md5_digest": "b56976b804364098f2c11fd4f6f298ca", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 24361, "upload_time": "2015-10-11T12:37:00", "url": "https://files.pythonhosted.org/packages/05/4b/a38f4f4d5eb9fcb88146338d0fd1b35168b64aba0ac53bf392f0d308c4b4/ftw.jsondump-1.1.0.tar.gz" } ] }