From: Christian S. <svn...@pl...> - 2008-01-20 15:56:29
|
Author: mrtopf Date: Sun Jan 20 15:56:31 2008 New Revision: 19042 Added: plone.app.commenting/trunk/plone/app/commenting/configuration/ plone.app.commenting/trunk/plone/app/commenting/configuration/__init__.py (contents, props changed) plone.app.commenting/trunk/plone/app/commenting/configuration/configure.zcml plone.app.commenting/trunk/plone/app/commenting/configuration/interfaces.py (contents, props changed) plone.app.commenting/trunk/plone/app/commenting/configuration/manager.py (contents, props changed) plone.app.commenting/trunk/plone/app/commenting/docs/test_configuration.txt (contents, props changed) Modified: plone.app.commenting/trunk/plone/app/commenting/configure.zcml plone.app.commenting/trunk/plone/app/commenting/tests/base.py plone.app.commenting/trunk/plone/app/commenting/tests/testDocTests.py Log: added local configuration support. Added: plone.app.commenting/trunk/plone/app/commenting/configuration/__init__.py ============================================================================== Added: plone.app.commenting/trunk/plone/app/commenting/configuration/configure.zcml ============================================================================== --- (empty file) +++ plone.app.commenting/trunk/plone/app/commenting/configuration/configure.zcml Sun Jan 20 15:56:31 2008 @@ -0,0 +1,9 @@ +<configure + xmlns="http://namespaces.zope.org/zope" + xmlns:five="http://namespaces.zope.org/five" + i18n_domain="plone.app.commenting"> + + <adapter factory=".manager.LocalCommentConfigurationManager" + provides=".interfaces.ILocalCommentConfigurationManager" /> + +</configure> Added: plone.app.commenting/trunk/plone/app/commenting/configuration/interfaces.py ============================================================================== --- (empty file) +++ plone.app.commenting/trunk/plone/app/commenting/configuration/interfaces.py Sun Jan 20 15:56:31 2008 @@ -0,0 +1,15 @@ +from plone.app.localconf.interfaces import IHasLocalConfiguration, ILocalConfigurationManager, ILocalConfigurationAssignable + +class IHasCommentConfiguration(IHasLocalConfiguration): + """marker interface to mark objects to have local configuration""" + + +class ILocalCommentConfigurationManager(ILocalConfigurationManager): + """handles comment configuration""" + +class ILocalCommentConfigurationAssignable(ILocalConfigurationAssignable): + """marker interface for objects which can have local configurations""" + + + + Added: plone.app.commenting/trunk/plone/app/commenting/configuration/manager.py ============================================================================== --- (empty file) +++ plone.app.commenting/trunk/plone/app/commenting/configuration/manager.py Sun Jan 20 15:56:31 2008 @@ -0,0 +1,16 @@ +from zope.interface import implements +from zope.component import adapts + +from plone.app.localconf.localconfmanager import LocalConfigurationManager +from interfaces import IHasCommentConfiguration, ILocalCommentConfigurationManager, ILocalCommentConfigurationAssignable + +class LocalCommentConfigurationManager(LocalConfigurationManager): + """implement a configuration manager for commenting""" + implements(ILocalCommentConfigurationManager) + adapts(ILocalCommentConfigurationAssignable) + + KEY = "plone.app.commenting.configurations" + MARKER = IHasCommentConfiguration + + + \ No newline at end of file Modified: plone.app.commenting/trunk/plone/app/commenting/configure.zcml ============================================================================== --- plone.app.commenting/trunk/plone/app/commenting/configure.zcml (original) +++ plone.app.commenting/trunk/plone/app/commenting/configure.zcml Sun Jan 20 15:56:31 2008 @@ -2,9 +2,17 @@ xmlns="http://namespaces.zope.org/zope" xmlns:five="http://namespaces.zope.org/five" i18n_domain="plone.app.commenting"> + + + <include package=".configuration" /> <five:implements class="Products.Archetypes.atapi.BaseContent" interface="plone.commenting.interfaces.ICommentable" /> + <five:implements + class="Products.Archetypes.atapi.BaseFolder" + interface="plone.app.commenting.configuration.interfaces.ILocalCommentConfigurationAssignable" /> + + </configure> Added: plone.app.commenting/trunk/plone/app/commenting/docs/test_configuration.txt ============================================================================== --- (empty file) +++ plone.app.commenting/trunk/plone/app/commenting/docs/test_configuration.txt Sun Jan 20 15:56:31 2008 @@ -0,0 +1,51 @@ + +First we set some stuff up and import it +>>> folder = self.portal.folder +>>> from plone.app.commenting.configuration.interfaces import ILocalCommentConfigurationManager +>>> from plone.app.commenting.configuration.interfaces import ILocalCommentConfigurationAssignable + + +The folder should be allowed to get comment configurations to be assigned: +>>> ILocalCommentConfigurationAssignable.providedBy(folder) +True + +Now we can adapt the folder to a comment configuration manager +>>> mgr = ILocalCommentConfigurationManager(folder) + +It should not have any configuration attached right now +>>> mgr.exists +False + +And we can initialize the configuration: +>>> mgr.initialize() +<persistent.dict.PersistentDict object at ...> +>>> mgr.exists +True + +As we see, it exists now. + + +Now retrieve the local configuration object and store something +>>> localconf = mgr.retrieve() +>>> localconf["foo"] = "bar" + +now retrieve it again and read something + +>>> mgr2 = ILocalCommentConfigurationManager(folder) +>>> localconf2 = mgr2.retrieve() +>>> localconf2.get('foo') +'bar' + + +Now we check the implementation details. First we check for the marker interface: +>>> from plone.app.commenting.configuration.interfaces import IHasCommentConfiguration +>>> IHasCommentConfiguration.providedBy(folder) +True + +Now we can check if the attributes are stores correctly (and the right key): +>>> from zope.annotation.interfaces import IAnnotations +>>> annotations = IAnnotations(folder) +>>> manager = annotations.get("plone.app.commenting.configurations", None) +>>> manager +<persistent.dict.PersistentDict object at ...> + Modified: plone.app.commenting/trunk/plone/app/commenting/tests/base.py ============================================================================== --- plone.app.commenting/trunk/plone/app/commenting/tests/base.py (original) +++ plone.app.commenting/trunk/plone/app/commenting/tests/base.py Sun Jan 20 15:56:31 2008 @@ -31,6 +31,16 @@ portal.invokeFactory("Document", 'document', title="Document") portal.portal_workflow.doActionFor(portal.document, "publish") + # add some more folders because we can + portal.invokeFactory("Folder", 'folder', title="Folder") + portal.folder.invokeFactory("Folder", 'folder2', title="Folder 2") + portal.folder.folder2.invokeFactory("Folder", 'folder3', title="Folder 3") + folder3 = portal.folder.folder2.folder3 + + # and another document + folder3.invokeFactory("Document", 'document2', title="Document 2") + portal.portal_workflow.doActionFor(folder3.document2, "publish") + commit() ZopeTestCase.close(app) Modified: plone.app.commenting/trunk/plone/app/commenting/tests/testDocTests.py ============================================================================== --- plone.app.commenting/trunk/plone/app/commenting/tests/testDocTests.py (original) +++ plone.app.commenting/trunk/plone/app/commenting/tests/testDocTests.py Sun Jan 20 15:56:31 2008 @@ -17,7 +17,7 @@ else: pattern = compile('(^test.*|/test[^/]*)\.(txt|rst)$') -# we collect all matching doctests in ../docs/ +# # we collect all matching doctests in ../docs/ tests = [] docs = join(abspath(dirname(__file__)), '../docs/') for path, dirs, files in walk(docs, topdown=False): |