{ "info": { "author": "Martijn Faassen", "author_email": "faassen@startifact.com", "bugtrack_url": null, "classifiers": [], "description": "*******************\nz3c.relationfieldui \n*******************\n\nThis package implements a ``zope.formlib`` compatible widget for\nrelations as defined by `z3c.relationfield`_.\n\n.. _`z3c.relationfield`: http://pypi.python.org/pypi/z3c.relationfield\n\nThis package does not provide a ``z3c.form`` widget for\n``z3c.relationfield``, but it is hoped that will eventually be\ndeveloped as well (in another package).\n\nSetup\n=====\n\nIn order to demonstrate our widget, we need to first set up a relation\nfield (for the details of this see z3c.relationfield's\ndocumentation)::\n\n >>> from z3c.relationfield import Relation\n >>> from zope.interface import Interface\n >>> class IItem(Interface):\n ... rel = Relation(title=u\"Relation\")\n >>> from z3c.relationfield.interfaces import IHasRelations\n >>> from persistent import Persistent\n >>> from zope.interface import implements\n >>> class Item(Persistent):\n ... implements(IItem, IHasRelations)\n ... def __init__(self):\n ... self.rel = None\n >>> from zope.app.component.site import SiteManagerContainer\n >>> from zope.app.container.btree import BTreeContainer\n >>> class TestApp(SiteManagerContainer, BTreeContainer):\n ... pass\n\nSet up the application with the right utilities::\n\n >>> root = getRootFolder()['root'] = TestApp()\n >>> from zope.app.component.site import LocalSiteManager\n >>> root.setSiteManager(LocalSiteManager(root))\n >>> from zope.app.component.hooks import setSite\n >>> setSite(root)\n >>> from zope.app.intid import IntIds\n >>> from zope.app.intid.interfaces import IIntIds\n >>> root['intids'] = intids = IntIds() \n >>> sm = root.getSiteManager()\n >>> sm.registerUtility(intids, provided=IIntIds)\n >>> from z3c.relationfield import RelationCatalog\n >>> from zc.relation.interfaces import ICatalog\n >>> root['catalog'] = catalog = RelationCatalog()\n >>> sm.registerUtility(catalog, provided=ICatalog)\n\nItems ``a`` and ``b`` with a relation from ``b`` to ``a``::\n\n >>> root['a'] = Item()\n >>> from z3c.relationfield import RelationValue\n >>> b = Item()\n >>> from zope import component\n >>> from zope.app.intid.interfaces import IIntIds\n >>> intids = component.getUtility(IIntIds)\n >>> a_id = intids.getId(root['a'])\n >>> b.rel = RelationValue(a_id)\n >>> root['b'] = b\n\nWe also need to set up a utility that knows how to generate an object\npath for a given object, and back::\n\n >>> import grokcore.component as grok\n >>> from z3c.objpath.interfaces import IObjectPath\n >>> class ObjectPath(grok.GlobalUtility):\n ... grok.provides(IObjectPath)\n ... def path(self, obj):\n ... return obj.__name__\n ... def resolve(self, path):\n ... try:\n ... return root[path]\n ... except KeyError:\n ... raise ValueError(\"Cannot resolve: %s\" % path)\n >>> grok.testing.grok_component('ObjectPath', ObjectPath)\n True\n\nLet's also set up a broken relation::\n\n >>> d = root['d'] = Item()\n >>> d_id = intids.getId(root['d'])\n >>> c = Item()\n >>> c.rel = RelationValue(d_id)\n >>> root['c'] = c\n >>> del root['d']\n >>> root['c'].rel.to_object is None\n True\n >>> root['c'].rel.isBroken()\n True\n\nThe relation widget\n===================\n\nThe relation widget can be looked up for a relation field. The widget\nwill render with a button that can be used to set the\nrelation. Pressing this button will show a pop up window. The URL\nimplementing the popup window is defined on a special view that needs\nto be available on the context object (that the relation is defined\non). This view must be named \"explorerurl\". We'll provide one here::\n\n >>> from zope.interface import Interface\n >>> import grokcore.view\n >>> class ExplorerUrl(grokcore.view.View):\n ... grok.context(Interface)\n ... def render(self):\n ... return 'http://grok.zope.org'\n\nNow we can Grok the view::\n\n >>> grok.testing.grok_component('ExplorerUrl', ExplorerUrl)\n True\n\nLet's take a look at the relation widget now::\n\n >>> from zope.publisher.browser import TestRequest\n >>> from z3c.relationfieldui import RelationWidget\n >>> request = TestRequest()\n >>> field = IItem['rel']\n >>> bound = field.bind(root['b'])\n >>> widget = RelationWidget(bound, request)\n >>> widget.setRenderedValue(bound.get(root['b']))\n >>> print widget()\n \n\nLet's also try it with the broken relation::\n\n >>> bound = field.bind(root['c'])\n >>> widget = RelationWidget(bound, request)\n >>> widget.setRenderedValue(bound.get(root['c']))\n\nWhen we render the widget, the value is still correct (even though\nit's broken)::\n\n >>> print widget()\n \n\nRelation Choice\n===============\n\nLet's examine the ``RelationChoice`` field from ``z3c.relationfield``. We\nneed to provide a source of possible relations for it, and we can do this\nusing the ``RelationSourceFactory``::\n\n >>> from z3c.relationfieldui import RelationSourceFactory\n >>> class MyRelationSourceFactory(RelationSourceFactory):\n ... def getTargets(self):\n ... return [root['a'], root['b'], root['c']]\n\nIn the source, we simply return an iterable of objects that are\npossible relation targets.\n\nLet's now create an object that makes use of this source::\n\n >>> from z3c.relationfield import RelationChoice\n >>> class IItemChoice(Interface):\n ... rel = RelationChoice(title=u\"Relation\", required=False,\n ... source=MyRelationSourceFactory())\n\nWe can now take a look at the widget, using ``ChoiceInputWidget``::\n\n >>> from zope.app.form.browser import ChoiceInputWidget\n\n >>> class ItemChoice(Persistent):\n ... implements(IItemChoice, IHasRelations)\n ... def __init__(self):\n ... self.rel = None\n\n >>> root['choice_a'] = ItemChoice()\n >>> field = IItemChoice['rel']\n >>> bound = field.bind(root['choice_a'])\n >>> widget = ChoiceInputWidget(bound, request)\n\nLet's first render the widget without a particular rendered value set::\n\n >>> print widget()\n
\n
\n \n
\n \n
\n\nLet's try it again with a value set as a relation to ``a``::\n\n >>> choice_b = ItemChoice()\n >>> choice_b.rel = RelationValue(a_id)\n >>> root['choice_b'] = choice_b\n >>> bound = field.bind(root['choice_b'])\n >>> widget = ChoiceInputWidget(bound, request)\n >>> widget.setRenderedValue(bound.get(root['b']))\n\nWhen we look at the widget we see that this relation is indeed selected::\n\n >>> print widget()\n
\n
\n \n
\n \n
\n\nRelation display widget\n=======================\n\nThe display widget for relation will render a URL to the object it relates\nto. What this URL will be exactly can be controlled by defining a view\non the object called \"relationurl\". Without such a view, the display\nwidget will link directly to the object::\n\n >>> from z3c.relationfieldui import RelationDisplayWidget\n >>> bound = field.bind(root['b'])\n >>> widget = RelationDisplayWidget(bound, request)\n >>> widget.setRenderedValue(bound.get(root['b']))\n\nThe widget will point to the plain URL of ``rel``'s ``to_object``::\n\n >>> print widget()\n a\n\nNow we register a special ``relationurl`` view::\n\n >>> class RelationUrl(grokcore.view.View):\n ... grok.context(Interface)\n ... def render(self):\n ... return self.url('edit')\n >>> grok.testing.grok_component('RelationUrl', RelationUrl)\n True\n\nWe should now see a link postfixed with ``/edit``::\n\n >>> print widget()\n a\n\nWhen the relation is broken, it will still display, but as broken::\n\n >>> bound = field.bind(root['c'])\n >>> widget = RelationDisplayWidget(bound, request)\n >>> widget.setRenderedValue(bound.get(root['c']))\n >>> print widget()\n Broken relation to: d\n\nCHANGES\n*******\n\n0.5 (2009-02-10)\n================\n\n* Add support for ``RelationChoice`` field. To create a relation field that\n uses a drop-down list to select the relation target, implement a\n ``RelationSourceFactory`` (implement the ``getTargets`` method), and\n pass it as a source to ``RelationChoice``.\n\n0.4 (2009-01-20)\n================\n\n* Use improved ``z3c.relationfield`` to better handle broken\n relations. Broken relations are now accepted by the UI but will be\n stored as broken.\n\n0.3 (2009-01-16)\n================\n\n* Pass along ``from_attribute`` and ``from_path`` URL parameters to\n explorer_url.\n\n0.2 (2009-01-08)\n================\n\n* Update the value of the input field using ``.value`` instead of\n using ``setAttribute('value', ...)``. The latter did not update\n dynamically updated input fields, and the former does.\n\n* ``z3c.relationfield`` does not use ``IRelationInfo`` anymore and\n instead exposes ``create_relation``. Use this instead.\n\n0.1.1 (2008-12-10)\n==================\n\n* Small internet Explorer compatibility tweaks.\n\n0.1 (2008-12-05)\n================\n\n* Initial public release.\n\nDownload\n********", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "UNKNOWN", "keywords": "", "license": "UNKNOWN", "maintainer": null, "maintainer_email": null, "name": "z3c.relationfieldui", "package_url": "https://pypi.org/project/z3c.relationfieldui/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/z3c.relationfieldui/", "project_urls": { "Download": "UNKNOWN", "Homepage": "UNKNOWN" }, "release_url": "https://pypi.org/project/z3c.relationfieldui/0.5/", "requires_dist": null, "requires_python": null, "summary": "A widget for z3c.relationfield.", "version": "0.5" }, "last_serial": 802093, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "af67fba57d6e53ab6ad37eb2850e7989", "sha256": "3a80927dfbc0d4d6039a6098fb26d3b55f64a79bb8052e78790554ed85a0f298" }, "downloads": -1, "filename": "z3c.relationfieldui-0.1.tar.gz", "has_sig": false, "md5_digest": "af67fba57d6e53ab6ad37eb2850e7989", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6272, "upload_time": "2008-12-05T19:23:48", "url": "https://files.pythonhosted.org/packages/1d/04/c208ed8c576dc93fc537df6ef74c79f98fa0ef02ef067ef8d97b4d125fa3/z3c.relationfieldui-0.1.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "046dba5ad3e89340720094fa89a5bcc6", "sha256": "7dc94909226493c00db21c5b86acd37a672257541f8814a8b2432575fd7b7ff1" }, "downloads": -1, "filename": "z3c.relationfieldui-0.1.1.tar.gz", "has_sig": false, "md5_digest": "046dba5ad3e89340720094fa89a5bcc6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6323, "upload_time": "2008-12-10T18:35:20", "url": "https://files.pythonhosted.org/packages/a6/61/8bc16d0280a9c41880245a418f05b9e04ed45979a4c16a8da75d08f4baed/z3c.relationfieldui-0.1.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "01c88136b23934194c2b3347a45f6630", "sha256": "51296ca6384e054e15032bdc21ae0624e2101e98d0b71e3b9d057a95cfbae2b3" }, "downloads": -1, "filename": "z3c.relationfieldui-0.2.tar.gz", "has_sig": false, "md5_digest": "01c88136b23934194c2b3347a45f6630", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6600, "upload_time": "2009-01-08T18:55:55", "url": "https://files.pythonhosted.org/packages/e7/5b/aa0253d98cd4211489db5b7398b0dc52f5289a0a0b95bf8fe47239ee9757/z3c.relationfieldui-0.2.tar.gz" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "c27d54fd0110b5fa827c0efc7966f5c4", "sha256": "a3effee5d57d783b32a9f5ca1077e58881e22acc88fa0b0b24c85f6d4f44b80e" }, "downloads": -1, "filename": "z3c.relationfieldui-0.3.tar.gz", "has_sig": false, "md5_digest": "c27d54fd0110b5fa827c0efc7966f5c4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6818, "upload_time": "2009-01-16T16:41:33", "url": "https://files.pythonhosted.org/packages/56/a1/9e550888fc4b0954968da5272c6e8f620583b1020b1c9f16a6828d570693/z3c.relationfieldui-0.3.tar.gz" } ], "0.4": [ { "comment_text": "", "digests": { "md5": "e15d7833fc4424e798ba2c9672927f34", "sha256": "23e7fa4ea564a3ff66b80fee87ab8e38ba792f87081d0d7ea65513599f407adf" }, "downloads": -1, "filename": "z3c.relationfieldui-0.4.tar.gz", "has_sig": false, "md5_digest": "e15d7833fc4424e798ba2c9672927f34", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7158, "upload_time": "2009-01-20T21:19:20", "url": "https://files.pythonhosted.org/packages/7f/bb/976db27bdd1220d5b1e9116f8a281d8f2fd7cbdfa4310e57c5ba2ca4b63f/z3c.relationfieldui-0.4.tar.gz" } ], "0.5": [ { "comment_text": "", "digests": { "md5": "cb9968efa2ae1596fb06dc3cb32f9f03", "sha256": "6bd86d34c6832cf7fd97f526d62e3fa38470cdbcee5a296504cb051b40e73619" }, "downloads": -1, "filename": "z3c.relationfieldui-0.5.tar.gz", "has_sig": false, "md5_digest": "cb9968efa2ae1596fb06dc3cb32f9f03", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9754, "upload_time": "2009-02-10T20:53:23", "url": "https://files.pythonhosted.org/packages/9f/31/e51755c6b8de0786bb825b2cd50e35db9f941427b623a10fab485a1def9d/z3c.relationfieldui-0.5.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "cb9968efa2ae1596fb06dc3cb32f9f03", "sha256": "6bd86d34c6832cf7fd97f526d62e3fa38470cdbcee5a296504cb051b40e73619" }, "downloads": -1, "filename": "z3c.relationfieldui-0.5.tar.gz", "has_sig": false, "md5_digest": "cb9968efa2ae1596fb06dc3cb32f9f03", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9754, "upload_time": "2009-02-10T20:53:23", "url": "https://files.pythonhosted.org/packages/9f/31/e51755c6b8de0786bb825b2cd50e35db9f941427b623a10fab485a1def9d/z3c.relationfieldui-0.5.tar.gz" } ] }