[Checkins] SVN: megrok.kss/trunk/ Added KSSActionsForView base
class which groks a view
Godefroid Chapelle
gotcha at bubblenet.be
Thu May 1 13:41:44 EDT 2008
Log message for revision 86018:
Added KSSActionsForView base class which groks a view
and the corresponding grokker.
[jladage]
Changed:
A megrok.kss/trunk/bootstrap.py
A megrok.kss/trunk/docs/CREDITS.txt
U megrok.kss/trunk/docs/HISTORY.txt
U megrok.kss/trunk/setup.py
U megrok.kss/trunk/src/megrok/kss/__init__.py
U megrok.kss/trunk/src/megrok/kss/components.py
U megrok.kss/trunk/src/megrok/kss/doc/README.txt
A megrok.kss/trunk/src/megrok/kss/integration.zcml
U megrok.kss/trunk/src/megrok/kss/meta.py
A megrok.kss/trunk/src/megrok/kss/testing.py
A megrok.kss/trunk/src/megrok/kss/tests/
A megrok.kss/trunk/src/megrok/kss/tests/__init__.py
A megrok.kss/trunk/src/megrok/kss/tests/kssactions.py
A megrok.kss/trunk/src/megrok/kss/tests/test_integration.py
-=-
Added: megrok.kss/trunk/bootstrap.py
===================================================================
--- megrok.kss/trunk/bootstrap.py (rev 0)
+++ megrok.kss/trunk/bootstrap.py 2008-05-01 17:41:43 UTC (rev 86018)
@@ -0,0 +1,55 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Corporation 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.
+#
+##############################################################################
+"""Bootstrap a buildout-based project
+
+Simply run this script in a directory containing a buildout.cfg.
+The script accepts buildout command-line options, so you can
+use the -c option to specify an alternate configuration file.
+
+$Id$
+"""
+
+import os, shutil, sys, tempfile, urllib2
+
+tmpeggs = tempfile.mkdtemp()
+
+try:
+ import pkg_resources
+except ImportError:
+ ez = {}
+ exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
+ ).read() in ez
+ ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+
+ import pkg_resources
+
+cmd = 'from setuptools.command.easy_install import main; main()'
+if sys.platform == 'win32':
+ cmd = '"%s"' % cmd # work around spawn lamosity on windows
+
+ws = pkg_resources.working_set
+assert os.spawnle(
+ os.P_WAIT, sys.executable, sys.executable,
+ '-c', cmd, '-mqNxd', tmpeggs, 'zc.buildout',
+ dict(os.environ,
+ PYTHONPATH=
+ ws.find(pkg_resources.Requirement.parse('setuptools')).location
+ ),
+ ) == 0
+
+ws.add_entry(tmpeggs)
+ws.require('zc.buildout')
+import zc.buildout.buildout
+zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
+shutil.rmtree(tmpeggs)
Added: megrok.kss/trunk/docs/CREDITS.txt
===================================================================
--- megrok.kss/trunk/docs/CREDITS.txt (rev 0)
+++ megrok.kss/trunk/docs/CREDITS.txt 2008-05-01 17:41:43 UTC (rev 86018)
@@ -0,0 +1,5 @@
+AUTHORS
+-------
+
+Jean-Paul Ladage <j.ladage at zestsoftware.nl>
+Godefroid Chapelle <gotcha at bubblenet.be>
Modified: megrok.kss/trunk/docs/HISTORY.txt
===================================================================
--- megrok.kss/trunk/docs/HISTORY.txt 2008-05-01 17:37:34 UTC (rev 86017)
+++ megrok.kss/trunk/docs/HISTORY.txt 2008-05-01 17:41:43 UTC (rev 86018)
@@ -1,10 +1,13 @@
Changelog for megrok.kss
+------------------------
(name of developer listed in brackets)
megrok.kss - 0.2 Unreleased
- - ...
+ - Added KSSActionsForView base class which groks a view
+ and the corresponding grokker.
+ [jladage]
megrok.kss - 0.1 Released 2008-04-30
Modified: megrok.kss/trunk/setup.py
===================================================================
--- megrok.kss/trunk/setup.py 2008-05-01 17:37:34 UTC (rev 86017)
+++ megrok.kss/trunk/setup.py 2008-05-01 17:41:43 UTC (rev 86018)
@@ -8,7 +8,9 @@
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
long_description = (
- read('docs', 'README.txt')
+ read('docs', 'README.txt') + '\n' +
+ read('docs', 'HISTORY.txt') + '\n' +
+ read('docs', 'CREDITS.txt')
)
setup(name='megrok.kss',
Modified: megrok.kss/trunk/src/megrok/kss/__init__.py
===================================================================
--- megrok.kss/trunk/src/megrok/kss/__init__.py 2008-05-01 17:37:34 UTC (rev 86017)
+++ megrok.kss/trunk/src/megrok/kss/__init__.py 2008-05-01 17:41:43 UTC (rev 86018)
@@ -1 +1 @@
-from components import KSSActions
+from components import KSSActions, KSSActionsForView
Modified: megrok.kss/trunk/src/megrok/kss/components.py
===================================================================
--- megrok.kss/trunk/src/megrok/kss/components.py 2008-05-01 17:37:34 UTC (rev 86017)
+++ megrok.kss/trunk/src/megrok/kss/components.py 2008-05-01 17:41:43 UTC (rev 86018)
@@ -1,12 +1,29 @@
from zope.publisher.publish import mapply
-
from kss.core import KSSView
+
class KSSActions(KSSView):
-
+ """This is the default KSSActions class that binds to a content object.
+ """
+
def __call__(self):
view_name = self.__view_name__
method = getattr(self, view_name)
method_result = mapply(method, (), self.request)
return self.render()
+
+class KSSActionsForView(KSSView):
+ """This KSSActions class is bound to a view class.
+ """
+
+ def __init__(self, context, request):
+ self.view = context
+ super(KSSActionsForView, self).__init__(context, request)
+ self.context = context.context
+
+ def __call__(self):
+ view_name = self.__view_name__
+ method = getattr(self, view_name)
+ method_result = mapply(method, (), self.request)
+ return self.render()
Modified: megrok.kss/trunk/src/megrok/kss/doc/README.txt
===================================================================
--- megrok.kss/trunk/src/megrok/kss/doc/README.txt 2008-05-01 17:37:34 UTC (rev 86017)
+++ megrok.kss/trunk/src/megrok/kss/doc/README.txt 2008-05-01 17:41:43 UTC (rev 86018)
@@ -41,11 +41,11 @@
<link tal:attributes="href static/app.kss" rel="kinetic-stylesheet" type="text/kss" />
-- create a KSSActions view with code like::
+- create a KSSAction view with code like::
- from megrok.kss import KSSActions
+ from megrok.kss import KSSAction
- class AppKSS(KSSActions):
+ class AppKSS(KSSAction):
def welcome(self):
core = self.getCommandSet('core')
Added: megrok.kss/trunk/src/megrok/kss/integration.zcml
===================================================================
--- megrok.kss/trunk/src/megrok/kss/integration.zcml (rev 0)
+++ megrok.kss/trunk/src/megrok/kss/integration.zcml 2008-05-01 17:41:43 UTC (rev 86018)
@@ -0,0 +1,9 @@
+<configure xmlns="http://namespaces.zope.org/zope"
+ xmlns:grok="http://namespaces.zope.org/grok">
+ <include package="grok" file="meta.zcml" />
+ <include package="grok" />
+ <include package="megrok.kss" />
+
+ <!-- Register the test fixtures -->
+ <grok:grok package="megrok.kss.tests.kssactions" />
+</configure>
Modified: megrok.kss/trunk/src/megrok/kss/meta.py
===================================================================
--- megrok.kss/trunk/src/megrok/kss/meta.py 2008-05-01 17:37:34 UTC (rev 86017)
+++ megrok.kss/trunk/src/megrok/kss/meta.py 2008-05-01 17:41:43 UTC (rev 86018)
@@ -1,28 +1,25 @@
from zope import component
from zope import interface
-
from zope.publisher.browser import BrowserPage
from zope.publisher.interfaces.browser import IDefaultBrowserLayer
import martian
from martian import util
-
+import grok
from grok.util import get_default_permission, make_checker
+from grok.util import determine_class_directive
from grok.meta import get_context
-from components import KSSActions
+from components import KSSActions, KSSActionsForView
-class KSSActionsGrokker(martian.ClassGrokker):
- component_class = KSSActions
+class KSSBaseGrokker(martian.ClassGrokker):
+ grok.baseclass()
- def grok(self, name, factory, module_info, config, **kw):
- view_context = get_context(module_info, factory)
- # XXX We should really not make __FOO__ methods available to
- # the outside -- need to discuss how to restrict such things.
+ def process_grok(self, name, factory, module_info, config, view_context,
+ **kw):
methods = util.methods_from_class(factory)
-
default_permission = get_default_permission(factory)
-
+
for method in methods:
name = method.__name__
if name.startswith('__'):
@@ -30,22 +27,19 @@
# Create a new class with a __view_name__ attribute so the
# KSSServerAction class knows what method to call.
-
+
#We should allow name directives on methods
#view_name = util.class_annotation(factory, 'grok.name',
# factory_name)
-
- method_view = type(
- factory.__name__, (factory, BrowserPage),
- {'__view_name__': name}
- )
+ method_view = type(factory.__name__, (factory, BrowserPage),
+ {'__view_name__': name})
+
adapts = (view_context, IDefaultBrowserLayer)
- config.action(
- discriminator=('adapter', adapts, interface.Interface, name),
+ config.action(discriminator=('adapter', adapts,
+ interface.Interface, name),
callable=component.provideAdapter,
- args=(method_view, adapts, interface.Interface, name),
- )
+ args=(method_view, adapts, interface.Interface, name))
# Protect method_view with either the permission that was
# set on the method, the default permission from the class
@@ -53,10 +47,30 @@
permission = getattr(method, '__grok_require__',
default_permission)
- config.action(
- discriminator=('protectName', method_view, '__call__'),
+ config.action(discriminator=('protectName', method_view,
+ '__call__'),
callable=make_checker,
- args=(factory, method_view, permission),
- )
+ args=(factory, method_view, permission))
+
+
+class KSSActionsGrokker(KSSBaseGrokker):
+ """This is a default KSSAction view, self.context is the content object"""
+ component_class = KSSActions
+
+ def grok(self, name, factory, module_info, config, **kw):
+ view_context = get_context(module_info, factory)
+ self.process_grok(name, factory, module_info, config, view_context)
+
return True
+
+class KSSActionsForViewGrokker(KSSBaseGrokker):
+ """A KSS Action for a view. This has self.view which holds a view class"""
+ component_class = KSSActionsForView
+
+ def grok(self, name, factory, module_info, config, **kw):
+ view_context = determine_class_directive('grok.view', factory,
+ module_info)
+ self.process_grok(name, factory, module_info, config, view_context)
+
+ return True
Added: megrok.kss/trunk/src/megrok/kss/testing.py
===================================================================
--- megrok.kss/trunk/src/megrok/kss/testing.py (rev 0)
+++ megrok.kss/trunk/src/megrok/kss/testing.py 2008-05-01 17:41:43 UTC (rev 86018)
@@ -0,0 +1,7 @@
+import os.path
+import megrok.kss
+from zope.app.testing.functional import ZCMLLayer
+
+integration_zcml = os.path.join(
+ os.path.dirname(megrok.kss.__file__), 'integration.zcml')
+IntegrationLayer = ZCMLLayer(integration_zcml, __name__, 'IntegrationLayer')
Added: megrok.kss/trunk/src/megrok/kss/tests/__init__.py
===================================================================
--- megrok.kss/trunk/src/megrok/kss/tests/__init__.py (rev 0)
+++ megrok.kss/trunk/src/megrok/kss/tests/__init__.py 2008-05-01 17:41:43 UTC (rev 86018)
@@ -0,0 +1 @@
+#
\ No newline at end of file
Added: megrok.kss/trunk/src/megrok/kss/tests/kssactions.py
===================================================================
--- megrok.kss/trunk/src/megrok/kss/tests/kssactions.py (rev 0)
+++ megrok.kss/trunk/src/megrok/kss/tests/kssactions.py 2008-05-01 17:41:43 UTC (rev 86018)
@@ -0,0 +1,77 @@
+"""
+ >>> from zope.publisher.browser import TestRequest
+ >>> from zope.component import getMultiAdapter
+ >>> request = TestRequest()
+
+First we create a model. After that we get and call the KSS action on
+it.
+
+ >>> mymodel = TestModel('model1')
+ >>> kssaction = getMultiAdapter((mymodel, request), name="getId")
+ >>> print kssaction()
+ <?xml version="1.0" ?>
+ <kukit xmlns="http://www.kukit.org/commands/1.1">
+ <commands>
+ <command selector="#click-me" name="replaceHTML"
+ selectorType="">
+ <param name="html"><![CDATA[Something silly!]]></param>
+ <param name="withKssSetup">True</param>
+ </command>
+ </commands>
+ </kukit>
+ <BLANKLINE>
+
+Second we create a view on the model and call the KSS action on the view. The
+KSS action calls `self.view.render()`.
+
+ >>> view = getMultiAdapter((mymodel, request), name="testview")
+ >>> kssaction = getMultiAdapter((view, request), name="getId")
+ >>> print kssaction()
+ <?xml version="1.0" ?>
+ <kukit xmlns="http://www.kukit.org/commands/1.1">
+ <commands>
+ <command selector="#click-me" name="replaceHTML"
+ selectorType="">
+ <param name="html"><![CDATA[model1]]></param>
+ <param name="withKssSetup">True</param>
+ </command>
+ </commands>
+ </kukit>
+ <BLANKLINE>
+"""
+
+import grok
+from megrok.kss import KSSActions, KSSActionsForView
+
+
+class TestModel(grok.Model):
+
+ def __init__(self, id):
+ """docstring for __init__"""
+ self.id = id
+
+
+class TestView(grok.View):
+
+ def render(self):
+ return self.context.id
+
+
+class TestKSSActions(KSSActions):
+
+ grok.context(TestModel)
+
+ def getId(self):
+ """Docstring for getId"""
+ core = self.getCommandSet('core')
+ core.replaceHTML('#click-me', 'Something silly!')
+
+
+class TestKSSActionsForView(KSSActionsForView):
+
+ grok.view(TestView)
+
+ def getId(self):
+ """Docstring for getId"""
+ core = self.getCommandSet('core')
+ core.replaceHTML('#click-me', self.view.render())
Added: megrok.kss/trunk/src/megrok/kss/tests/test_integration.py
===================================================================
--- megrok.kss/trunk/src/megrok/kss/tests/test_integration.py (rev 0)
+++ megrok.kss/trunk/src/megrok/kss/tests/test_integration.py 2008-05-01 17:41:43 UTC (rev 86018)
@@ -0,0 +1,19 @@
+import unittest
+from zope.testing import doctest
+from zope.configuration import xmlconfig
+
+import megrok.kss.tests
+from megrok.kss.testing import IntegrationLayer
+
+
+def setUp(test):
+ """docstring for setUp"""
+ xmlconfig.file('configure.zcml', package=megrok.kss.tests)
+
+
+def test_suite():
+ suite = unittest.TestSuite()
+ suite.addTest(doctest.DocTestSuite('megrok.kss.tests.kssactions',
+ optionflags=doctest.NORMALIZE_WHITESPACE))
+ suite.layer = IntegrationLayer
+ return suite
More information about the Checkins
mailing list