{ "info": { "author": "Zope Community", "author_email": "zope-dev@zope.org", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Web Environment", "Framework :: Zope3", "Intended Audience :: Developers", "License :: OSI Approved :: Zope Public License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Internet :: WWW/HTTP" ], "description": "A simple package to support a list of comments for an object.\n\n\nDetailed Documentation\n**********************\n\n========\nComments\n========\n\nThe comment package is a simple way to add comments to any ``IAnnotatable``\nZope content. The datetime and current principals are stamped on to the\ncomment. The comment body is currently simply unicode text but intended to be\nhtml snippets (\"rich text\") at a later date.\n\nThe inclusion of current principals requires an interaction, which is what we\nneed to set up before we can use the system here. Below, we set up a dummy\ninteraction with dummy participants, create some content that is\n``IAttributeAnnotatable``, and then finally show the system in use.\n\nIn order to create a participation, we need a few principals:\n\n >>> import zope.security.management\n >>> import zope.security.interfaces\n >>> from zope import interface\n >>> class Principal(object):\n ... interface.implements(zope.security.interfaces.IPrincipal)\n ...\n ... def __init__(self, id, title, description):\n ... self.id = id\n ... self.title = title\n ... self.description = description\n ...\n ... def __repr__(self):\n ... return '<%s %r>' %(self.__class__.__name__, self.id)\n\n >>> alice = Principal('alice', 'Alice Aal', 'first principal')\n >>> betty = Principal('betty', 'Betty Barnes', 'second principal')\n\nNow we can create a participation:\n\n >>> class Participation(object):\n ... zope.interface.implements(\n ... zope.security.interfaces.IParticipation,\n ... zope.publisher.interfaces.IRequest)\n ... interaction = principal = None\n ...\n ... def __init__(self, principal):\n ... self.principal = principal\n ...\n ... def __repr__(self):\n ... return '<%s %r>' %(self.__class__.__name__, self.principal)\n\nNext we need to make sute the annotation mechanism is setup, because the\ncomments adapter needs to be able to annotate the adapted object:\n\n >>> import zope.component\n >>> import zope.annotation\n >>> zope.component.provideAdapter(\n ... zope.annotation.attribute.AttributeAnnotations)\n\nLet's now make sure that all commentable objects can receive comments:\n\n >>> from zc.comment import comment\n >>> zope.component.provideAdapter(comment.CommentsFactory)\n\nNow that we have everything setup, let's have a look at how it works. First we\nneed a simple content component:\n\n >>> class SimpleContent(object):\n ... interface.implements(\n ... zope.annotation.interfaces.IAttributeAnnotatable)\n ... def __init__(self, name):\n ... self.name = name\n ... def __repr__(self):\n ... return '<%s %r>' %(self.__class__.__name__, self.name)\n >>> content = SimpleContent(u'content')\n\nIn order to play with the comments, we now have to register a new\nparticipation. In our case, Alice wants to create a comment:\n\n >>> zope.security.management.endInteraction()\n >>> zope.security.management.newInteraction(Participation(alice))\n\nWe can access the comments of an object by adapting to ``IComments``:\n\n >>> from zc.comment import interfaces\n >>> comments = interfaces.IComments(content)\n Traceback (most recent call last):\n ...\n TypeError: ('Could not adapt',\n ,\n )\n\nInitially, the component is not commentable, because it does not provide the\ncorrect interface:\n\n >>> zope.interface.directlyProvides(content, interfaces.ICommentable)\n\n >>> comments = interfaces.IComments(content)\n >>> comments\n >\n\nLet's now add a comment:\n\n >>> import datetime, pytz\n >>> before = datetime.datetime.now(pytz.utc)\n\n >>> comments.add(u\"Foo! Bar!\")\n\n >>> after = datetime.datetime.now(pytz.utc)\n\nAs you can see it was not necessary to create the comments object manually,\nbut simply pass in the text. Clearly a comment has been added:\n\n >>> len(comments)\n 1\n\nLet's now make sure that the data was set correctly:\n\n >>> comments[0].body\n u'Foo! Bar!'\n >>> before <= comments[0].date <= after\n True\n >>> comments[0].principal_ids\n ('alice',)\n\nLet's now log in as Betty:\n\n >>> zope.security.management.endInteraction()\n >>> zope.security.management.newInteraction(Participation(betty))\n\nBetty can also add a comment:\n\n >>> comments = interfaces.IComments(content)\n >>> before = datetime.datetime.now(pytz.utc)\n >>> comments.add(u\"Shazam\")\n >>> after = datetime.datetime.now(pytz.utc)\n >>> len(comments)\n 2\n\nAnd her comment is also correctly stored:\n\n >>> comments[1].body\n u'Shazam'\n >>> before <= comments[1].date <= after\n True\n >>> comments[1].principal_ids\n ('betty',)\n\nLet's now make sure that if multiple participants are in the interaction that\nall of them get picked up:\n\n >>> zope.security.management.endInteraction()\n >>> zope.security.management.newInteraction(\n ... Participation(alice), Participation(betty))\n\n >>> comments.add(u\"Boom.\")\n >>> len(comments)\n 3\n >>> comments[2].body\n u'Boom.'\n >>> comments[2].principal_ids\n ('alice', 'betty')\n\nFinally, note that we can only add unicode text as a valid comment:\n\n >>> comments.add(42)\n Traceback (most recent call last):\n ...\n WrongType: (42, )\n\nIf you like, you can always clear all comments:\n\n >>> comments.clear()\n >>> len(comments)\n 0\n\nAnd of course some cleanup:\n\n >>> zope.security.management.endInteraction()\n\n\n=============\nCommenting UI\n=============\n\nCreate the browser object we'll be using.\n\n >>> from zope.testbrowser.testing import Browser\n >>> browser = Browser()\n >>> browser.addHeader('Accept-Language', 'test')\n\nTo see how comments work, we'll create an instance of a simple content\nobject:\n\n >>> browser.open('http://localhost/@@contents.html')\n >>> browser.getLink('[[zope][[top]]]').click()\n >>> browser.getLink('[[zc.comment][Content]]').click()\n >>> browser.getControl(name='new_value').value = 'number'\n >>> browser.getControl('[[zope][container-apply-button (Apply)]]').click()\n\nLet's visit the object and click on the comments tab:\n\n >>> browser.handleErrors = False\n >>> browser.getLink('number').click()\n >>> browser.getLink('[[zc.comment][Comments]]').click()\n\nWe see that no comments have been made yet:\n\n >>> '[[zc.intranet][No comments have been made.]]' in browser.contents\n True\n\nLet's add a new multi-line comment:\n\n >>> browser.getControl('[[zc.comment][New Comment]]').value = '''\\\n ... I give my pledge, as an Earthling\n ... to save, and faithfully defend from waste\n ... the natural resources of my planet.\n ... It's soils, minerals, forests, waters, and wildlife.\n ... '''\n\n >>> browser.getControl('[[zc.comment][Add Comment]]').click()\n\nNow, we get a table that displays the comment with it's date, text,\nand the user who made it:\n\n >>> print browser.contents\n <...\n \n ...[[zc.comment][comment_column-date (Date)]]...\n \n \n ...[[zc.comment][comment_column-principals (Principals)]]...\n \n \n [[zc.comment][comment_column-comment (Comment)]]\n \n ...\n \n 2005 11 14 12:00:55 -500\n \n \n Unauthenticated User\n \n \n I give my pledge, as an Earthling
\n to save, and faithfully defend from waste
\n the natural resources of my planet.
\n It's soils, minerals, forests, waters, and wildlife.
\n ...\n \n ...\n ...\n \n ...\n\nNow, we'll add another comment.\n\n >>> browser.getControl('[[zc.comment][New Comment]]'\n ... ).value = 'another comment'\n >>> browser.getControl('[[zc.comment][Add Comment]]').click()\n >>> print browser.contents\n <...\n \n ...[[zc.comment][comment_column-date (Date)]]...\n \n \n ...[[zc.comment][comment_column-principals (Principals)]]...\n \n \n [[zc.comment][comment_column-comment (Comment)]]\n \n \n ...\n \n 2005 11 14 12:10:18 -500\n \n \n Unauthenticated User\n \n \n I give my pledge, as an Earthling
\n to save, and faithfully defend from waste
\n the natural resources of my planet.
\n It's soils, minerals, forests, waters, and wildlife.
\n \n \n \n ...\n \n 2005 11 14 12:10:18 -500\n \n \n Unauthenticated User\n \n \n another comment\n \n \n ...\n \n ...\n ......\n \n ...\n\n\n=======\nCHANGES\n=======\n\n0.1.0 (2008-04-21)\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://pypi.python.org/pypi/zc.comment", "keywords": "zope3 comment", "license": "ZPL 2.1", "maintainer": null, "maintainer_email": null, "name": "zc.comment", "package_url": "https://pypi.org/project/zc.comment/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/zc.comment/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://pypi.python.org/pypi/zc.comment" }, "release_url": "https://pypi.org/project/zc.comment/0.1.0/", "requires_dist": null, "requires_python": null, "summary": "A simple comment package.", "version": "0.1.0" }, "last_serial": 802165, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "4a7172d8e8c029a9e418228345c8f14f", "sha256": "2cc8d1f5b7adf1a7f297b3f5412a4ee3a1c00a65fb1f9bc3ac101c116082ab8e" }, "downloads": -1, "filename": "zc.comment-0.1.0.tar.gz", "has_sig": false, "md5_digest": "4a7172d8e8c029a9e418228345c8f14f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13096, "upload_time": "2008-04-22T00:05:28", "url": "https://files.pythonhosted.org/packages/6f/c3/7a12a64dd555917ad7bd3ecdc5e7200b6ee0013770d4092b9724a5637508/zc.comment-0.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "4a7172d8e8c029a9e418228345c8f14f", "sha256": "2cc8d1f5b7adf1a7f297b3f5412a4ee3a1c00a65fb1f9bc3ac101c116082ab8e" }, "downloads": -1, "filename": "zc.comment-0.1.0.tar.gz", "has_sig": false, "md5_digest": "4a7172d8e8c029a9e418228345c8f14f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13096, "upload_time": "2008-04-22T00:05:28", "url": "https://files.pythonhosted.org/packages/6f/c3/7a12a64dd555917ad7bd3ecdc5e7200b6ee0013770d4092b9724a5637508/zc.comment-0.1.0.tar.gz" } ] }