{ "info": { "author": "Souheil Chelfouh", "author_email": "trollfot@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Web Environment", "Framework :: Zope3", "Intended Audience :: Other Audience", "License :: OSI Approved :: GNU General Public License (GPL)", "Operating System :: OS Independent", "Programming Language :: Python" ], "description": "================\ndolmen.relations\n================\n\n`dolmen.relations` is a thin layer above `zc.relation`, allowing a\nsimple and straightforward implementation of standalone relationships\nbetween objects.\n\nGetting started\n===============\n\nIn order to demonstrate the package's features, we first set up a sane\nenvironment::\n\n >>> from zope import component\n >>> from zope.container.btree import BTreeContainer\n\n >>> sm = component.getGlobalSiteManager()\n >>> herd = getRootFolder()['herd'] = BTreeContainer()\n\n\nRelations catalog\n-----------------\n\n`dolmen.relations` provides a component called `RelationCatalog` that\nis in charge of registering the relations and finding them::\n\n >>> from dolmen.relations import RelationCatalog, ICatalog\n >>> sm.registerUtility(RelationCatalog(), ICatalog)\n\n\nRelations container\n-------------------\n\nTo store the relations and trigger the needed events,\n`dolmen.relations` provides a btree container::\n \n >>> from dolmen.relations import RelationsContainer\n >>> relations = herd['_relations'] = RelationsContainer()\n\n\nContent\n-------\n\nNow, we need some content to get started. The tests module defines a\nMammoth persistent object that we are going to use here::\n\n >>> from dolmen.relations.tests import Mammoth\n \n >>> manfred = herd['manfred'] = Mammoth()\n >>> gunther = herd['gunther'] = Mammoth()\n\nTo be sure that our objects will be persisted and will be\ngranted an int id, we commit::\n\n >>> import transaction\n >>> transaction.commit()\n\n\nRelations\n=========\n\nThe relations proposed by `dolmen.relations` are of the \"A to B\"\ntype. They allow you to link a source object with a target object. For\ntests purposes, we are going to create two Mammoth objects that are\ngoing to be used as source and target::\n\n >>> from dolmen.relations import values, any\n >>> from zope.intid.interfaces import IIntIds\n >>> ids = component.getUtility(IIntIds)\n >>> rcatalog = component.getUtility(ICatalog)\n\n >>> gunther_id = ids.getId(gunther)\n >>> manfred_id = ids.getId(manfred)\n\n\nSimple relation\n---------------\n\nThe first and simpliest relation type is the `RelationValue`. This\nrelation is created with a source id and target id::\n\n >>> relations[\"simple\"] = values.RelationValue(gunther_id, manfred_id)\n \nYou can query the relations by giving the target and/or source id::\n\n >>> found = list(rcatalog.findRelations({'target_id': manfred_id}))\n >>> found\n []\n\nThe relation has attributes dedicated to resolving the source or\ntarget::\n\n >>> relation = found.pop()\n >>> relation\n \n >>> relation.source\n \n >>> relation.target\n \n\n\nTagged relation\n---------------\n\nThe second type of relation is the `TaggedRelationValue`. It allows us to\nadd to the a source-target couple, a list of tags as a list of\nunicode strings::\n\n >>> relations[\"tagged\"] = values.TaggedRelationValue(\n ... gunther_id, manfred_id, tags=[u'grok', u'dolmen'])\n\nThe relation can still be retrieved with a basic query::\n\n >>> found = list(rcatalog.findRelations({'target_id': manfred_id}))\n >>> found\n [, ]\n\nIt can also, now, be queried using a tag value::\n\n >>> found = list(rcatalog.findRelations({'tag': any('grok')}))\n >>> found\n []\n\n >>> found = list(rcatalog.findRelations({'tag': any('drupal')}))\n >>> found\n []\n\n\nStateful relation\n-----------------\n\nThe third type of relation is the `StatefulRelationValue`. It adds, to\nthe source-target couple, state information as a unicode string::\n\n >>> relations[\"stateful\"] = values.StatefulRelationValue(\n ... gunther_id, manfred_id, state=u\"private\")\n\nThe relation can still be retrieved with a basic query::\n\n >>> found = list(rcatalog.findRelations({'target_id': manfred_id}))\n >>> found\n [, , ]\n\nIt can also, now, be queried using the state string::\n\n >>> found = list(rcatalog.findRelations({'state': any('private')}))\n >>> found\n []\n\n >>> found = list(rcatalog.findRelations({'state': any('public')}))\n >>> found\n []\n\n\nEvents\n======\n\nWhenever an object is deleted, the relations using it as source or\ntarget are deleted also::\n\n >>> del herd['manfred']\n >>> print list(herd['_relations'].keys())\n []\n >>> found = list(rcatalog.findRelations({'target_id': manfred_id}))\n >>> found\n []\n\n\nChangelog\n=========\n\n0.5 (2011-11-08)\n----------------\n\n* Catch an error from the intids when the ID have been removed. Return\n None in this case.\n\n0.4 (2010-03-15)\n----------------\n\n* Add event when relation are deleted because a component of them has been\n deleted.\n* Fix an error when you del container[reference_id] in a relation container\n of an inexisting relation (you should only get a KeyError).\n\n0.3 (2010-03-10)\n----------------\n\n* Correct zip-safe flag on package.\n* Fix potential NotYet errors by using register instead of getId IntIds method.\n* Fix event when you don't have a relation catalog available.\n\n0.2 (2009-12-26)\n----------------\n\n* ZTK compatibility imports change.\n\n\n0.1 (2009-10-20)\n----------------\n\n* Initial release", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://gitweb.dolmen-project.org", "keywords": "Grok Zope3 CMS Dolmen Relations", "license": "GPL", "maintainer": null, "maintainer_email": null, "name": "dolmen.relations", "package_url": "https://pypi.org/project/dolmen.relations/", "platform": "Any", "project_url": "https://pypi.org/project/dolmen.relations/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://gitweb.dolmen-project.org" }, "release_url": "https://pypi.org/project/dolmen.relations/0.5/", "requires_dist": null, "requires_python": null, "summary": "Dolmen relations", "version": "0.5" }, "last_serial": 791337, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "6464c0aa8bb26847b6b1f21ce0f85547", "sha256": "e695f7773530a22fe0164429d563c288a23bd800519d955f776b1c868cfb786b" }, "downloads": -1, "filename": "dolmen.relations-0.1.tar.gz", "has_sig": false, "md5_digest": "6464c0aa8bb26847b6b1f21ce0f85547", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7735, "upload_time": "2009-10-20T18:10:52", "url": "https://files.pythonhosted.org/packages/59/80/a003ca06ec08deef361241d25913aad5e04e2ab927f8a184183e4fe266d8/dolmen.relations-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "f79122ac885c5723fdb103f643c331d5", "sha256": "d389104476423be98b9386192fcc3434cc0300f772536fd2166270aa7778d1b3" }, "downloads": -1, "filename": "dolmen.relations-0.2.tar.gz", "has_sig": false, "md5_digest": "f79122ac885c5723fdb103f643c331d5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6982, "upload_time": "2009-12-26T19:12:04", "url": "https://files.pythonhosted.org/packages/cc/ab/6e26dc894189fb4898810a9be541fc8545f56102acd0a9e6a6d9bc13ffa4/dolmen.relations-0.2.tar.gz" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "fb9a648b653354cf9b74f5abfbb90461", "sha256": "8f93a2fa79acb6d0dcae0b94260a0f7ee7e04057b9745a8318d33783b93d0ae5" }, "downloads": -1, "filename": "dolmen.relations-0.3.tar.gz", "has_sig": false, "md5_digest": "fb9a648b653354cf9b74f5abfbb90461", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7157, "upload_time": "2010-03-10T11:40:06", "url": "https://files.pythonhosted.org/packages/8a/16/959f2050f56f38e34960fd5fd05f038c9958c49868c3ff2a78ebc2847038/dolmen.relations-0.3.tar.gz" } ], "0.4": [ { "comment_text": "", "digests": { "md5": "0fcaba5074cff40416dfaf998c9fd58a", "sha256": "99746c1deabfcfe3d7e0e63057bcbbc00e3065f3bb0cd51b96b6b268d30e18eb" }, "downloads": -1, "filename": "dolmen.relations-0.4.tar.gz", "has_sig": false, "md5_digest": "0fcaba5074cff40416dfaf998c9fd58a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7695, "upload_time": "2010-03-15T17:29:01", "url": "https://files.pythonhosted.org/packages/38/a2/eb012dcb33ed15e3f4360f7b5e1d03c070a9b74b48be38d9a3ef59b36dc3/dolmen.relations-0.4.tar.gz" } ], "0.5": [ { "comment_text": "", "digests": { "md5": "60ef4dd740b7d1bf2c74894eb3891eea", "sha256": "0db01c59cd9806e143c883b38701dcd4084154f5b353df9ea23a1092103c8d3c" }, "downloads": -1, "filename": "dolmen.relations-0.5.tar.gz", "has_sig": false, "md5_digest": "60ef4dd740b7d1bf2c74894eb3891eea", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7938, "upload_time": "2011-11-08T14:52:48", "url": "https://files.pythonhosted.org/packages/0e/0f/f07b18917fe8dc1ae08a5ce0e832ad7177113dc4d9797053fe34a35c1c15/dolmen.relations-0.5.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "60ef4dd740b7d1bf2c74894eb3891eea", "sha256": "0db01c59cd9806e143c883b38701dcd4084154f5b353df9ea23a1092103c8d3c" }, "downloads": -1, "filename": "dolmen.relations-0.5.tar.gz", "has_sig": false, "md5_digest": "60ef4dd740b7d1bf2c74894eb3891eea", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7938, "upload_time": "2011-11-08T14:52:48", "url": "https://files.pythonhosted.org/packages/0e/0f/f07b18917fe8dc1ae08a5ce0e832ad7177113dc4d9797053fe34a35c1c15/dolmen.relations-0.5.tar.gz" } ] }