[Checkins] SVN: zc.comment/trunk/ Cleanup up the package a lot. ZC
told me they are not using it, so I
Stephan Richter
srichter at cosmos.phy.tufts.edu
Mon Apr 21 19:19:23 EDT 2008
Log message for revision 85576:
Cleanup up the package a lot. ZC told me they are not using it, so I
showed no mercy to the existing API.
Changed:
_U zc.comment/trunk/
A zc.comment/trunk/CHANGES.txt
A zc.comment/trunk/README.txt
U zc.comment/trunk/buildout.cfg
U zc.comment/trunk/setup.py
_U zc.comment/trunk/src/
A zc.comment/trunk/src/zc/comment/README.txt
A zc.comment/trunk/src/zc/comment/browser/README.txt
D zc.comment/trunk/src/zc/comment/browser/comments.txt
A zc.comment/trunk/src/zc/comment/browser/ftesting.zcml
D zc.comment/trunk/src/zc/comment/browser/ftests.py
U zc.comment/trunk/src/zc/comment/browser/tests.py
U zc.comment/trunk/src/zc/comment/comment.py
D zc.comment/trunk/src/zc/comment/comment.txt
U zc.comment/trunk/src/zc/comment/configure.zcml
D zc.comment/trunk/src/zc/comment/ftesting.zcml
U zc.comment/trunk/src/zc/comment/interfaces.py
U zc.comment/trunk/src/zc/comment/tests.py
-=-
Property changes on: zc.comment/trunk
___________________________________________________________________
Name: svn:ignore
+ .installed.cfg
bin
develop-eggs
parts
Added: zc.comment/trunk/CHANGES.txt
===================================================================
--- zc.comment/trunk/CHANGES.txt (rev 0)
+++ zc.comment/trunk/CHANGES.txt 2008-04-21 23:19:22 UTC (rev 85576)
@@ -0,0 +1,8 @@
+=======
+CHANGES
+=======
+
+0.1.0 (2008-??-??)
+------------------
+
+- Initial Release
Property changes on: zc.comment/trunk/CHANGES.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: zc.comment/trunk/README.txt
===================================================================
--- zc.comment/trunk/README.txt (rev 0)
+++ zc.comment/trunk/README.txt 2008-04-21 23:19:22 UTC (rev 85576)
@@ -0,0 +1 @@
+A simple package to support a list of comments for an object.
Property changes on: zc.comment/trunk/README.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: zc.comment/trunk/buildout.cfg
===================================================================
--- zc.comment/trunk/buildout.cfg 2008-04-21 21:55:48 UTC (rev 85575)
+++ zc.comment/trunk/buildout.cfg 2008-04-21 23:19:22 UTC (rev 85576)
@@ -1,15 +1,23 @@
[buildout]
develop = .
-parts = test py
-find-links = http://download.zope.org/distribution/
+parts = test coverage-test coverage-report python
[test]
recipe = zc.recipe.testrunner
-defaults = ['--tests-pattern','[fn]?tests$','--exit-with-status']
-working-directory = ${buildout:directory}/src/zc/comment
-eggs = zc.comment [test]
+eggs = zc.comment [browser, test]
-[py]
+[coverage-test]
+recipe = zc.recipe.testrunner
+eggs = zc.comment [browser, test]
+defaults = ['--coverage', '../../coverage']
+
+[coverage-report]
recipe = zc.recipe.egg
-interpreter = py
-eggs = zc.comment [test]
+eggs = z3c.coverage
+scripts = coverage=coverage-report
+arguments = ('coverage', 'coverage/report')
+
+[python]
+recipe = zc.recipe.egg
+interpreter = python
+eggs = zc.comment
Modified: zc.comment/trunk/setup.py
===================================================================
--- zc.comment/trunk/setup.py 2008-04-21 21:55:48 UTC (rev 85575)
+++ zc.comment/trunk/setup.py 2008-04-21 23:19:22 UTC (rev 85576)
@@ -1,37 +1,88 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Setup
+
+$Id$
+"""
+import os
+import xml.sax.saxutils
from setuptools import setup, find_packages
-setup(
- name="zc.comment",
- version="0.1dev",
- packages=find_packages('src'),
- package_dir={'':'src'},
- namespace_packages=['zc'],
- include_package_data=True,
- install_requires = [ 'setuptools',
- 'zope.interface',
- 'zope.component',
- 'zope.schema',
- 'zope.cachedescriptors',
- 'zope.app.zapi',
- 'zope.app.pagetemplate',
- 'zope.formlib',
- 'zc.table',
- 'zope.app.form',
- 'zope.annotation',
- 'zope.lifecycleevent',
- 'zc.security',
- 'zope.i18nmessageid',
- 'zope.event',
- 'zope.publisher',
- 'zope.app.zcmlfiles',
- 'zope.security',
- 'ZODB3',
- 'pytz',
- ],
- extras_require = dict( test=[ 'zope.app.testing',
- 'zope.testbrowser',
- 'zope.testing',
- ]
- ),
+def read(*rnames):
+ return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
+
+setup (
+ name='zc.comment',
+ version='0.0.1dev',
+ author = "Zope Community",
+ author_email = "zope-dev at zope.org",
+ description = "A simple comment package.",
+ long_description=(
+ read('README.txt')
+ + '\n\n' +
+ 'Detailed Documentation\n'
+ '**********************'
+ + '\n\n' +
+ read('src', 'zc', 'comment', 'README.txt')
+ + '\n\n' +
+ read('src', 'zc', 'comment', 'browser', 'README.txt')
+ + '\n\n' +
+ read('CHANGES.txt')
+ ),
+ license = "ZPL 2.1",
+ keywords = "zope3 comment",
+ classifiers = [
+ 'Development Status :: 4 - Beta',
+ 'Environment :: Web Environment',
+ 'Intended Audience :: Developers',
+ 'License :: OSI Approved :: Zope Public License',
+ 'Programming Language :: Python',
+ 'Natural Language :: English',
+ 'Operating System :: OS Independent',
+ 'Topic :: Internet :: WWW/HTTP',
+ 'Framework :: Zope3'],
+ url = 'http://pypi.python.org/pypi/zc.comment',
+ packages = find_packages('src'),
+ include_package_data = True,
+ package_dir = {'':'src'},
+ namespace_packages = ['zc'],
+ install_requires = ['setuptools',
+ 'zope.interface',
+ 'zope.component',
+ 'zope.schema',
+ 'zope.cachedescriptors',
+ 'zope.app.zapi',
+ 'zope.app.pagetemplate',
+ 'zope.annotation',
+ 'zope.lifecycleevent',
+ 'zope.i18nmessageid',
+ 'zope.event',
+ 'zope.publisher',
+ 'zope.security',
+ 'ZODB3',
+ 'pytz',
+ ],
+ extras_require = dict(
+ test=['zope.app.testing',
+ 'zope.app.zcmlfiles',
+ 'zope.testbrowser',
+ 'zope.testing',
+ ],
+ browser=['zope.formlib',
+ 'zc.table',
+ 'zope.app.form'
+ ],
+ ),
zip_safe = False,
)
Property changes on: zc.comment/trunk/src
___________________________________________________________________
Name: svn:ignore
+ zc.comment.egg-info
Copied: zc.comment/trunk/src/zc/comment/README.txt (from rev 85575, zc.comment/trunk/src/zc/comment/comment.txt)
===================================================================
--- zc.comment/trunk/src/zc/comment/README.txt (rev 0)
+++ zc.comment/trunk/src/zc/comment/README.txt 2008-04-21 23:19:22 UTC (rev 85576)
@@ -0,0 +1,169 @@
+========
+Comments
+========
+
+The comment package is a simple way to add comments to any ``IAnnotatable``
+Zope content. The datetime and current principals are stamped on to the
+comment. The comment body is currently simply unicode text but intended to be
+html snippets ("rich text") at a later date.
+
+The inclusion of current principals requires an interaction, which is what we
+need to set up before we can use the system here. Below, we set up a dummy
+interaction with dummy participants, create some content that is
+``IAttributeAnnotatable``, and then finally show the system in use.
+
+In order to create a participation, we need a few principals:
+
+ >>> import zope.security.management
+ >>> import zope.security.interfaces
+ >>> from zope import interface
+ >>> class Principal(object):
+ ... interface.implements(zope.security.interfaces.IPrincipal)
+ ...
+ ... def __init__(self, id, title, description):
+ ... self.id = id
+ ... self.title = title
+ ... self.description = description
+ ...
+ ... def __repr__(self):
+ ... return '<%s %r>' %(self.__class__.__name__, self.id)
+
+ >>> alice = Principal('alice', 'Alice Aal', 'first principal')
+ >>> betty = Principal('betty', 'Betty Barnes', 'second principal')
+
+Now we can create a participation:
+
+ >>> class Participation(object):
+ ... zope.interface.implements(
+ ... zope.security.interfaces.IParticipation,
+ ... zope.publisher.interfaces.IRequest)
+ ... interaction = principal = None
+ ...
+ ... def __init__(self, principal):
+ ... self.principal = principal
+ ...
+ ... def __repr__(self):
+ ... return '<%s %r>' %(self.__class__.__name__, self.principal)
+
+Next we need to make sute the annotation mechanism is setup, because the
+comments adapter needs to be able to annotate the adapted object:
+
+ >>> import zope.component
+ >>> import zope.annotation
+ >>> zope.component.provideAdapter(
+ ... zope.annotation.attribute.AttributeAnnotations)
+
+Let's now make sure that all commentable objects can receive comments:
+
+ >>> from zc.comment import comment
+ >>> zope.component.provideAdapter(comment.CommentsFactory)
+
+Now that we have everything setup, let's have a look at how it works. First we
+need a simple content component:
+
+ >>> class SimpleContent(object):
+ ... interface.implements(
+ ... zope.annotation.interfaces.IAttributeAnnotatable)
+ ... def __init__(self, name):
+ ... self.name = name
+ ... def __repr__(self):
+ ... return '<%s %r>' %(self.__class__.__name__, self.name)
+ >>> content = SimpleContent(u'content')
+
+In order to play with the comments, we now have to register a new
+participation. In our case, Alice wants to create a comment:
+
+ >>> zope.security.management.endInteraction()
+ >>> zope.security.management.newInteraction(Participation(alice))
+
+We can access the comments of an object by adapting to ``IComments``:
+
+ >>> from zc.comment import interfaces
+ >>> comments = interfaces.IComments(content)
+ Traceback (most recent call last):
+ ...
+ TypeError: ('Could not adapt',
+ <SimpleContent u'content'>,
+ <InterfaceClass zc.comment.interfaces.IComments>)
+
+Initially, the component is not commentable, because it does not provide the
+correct interface:
+
+ >>> zope.interface.directlyProvides(content, interfaces.ICommentable)
+
+ >>> comments = interfaces.IComments(content)
+ >>> comments
+ <Comments (0) for <SimpleContent u'content'>>
+
+Let's now add a comment:
+
+ >>> import datetime, pytz
+ >>> before = datetime.datetime.now(pytz.utc)
+
+ >>> comments.add(u"Foo! Bar!")
+
+ >>> after = datetime.datetime.now(pytz.utc)
+
+As you can see it was not necessary to create the comments object manually,
+but simply pass in the text. Clearly a comment has been added:
+
+ >>> len(comments)
+ 1
+
+Let's now make sure that the data was set correctly:
+
+ >>> comments[0].body
+ u'Foo! Bar!'
+ >>> before <= comments[0].date <= after
+ True
+ >>> comments[0].principal_ids
+ ('alice',)
+
+Let's now log in as Betty:
+
+ >>> zope.security.management.endInteraction()
+ >>> zope.security.management.newInteraction(Participation(betty))
+
+Betty can also add a comment:
+
+ >>> comments = interfaces.IComments(content)
+ >>> before = datetime.datetime.now(pytz.utc)
+ >>> comments.add(u"Shazam")
+ >>> after = datetime.datetime.now(pytz.utc)
+ >>> len(comments)
+ 2
+
+And her comment is also correctly stored:
+
+ >>> comments[1].body
+ u'Shazam'
+ >>> before <= comments[1].date <= after
+ True
+ >>> comments[1].principal_ids
+ ('betty',)
+
+Let's now make sure that if multiple participants are in the interaction that
+all of them get picked up:
+
+ >>> zope.security.management.endInteraction()
+ >>> zope.security.management.newInteraction(
+ ... Participation(alice), Participation(betty))
+
+ >>> comments.add(u"Boom.")
+ >>> len(comments)
+ 3
+ >>> comments[2].body
+ u'Boom.'
+ >>> comments[2].principal_ids
+ ('alice', 'betty')
+
+Finally, note that we can only add unicode text as a valid comment:
+
+ >>> comments.add(42)
+ Traceback (most recent call last):
+ ...
+ ValueError: comment body must be unicode
+
+And of course some cleanup:
+
+ >>> zope.security.management.endInteraction()
Copied: zc.comment/trunk/src/zc/comment/browser/README.txt (from rev 85575, zc.comment/trunk/src/zc/comment/browser/comments.txt)
===================================================================
--- zc.comment/trunk/src/zc/comment/browser/README.txt (rev 0)
+++ zc.comment/trunk/src/zc/comment/browser/README.txt 2008-04-21 23:19:22 UTC (rev 85576)
@@ -0,0 +1,141 @@
+Commenting UI
+=============
+
+Create the browser object we'll be using.
+
+ >>> from zope.testbrowser.testing import Browser
+ >>> browser = Browser()
+ >>> browser.addHeader('Accept-Language', 'test')
+
+To see how comments work, we'll create an instance of a simple content
+object:
+
+ >>> browser.open('http://localhost/@@contents.html')
+ >>> browser.getLink('[[zope][[top]]]').click()
+ >>> browser.getLink('[[zc.comment][Content]]').click()
+ >>> browser.getControl(name='new_value').value = 'number'
+ >>> browser.getControl('[[zope][container-apply-button (Apply)]]').click()
+
+Let's visit the object and click on the comments tab:
+
+ >>> browser.getLink('number').click()
+ >>> browser.getLink('[[zc.comment][Comments]]').click()
+
+We see that no comments have been made yet:
+
+ >>> '[[zc.intranet][No comments have been made.]]' in browser.contents
+ True
+
+Let's add a new multi-line comment:
+
+ >>> browser.getControl('[[zc.comment][New Comment]]').value = '''\
+ ... I give my pledge, as an Earthling
+ ... to save, and faithfully defend from waste
+ ... the natural resources of my planet.
+ ... It's soils, minerals, forests, waters, and wildlife.
+ ... '''
+
+ >>> browser.getControl('[[zc.comment][Add Comment]]').click()
+
+Now, we get a table that displays the comment with it's date, text,
+and the user who made it:
+
+ >>> print browser.contents
+ <...
+ <th>
+ ...[[zc.comment][comment_column-date (Date)]]...
+ </th>
+ <th>
+ ...[[zc.comment][comment_column-principals (Principals)]]...
+ </th>
+ <th>
+ [[zc.comment][comment_column-comment (Comment)]]
+ </th>
+ ...
+ <td>
+ 2005 11 14 12:00:55 -500
+ </td>
+ <td>
+ Unauthenticated User
+ </td>
+ <td>
+ I give my pledge, as an Earthling<br />
+ to save, and faithfully defend from waste<br />
+ the natural resources of my planet.<br />
+ It's soils, minerals, forests, waters, and wildlife.<br />
+ ...
+ <label for="form.comment">
+ <span class="required">*</span><span>[[zc.comment][New Comment]]</span>
+ </label>
+ ...<textarea class="zc-comment-text"
+ style="width: 50ex; height: 6em;"
+ cols="60" id="form.comment"
+ name="form.comment" rows="15" ></textarea></div>
+ ...
+ <input type="submit"
+ id="form.actions.41646420436f6d6d656e74"
+ name="form.actions.41646420436f6d6d656e74"
+ value="[[zc.comment][Add Comment]]"
+ class="button" />
+ ...
+
+Now, we'll add another comment.
+
+ >>> browser.getControl('[[zc.comment][New Comment]]'
+ ... ).value = 'another comment'
+ >>> browser.getControl('[[zc.comment][Add Comment]]').click()
+ >>> print browser.contents
+ <...
+ <th>
+ ...[[zc.comment][comment_column-date (Date)]]...
+ </th>
+ <th>
+ ...[[zc.comment][comment_column-principals (Principals)]]...
+ </th>
+ <th>
+ [[zc.comment][comment_column-comment (Comment)]]
+ </th>
+ </tr>
+ ...
+ <td>
+ 2005 11 14 12:10:18 -500
+ </td>
+ <td>
+ Unauthenticated User
+ </td>
+ <td>
+ I give my pledge, as an Earthling<br />
+ to save, and faithfully defend from waste<br />
+ the natural resources of my planet.<br />
+ It's soils, minerals, forests, waters, and wildlife.<br />
+ <BLANKLINE>
+ </td>
+ </tr>
+ ...
+ <td>
+ 2005 11 14 12:10:18 -500
+ </td>
+ <td>
+ Unauthenticated User
+ </td>
+ <td>
+ another comment
+ </td>
+ </tr>
+ ...
+ <label for="form.comment">
+ <span class="required">*</span><span>[[zc.comment][New Comment]]</span>
+ </label>
+ ...
+ ...<textarea class="zc-comment-text"
+ style="width: 50ex; height: 6em;"
+ cols="60"
+ id="form.comment"
+ name="form.comment"
+ rows="15" ></textarea>...
+ <input type="submit"
+ id="form.actions.41646420436f6d6d656e74"
+ name="form.actions.41646420436f6d6d656e74"
+ value="[[zc.comment][Add Comment]]"
+ class="button" />
+ ...
Deleted: zc.comment/trunk/src/zc/comment/browser/comments.txt
===================================================================
--- zc.comment/trunk/src/zc/comment/browser/comments.txt 2008-04-21 21:55:48 UTC (rev 85575)
+++ zc.comment/trunk/src/zc/comment/browser/comments.txt 2008-04-21 23:19:22 UTC (rev 85576)
@@ -1,141 +0,0 @@
-Commenting UI
-=============
-
-Create the browser object we'll be using.
-
- >>> from zope.testbrowser.testing import Browser
- >>> browser = Browser()
- >>> browser.addHeader('Accept-Language', 'test')
-
-To see how comments work, we'll create an instance of a simple content
-object:
-
- >>> browser.open('http://localhost/@@contents.html')
- >>> browser.getLink('[[zope][[top]]]').click()
- >>> browser.getLink('[[zc.comment][Content]]').click()
- >>> browser.getControl(name='new_value').value = 'number'
- >>> browser.getControl('[[zope][container-apply-button (Apply)]]').click()
-
-Let's visit the object and click on the comments tab:
-
- >>> browser.getLink('number').click()
- >>> browser.getLink('[[zc.comment][Comments]]').click()
-
-We see that no comments have been made yet:
-
- >>> '[[zc.intranet][No comments have been made.]]' in browser.contents
- True
-
-Let's add a new multi-line comment:
-
- >>> browser.getControl('[[zc.comment][New Comment]]').value = '''\
- ... I give my pledge, as an Earthling
- ... to save, and faithfully defend from waste
- ... the natural resources of my planet.
- ... It's soils, minerals, forests, waters, and wildlife.
- ... '''
-
- >>> browser.getControl('[[zc.comment][Add Comment]]').click()
-
-Now, we get a table that displays the comment with it's date, text,
-and the user who made it:
-
- >>> print browser.contents
- <...
- <th>
- ...[[zc.comment][comment_column-date (Date)]]...
- </th>
- <th>
- ...[[zc.comment][comment_column-principals (Principals)]]...
- </th>
- <th>
- [[zc.comment][comment_column-comment (Comment)]]
- </th>
- ...
- <td>
- 2005 11 14 12:00:55 -500
- </td>
- <td>
- Unauthenticated User
- </td>
- <td>
- I give my pledge, as an Earthling<br />
- to save, and faithfully defend from waste<br />
- the natural resources of my planet.<br />
- It's soils, minerals, forests, waters, and wildlife.<br />
- ...
- <label for="form.comment">
- <span class="required">*</span><span>[[zc.comment][New Comment]]</span>
- </label>
- ...<textarea class="zc-comment-text"
- style="width: 50ex; height: 6em;"
- cols="60" id="form.comment"
- name="form.comment" rows="15" ></textarea></div>
- ...
- <input type="submit"
- id="form.actions.41646420436f6d6d656e74"
- name="form.actions.41646420436f6d6d656e74"
- value="[[zc.comment][Add Comment]]"
- class="button" />
- ...
-
-Now, we'll add another comment.
-
- >>> browser.getControl('[[zc.comment][New Comment]]'
- ... ).value = 'another comment'
- >>> browser.getControl('[[zc.comment][Add Comment]]').click()
- >>> print browser.contents
- <...
- <th>
- ...[[zc.comment][comment_column-date (Date)]]...
- </th>
- <th>
- ...[[zc.comment][comment_column-principals (Principals)]]...
- </th>
- <th>
- [[zc.comment][comment_column-comment (Comment)]]
- </th>
- </tr>
- ...
- <td>
- 2005 11 14 12:10:18 -500
- </td>
- <td>
- Unauthenticated User
- </td>
- <td>
- I give my pledge, as an Earthling<br />
- to save, and faithfully defend from waste<br />
- the natural resources of my planet.<br />
- It's soils, minerals, forests, waters, and wildlife.<br />
- <BLANKLINE>
- </td>
- </tr>
- ...
- <td>
- 2005 11 14 12:10:18 -500
- </td>
- <td>
- Unauthenticated User
- </td>
- <td>
- another comment
- </td>
- </tr>
- ...
- <label for="form.comment">
- <span class="required">*</span><span>[[zc.comment][New Comment]]</span>
- </label>
- ...
- ...<textarea class="zc-comment-text"
- style="width: 50ex; height: 6em;"
- cols="60"
- id="form.comment"
- name="form.comment"
- rows="15" ></textarea>...
- <input type="submit"
- id="form.actions.41646420436f6d6d656e74"
- name="form.actions.41646420436f6d6d656e74"
- value="[[zc.comment][Add Comment]]"
- class="button" />
- ...
Copied: zc.comment/trunk/src/zc/comment/browser/ftesting.zcml (from rev 85575, zc.comment/trunk/src/zc/comment/ftesting.zcml)
===================================================================
--- zc.comment/trunk/src/zc/comment/browser/ftesting.zcml (rev 0)
+++ zc.comment/trunk/src/zc/comment/browser/ftesting.zcml 2008-04-21 23:19:22 UTC (rev 85576)
@@ -0,0 +1,9 @@
+<configure xmlns="http://namespaces.zope.org/zope">
+
+ <include package="zope.app.zcmlfiles" />
+ <include package="zope.app.zcmlfiles" file="ftesting.zcml" />
+
+ <include package="zc.comment" />
+ <include package="zc.comment.browser" />
+
+</configure>
Deleted: zc.comment/trunk/src/zc/comment/browser/ftests.py
===================================================================
--- zc.comment/trunk/src/zc/comment/browser/ftests.py 2008-04-21 21:55:48 UTC (rev 85575)
+++ zc.comment/trunk/src/zc/comment/browser/ftests.py 2008-04-21 23:19:22 UTC (rev 85576)
@@ -1,72 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2005 Zope Corporation. All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Visible Source
-# License, Version 1.0 (ZVSL). A copy of the ZVSL should accompany this
-# distribution.
-#
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE
-#
-##############################################################################
-"""Functional tests for the comment text widgets.
-
-"""
-__docformat__ = "reStructuredText"
-
-import unittest
-
-from zope import interface, component
-import zope.publisher.browser
-
-import zope.app.form.interfaces
-import zope.app.testing.functional
-
-import zc.comment.interfaces
-import zc.comment.browser.widget
-
-
-class IFace(interface.Interface):
-
- foo = zc.comment.interfaces.CommentText(
- title=u"Foo",
- description=u"Foo description",
- )
-
-class Face(object):
-
- foo = (u"Foo<br />\n"
- u"\n"
- u"Bar < & >")
-
-
-class WidgetConfigurationTestCase(
- zope.app.testing.functional.FunctionalTestCase):
-
- """Check that configure.zcml sets up the widgets as expected."""
-
- def setUp(self):
- super(WidgetConfigurationTestCase, self).setUp()
- self.field = IFace["foo"]
- self.bound_field = self.field.bind(Face())
- self.request = zope.publisher.browser.TestRequest()
-
- def test_display_widget_lookup(self):
- w = component.getMultiAdapter(
- (self.bound_field, self.request),
- zope.app.form.interfaces.IDisplayWidget)
- self.failUnless(isinstance(w,
- zc.comment.browser.widget.Display))
-
- def test_input_widget_lookup(self):
- w = component.getMultiAdapter(
- (self.bound_field, self.request),
- zope.app.form.interfaces.IInputWidget)
- self.failUnless(isinstance(w, zc.comment.browser.widget.Input))
-
-
-def test_suite():
- return unittest.makeSuite(WidgetConfigurationTestCase)
Modified: zc.comment/trunk/src/zc/comment/browser/tests.py
===================================================================
--- zc.comment/trunk/src/zc/comment/browser/tests.py 2008-04-21 21:55:48 UTC (rev 85575)
+++ zc.comment/trunk/src/zc/comment/browser/tests.py 2008-04-21 23:19:22 UTC (rev 85576)
@@ -16,17 +16,61 @@
"""
__docformat__ = "reStructuredText"
-
+import os
import unittest
-
+import zope.component
+import zope.interface
+import zope.app.form.interfaces
+import zope.app.testing.functional
+import zope.publisher.browser
from zope.app.form.browser.tests import test_browserwidget
+from zope.app.testing.functional import ZCMLLayer
import zc.comment.interfaces
import zc.comment.browser.widget
+CommentsLayer = ZCMLLayer(
+ os.path.join(
+ os.path.split(zc.comment.browser.__file__)[0], 'ftesting.zcml'),
+ __name__, 'CommentsLayer', allow_teardown=True)
+
+
+class IFace(zope.interface.Interface):
+ foo = zc.comment.interfaces.CommentText(
+ title=u"Foo",
+ description=u"Foo description",
+ )
+
+class Face(object):
+ foo = (u"Foo<br />\n"
+ u"\n"
+ u"Bar < & >")
+
+
+class WidgetConfigurationTestCase(unittest.TestCase):
+ """Check that configure.zcml sets up the widgets as expected."""
+
+ def setUp(self):
+ super(WidgetConfigurationTestCase, self).setUp()
+ self.field = IFace["foo"]
+ self.bound_field = self.field.bind(Face())
+ self.request = zope.publisher.browser.TestRequest()
+
+ def test_display_widget_lookup(self):
+ w = zope.component.getMultiAdapter(
+ (self.bound_field, self.request),
+ zope.app.form.interfaces.IDisplayWidget)
+ self.failUnless(isinstance(w, zc.comment.browser.widget.Display))
+
+ def test_input_widget_lookup(self):
+ w = zope.component.getMultiAdapter(
+ (self.bound_field, self.request),
+ zope.app.form.interfaces.IInputWidget)
+ self.failUnless(isinstance(w, zc.comment.browser.widget.Input))
+
+
class TestBase(object):
-
_FieldFactory = zc.comment.interfaces.CommentText
@@ -112,4 +156,9 @@
InputWidgetTestCase,
):
suite.addTest(unittest.makeSuite(cls))
+
+ widgetConfig = unittest.makeSuite(WidgetConfigurationTestCase)
+ widgetConfig.layer = CommentsLayer
+ suite.addTest(widgetConfig)
+
return suite
Modified: zc.comment/trunk/src/zc/comment/comment.py
===================================================================
--- zc.comment/trunk/src/zc/comment/comment.py 2008-04-21 21:55:48 UTC (rev 85575)
+++ zc.comment/trunk/src/zc/comment/comment.py 2008-04-21 23:19:22 UTC (rev 85576)
@@ -12,25 +12,28 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-"""comment adapter
+"""Simple comments implementation as an annotation to commentable objects.
-$Id: comment.py 9472 2006-04-28 04:41:20Z gary $
+$Id$
"""
-import datetime, UserList, pytz
-
-from persistent.list import PersistentList
-from zope import interface, component, event
+import datetime
+import persistent
+import persistent.list
+import pytz
import zope.annotation.interfaces
+import zope.component
+import zope.event
+import zope.interface
+import zope.location
import zope.security.management
import zope.publisher.interfaces
+from zope.annotation import factory
from zc.comment import interfaces
-marker = 'zc.comment'
+class Comment(persistent.Persistent):
+ zope.interface.implements(interfaces.IComment)
-class Comment(object):
- interface.implements(interfaces.IComment)
-
def __init__(self, body):
if not isinstance(body, unicode):
raise ValueError("comment body must be unicode")
@@ -41,31 +44,27 @@
[p.principal.id for p in interaction.participations
if zope.publisher.interfaces.IRequest.providedBy(p)])
-class Comments(object, UserList.UserList):
- interface.implements(interfaces.IComments)
- component.adapts(interfaces.ICommentable)
+
+class Comments(zope.location.Location, persistent.list.PersistentList):
+ zope.interface.implements(interfaces.IComments)
+ zope.component.adapts(interfaces.ICommentable)
+
def pop(self):
raise AttributeError
pop = property(pop)
__setitem__ = __delitem__ = __setslice__ = __delslice__ = __iadd__ = pop
insert = append = remove = reverse = sort = extend = pop
- def __init__(self, context):
- self.__parent__ = context # so we can acquire grants
- self.context = context
- self.annotations = zope.annotation.interfaces.IAnnotations(
- self.context)
- self.data = self.annotations.get(marker)
- if self.data is None:
- self.data = []
-
def add(self, body):
- if self.annotations.get(marker) is None:
- self.data = self.annotations[marker] = PersistentList()
- self.data.append(Comment(body))
- event.notify(interfaces.CommentAdded(self.context, body))
+ super(Comments, self).append(Comment(body))
+ zope.event.notify(interfaces.CommentAdded(self.__parent__, body))
def clear(self): # XXX no test
- if marker in self.annotations:
- del self.annotations[marker]
-
+ persistent.list.PersistentList.__init__(self)
+
+ def __repr__(self):
+ return '<%s (%i) for %r>' %(
+ self.__class__.__name__, len(self), self.__parent__)
+
+
+CommentsFactory = factory(Comments)
Deleted: zc.comment/trunk/src/zc/comment/comment.txt
===================================================================
--- zc.comment/trunk/src/zc/comment/comment.txt 2008-04-21 21:55:48 UTC (rev 85575)
+++ zc.comment/trunk/src/zc/comment/comment.txt 2008-04-21 23:19:22 UTC (rev 85576)
@@ -1,114 +0,0 @@
-========
-Comments
-========
-
-The comment package is a simple way to add comments to any IAnnotatable
-Zope content. The datetime and current principals are stamped on to the
-comment. The comment body is currently simply unicode text but intended to
-be html snippets ("rich text") at a later date.
-
-The inclusion of current principals requires an interaction, which is what we
-need to set up before we can use the system here. Below, we set up a dummy
-interaction with dummy participants, create some content that is
-IAttributeAnnotatable, and then finally show the system in use.
-
- >>> import zope.security.management
- >>> import zope.security.interfaces
- >>> from zope import interface
- >>> class DummyPrincipal(object):
- ... interface.implements(zope.security.interfaces.IPrincipal)
- ... def __init__(self, id, title, description):
- ... self.id = id
- ... self.title = title
- ... self.description = description
- ...
- >>> alice = DummyPrincipal('alice', 'Alice Aal', 'first principal')
- >>> betty = DummyPrincipal('betty', 'Betty Barnes', 'second principal')
- >>> cathy = DummyPrincipal('cathy', 'Cathy Camero', 'third principal')
- >>> class DummyParticipation(object):
- ... interface.implements(zope.security.interfaces.IParticipation)
- ... interaction = principal = None
- ... def __init__(self, principal):
- ... self.principal = principal
- ...
- >>> import zope.publisher.interfaces
-
- >>> import zope.annotation.interfaces
- >>> from zope.app.testing import ztapi
- >>> import zope.annotation.attribute
- >>> ztapi.provideAdapter( # hook up attribute annotations
- ... (zope.annotation.interfaces.IAttributeAnnotatable,),
- ... zope.annotation.interfaces.IAnnotations,
- ... zope.annotation.attribute.AttributeAnnotations)
-
- >>> from zc.comment import comment, interfaces
- >>> ztapi.provideAdapter( # hook up our adapter
- ... (zope.annotation.interfaces.IAnnotatable,),
- ... interfaces.IComments,
- ... comment.Comments)
-
- >>> class DummyObject(object):
- ... interface.implements(
- ... zope.annotation.interfaces.IAttributeAnnotatable)
- ...
- >>> obj = DummyObject()
-
- >>> a_p = DummyParticipation(alice)
- >>> interface.directlyProvides(a_p, zope.publisher.interfaces.IRequest)
- >>> zope.security.management.newInteraction(a_p)
- >>> adapted = interfaces.IComments(obj)
- >>> len(adapted)
- 0
- >>> import datetime, pytz
- >>> before = datetime.datetime.now(pytz.utc)
- >>> adapted.add(u"Foo! Bar!")
- >>> after = datetime.datetime.now(pytz.utc)
- >>> len(adapted)
- 1
- >>> adapted[0].body
- u'Foo! Bar!'
- >>> before <= adapted[0].date <= after
- True
- >>> adapted[0].principal_ids
- ('alice',)
- >>> zope.security.management.endInteraction()
- >>> b_p = DummyParticipation(betty)
- >>> interface.directlyProvides(b_p, zope.publisher.interfaces.IRequest)
- >>> zope.security.management.newInteraction(b_p)
- >>> adapted = interfaces.IComments(obj)
- >>> before = datetime.datetime.now(pytz.utc)
- >>> adapted.add(u"Shazam")
- >>> after = datetime.datetime.now(pytz.utc)
- >>> len(adapted)
- 2
- >>> adapted[1].body
- u'Shazam'
- >>> before <= adapted[1].date <= after
- True
- >>> adapted[1].principal_ids
- ('betty',)
- >>> zope.security.management.endInteraction()
- >>> a_p = DummyParticipation(alice)
- >>> b_p = DummyParticipation(betty)
- >>> c_p = DummyParticipation(cathy)
- >>> interface.directlyProvides(a_p, zope.publisher.interfaces.IRequest)
- >>> interface.directlyProvides(b_p, zope.publisher.interfaces.IRequest)
-
- >>> zope.security.management.newInteraction(a_p, b_p, c_p)
- >>> adapted = interfaces.IComments(obj)
- >>> before = datetime.datetime.now(pytz.utc)
- >>> adapted.add(u"Boom.")
- >>> after = datetime.datetime.now(pytz.utc)
- >>> len(adapted)
- 3
- >>> adapted[2].body
- u'Boom.'
- >>> before <= adapted[2].date <= after
- True
- >>> adapted[2].principal_ids # cathy was not a request so not in list
- ('alice', 'betty')
- >>> adapted.add(42)
- Traceback (most recent call last):
- ...
- ValueError: comment body must be unicode
- >>> zope.security.management.endInteraction()
Modified: zc.comment/trunk/src/zc/comment/configure.zcml
===================================================================
--- zc.comment/trunk/src/zc/comment/configure.zcml 2008-04-21 21:55:48 UTC (rev 85575)
+++ zc.comment/trunk/src/zc/comment/configure.zcml 2008-04-21 23:19:22 UTC (rev 85576)
@@ -3,14 +3,18 @@
<class class=".comment.Comment">
<require permission="zope.Public"
- interface=".interfaces.IComment"/>
+ interface=".interfaces.IComment"/>
</class>
+ <class class=".comment.Comments">
+ <require permission="zope.Public"
+ interface=".interfaces.IComments"/>
+ </class>
+
<adapter
- factory=".comment.Comments"
- trusted="1" permission="zope.View"
+ factory=".comment.CommentsFactory"
+ trusted="True"
+ permission="zope.View"
/>
- <include package=".browser" />
-
</configure>
Deleted: zc.comment/trunk/src/zc/comment/ftesting.zcml
===================================================================
--- zc.comment/trunk/src/zc/comment/ftesting.zcml 2008-04-21 21:55:48 UTC (rev 85575)
+++ zc.comment/trunk/src/zc/comment/ftesting.zcml 2008-04-21 23:19:22 UTC (rev 85576)
@@ -1,8 +0,0 @@
-<configure xmlns="http://namespaces.zope.org/zope">
-
- <include package="zope.app.zcmlfiles" />
- <include package="zope.app.zcmlfiles" file="ftesting.zcml" />
-
- <include package="zc.comment" />
-
-</configure>
\ No newline at end of file
Modified: zc.comment/trunk/src/zc/comment/interfaces.py
===================================================================
--- zc.comment/trunk/src/zc/comment/interfaces.py 2008-04-21 21:55:48 UTC (rev 85575)
+++ zc.comment/trunk/src/zc/comment/interfaces.py 2008-04-21 23:19:22 UTC (rev 85576)
@@ -12,69 +12,68 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-"""interfaces for comment package
+"""Interfaces for comment package
-$Id: interfaces.py 9472 2006-04-28 04:41:20Z gary $
+$Id$
"""
-from zope import interface, schema
-from zope.interface.common.sequence import IReadSequence
-import zope.schema.interfaces
-
+import zope.interface
+import zope.schema
import zope.annotation.interfaces
import zope.lifecycleevent
import zope.lifecycleevent.interfaces
+from zope.interface.common.sequence import IReadSequence
-from zc.security.search import SimplePrincipalSource
from i18n import _
-class ICommentText(schema.interfaces.IText):
+class ICommentText(zope.schema.interfaces.IText):
"""Type of rich text field used for comment text."""
class CommentText(zope.schema.Text):
"""Rich text field used for comment text."""
+ zope.interface.implements(ICommentText)
- interface.implements(ICommentText)
-
-class IComment(interface.Interface):
- date = schema.Datetime(
+class IComment(zope.interface.Interface):
+ date = zope.schema.Datetime(
title=_("Creation Date"),
description=_("The date on which this comment was made"),
- required=True, readonly=True)
+ required=True,
+ readonly=True)
- principal_ids = schema.Tuple(
- value_type=schema.Choice(
- source=SimplePrincipalSource()),
+ principal_ids = zope.schema.Tuple(
title=_("Principals"),
- description=_(
- """The ids of the principals who made this comment"""),
- required=True, readonly=True)
+ description=_("""The ids of the principals who made this comment"""),
+ required=True,
+ readonly=True)
body = CommentText(
title=_("Comment Body"),
description=_("The comment text."),
- required=False, readonly=True)
+ required=False,
+ readonly=True)
+
class IComments(IReadSequence):
def add(body):
- """add comment with given body.
- """
+ """add comment with given body."""
def clear():
- """Remove all comments.
- """
+ """Remove all comments."""
class ICommentable(zope.annotation.interfaces.IAnnotatable):
"Content that may be commented upon"
+
class ICommentAdded(zope.lifecycleevent.interfaces.IObjectModifiedEvent):
"""Somone added a comment to some content
"""
- comment = schema.Text(title=u"The comment entered")
+ comment = zope.schema.Text(
+ title=u"The comment entered")
+
class CommentAdded(zope.lifecycleevent.ObjectModifiedEvent):
def __init__(self, object, comment):
Modified: zc.comment/trunk/src/zc/comment/tests.py
===================================================================
--- zc.comment/trunk/src/zc/comment/tests.py 2008-04-21 21:55:48 UTC (rev 85575)
+++ zc.comment/trunk/src/zc/comment/tests.py 2008-04-21 23:19:22 UTC (rev 85576)
@@ -16,14 +16,17 @@
$Id: tests.py 678 2005-02-22 21:49:28Z gary $
"""
-
import unittest
from zope.testing import doctest
+from zope.app.testing import placelesssetup
def test_suite():
return unittest.TestSuite((
doctest.DocFileSuite(
- 'comment.txt'),))
+ 'README.txt',
+ setUp=placelesssetup.setUp, tearDown=placelesssetup.tearDown,
+ optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS),
+ ))
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
More information about the Checkins
mailing list