[Checkins] SVN: megrok.kss/trunk/ Changed the base class to `KSS` instead of `KSSActions`. It now also binds to a view instead of just the context. Thanks Jean-Paul for the changes.

Jeroen Vloothuis jeroen.vloothuis at xs4all.nl
Fri May 2 10:36:03 EDT 2008


Log message for revision 86097:
  Changed the base class to `KSS` instead of `KSSActions`. It now also binds to a view instead of just the context. Thanks Jean-Paul for the changes.

Changed:
  U   megrok.kss/trunk/docs/HISTORY.txt
  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/integration.zcml
  U   megrok.kss/trunk/src/megrok/kss/meta.py
  A   megrok.kss/trunk/src/megrok/kss/tests/kss.py
  D   megrok.kss/trunk/src/megrok/kss/tests/kssactions.py
  U   megrok.kss/trunk/src/megrok/kss/tests/test_integration.py

-=-
Modified: megrok.kss/trunk/docs/HISTORY.txt
===================================================================
--- megrok.kss/trunk/docs/HISTORY.txt	2008-05-02 14:25:53 UTC (rev 86096)
+++ megrok.kss/trunk/docs/HISTORY.txt	2008-05-02 14:36:03 UTC (rev 86097)
@@ -5,12 +5,11 @@
 
 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
-  
-    - basic kss.core support
-      [gotcha]
+    - To simplify the usage of KSS in Grok we renamed the `KSSActions` class
+      to `KSS`, which is more in line with the JSON and WSGI extensions. In
+      Grok, you apply KSS on a view rather than a content object.
+      Use: grok.view(MyViewClass) to register it.
+ 
+    -  [jladage] - - megrok.kss - 0.1 Released 2008-04-30 - - - basic kss.core
+      support [gotcha]
 

Modified: megrok.kss/trunk/src/megrok/kss/__init__.py
===================================================================
--- megrok.kss/trunk/src/megrok/kss/__init__.py	2008-05-02 14:25:53 UTC (rev 86096)
+++ megrok.kss/trunk/src/megrok/kss/__init__.py	2008-05-02 14:36:03 UTC (rev 86097)
@@ -1 +1 @@
-from components import KSSActions, KSSActionsForView
+from components import KSS
\ No newline at end of file

Modified: megrok.kss/trunk/src/megrok/kss/components.py
===================================================================
--- megrok.kss/trunk/src/megrok/kss/components.py	2008-05-02 14:25:53 UTC (rev 86096)
+++ megrok.kss/trunk/src/megrok/kss/components.py	2008-05-02 14:36:03 UTC (rev 86097)
@@ -2,24 +2,13 @@
 from kss.core import KSSView
 
 
-class KSSActions(KSSView):
-    """This is the default KSSActions class that binds to a content object.
+class KSS(KSSView):
+    """This is the default KSS action 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)
+        super(KSS, self).__init__(context, request)
         self.context = context.context
 
     def __call__(self):

Modified: megrok.kss/trunk/src/megrok/kss/integration.zcml
===================================================================
--- megrok.kss/trunk/src/megrok/kss/integration.zcml	2008-05-02 14:25:53 UTC (rev 86096)
+++ megrok.kss/trunk/src/megrok/kss/integration.zcml	2008-05-02 14:36:03 UTC (rev 86097)
@@ -5,5 +5,5 @@
   <include package="megrok.kss" />
 
   <!-- Register the test fixtures -->
-  <grok:grok package="megrok.kss.tests.kssactions" />
+  <grok:grok package="megrok.kss.tests.kss" />
 </configure>

Modified: megrok.kss/trunk/src/megrok/kss/meta.py
===================================================================
--- megrok.kss/trunk/src/megrok/kss/meta.py	2008-05-02 14:25:53 UTC (rev 86096)
+++ megrok.kss/trunk/src/megrok/kss/meta.py	2008-05-02 14:36:03 UTC (rev 86097)
@@ -5,21 +5,22 @@
 
 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, KSSActionsForView
+from components import KSS
 
-class KSSBaseGrokker(martian.ClassGrokker):
-    grok.baseclass()
 
-    def process_grok(self, name, factory, module_info, config, view_context,
-                     **kw):
+class KSSGrokker(martian.ClassGrokker):
+    component_class = KSS
+
+    def grok(self, name, factory, module_info, config, **kw):
+        view_context = determine_class_directive('grok.view', factory,
+                                                 module_info)
         methods = util.methods_from_class(factory)
         default_permission = get_default_permission(factory)
-        
+
         for method in methods:
             name = method.__name__
             if name.startswith('__'):
@@ -52,25 +53,4 @@
                 callable=make_checker,
                 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

Copied: megrok.kss/trunk/src/megrok/kss/tests/kss.py (from rev 86096, megrok.kss/trunk/src/megrok/kss/tests/kssactions.py)
===================================================================
--- megrok.kss/trunk/src/megrok/kss/tests/kss.py	                        (rev 0)
+++ megrok.kss/trunk/src/megrok/kss/tests/kss.py	2008-05-02 14:36:03 UTC (rev 86097)
@@ -0,0 +1,50 @@
+"""
+  >>> from zope.publisher.browser import TestRequest
+  >>> from zope.component import getMultiAdapter
+  >>> request = TestRequest()
+
+We create a view on the model and call the KSS action on the view. The
+KSS action calls `self.view.render()`.
+
+  >>> mymodel = TestModel('model1') 
+  >>> view = getMultiAdapter((mymodel, request), name="testview")
+  >>> kss = getMultiAdapter((view, request), name="getId")
+  >>> print kss()
+  <?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>
+"""
+
+import grok
+from megrok.kss import KSS
+
+
+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 TestKSS(KSS):
+
+    grok.view(TestView)
+
+    def getId(self):
+        """Docstring for getId"""
+        core = self.getCommandSet('core')
+        core.replaceHTML('#click-me', 'Something silly!')

Deleted: megrok.kss/trunk/src/megrok/kss/tests/kssactions.py
===================================================================
--- megrok.kss/trunk/src/megrok/kss/tests/kssactions.py	2008-05-02 14:25:53 UTC (rev 86096)
+++ megrok.kss/trunk/src/megrok/kss/tests/kssactions.py	2008-05-02 14:36:03 UTC (rev 86097)
@@ -1,77 +0,0 @@
-"""
-  >>> 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())

Modified: megrok.kss/trunk/src/megrok/kss/tests/test_integration.py
===================================================================
--- megrok.kss/trunk/src/megrok/kss/tests/test_integration.py	2008-05-02 14:25:53 UTC (rev 86096)
+++ megrok.kss/trunk/src/megrok/kss/tests/test_integration.py	2008-05-02 14:36:03 UTC (rev 86097)
@@ -13,7 +13,7 @@
 
 def test_suite():
     suite = unittest.TestSuite()
-    suite.addTest(doctest.DocTestSuite('megrok.kss.tests.kssactions',
+    suite.addTest(doctest.DocTestSuite('megrok.kss.tests.kss',
                                         optionflags=doctest.NORMALIZE_WHITESPACE))
     suite.layer = IntegrationLayer
     return suite



More information about the Checkins mailing list