[Checkins] SVN: grok/branches/christiancodeviewsplit/src/grok/ Create a Base Class which holds the methods application_url and flash

Christian Klinger cklinger at novareto.de
Tue Jul 7 08:42:16 EDT 2009


Log message for revision 101698:
  Create a Base Class which holds the methods application_url and flash
  Let grokcore.View and grokcore.CodeView inherit from these Base Class
  

Changed:
  U   grok/branches/christiancodeviewsplit/src/grok/__init__.py
  U   grok/branches/christiancodeviewsplit/src/grok/components.py

-=-
Modified: grok/branches/christiancodeviewsplit/src/grok/__init__.py
===================================================================
--- grok/branches/christiancodeviewsplit/src/grok/__init__.py	2009-07-07 12:04:09 UTC (rev 101697)
+++ grok/branches/christiancodeviewsplit/src/grok/__init__.py	2009-07-07 12:42:16 UTC (rev 101698)
@@ -38,7 +38,6 @@
 from grokcore.view import skin
 from grokcore.view import url
 from grokcore.view import path
-from grokcore.view import CodeView 
 
 from grokcore.viewlet import Viewlet
 from grokcore.viewlet import ViewletManager
@@ -72,7 +71,7 @@
     ObjectRemovedEvent,
     ContainerModifiedEvent)
 
-from grok.components import Model, View
+from grok.components import Model, View, CodeView
 from grok.components import XMLRPC, REST, JSON
 from grok.components import Traverser
 from grok.components import Container, OrderedContainer

Modified: grok/branches/christiancodeviewsplit/src/grok/components.py
===================================================================
--- grok/branches/christiancodeviewsplit/src/grok/components.py	2009-07-07 12:04:09 UTC (rev 101697)
+++ grok/branches/christiancodeviewsplit/src/grok/components.py	2009-07-07 12:42:16 UTC (rev 101698)
@@ -215,7 +215,32 @@
     """The base class for annotation classes in Grok applications."""
 
 
-class View(grokcore.view.View):
+class BaseView(object):
+    """ Base Class for helper methods"""
+    interface.implements(interfaces.IGrokView)
+
+    def application_url(self, name=None):
+        """Return the URL of the nearest enclosing `grok.Application`."""
+        obj = self.context
+        while obj is not None:
+            if isinstance(obj, Application):
+                return self.url(obj, name)
+            obj = obj.__parent__
+        raise ValueError("No application found.")
+
+    def flash(self, message, type='message'):
+        """Send a short message to the user."""
+        # XXX this has no tests or documentation, anywhere
+        source = component.getUtility(
+            z3c.flashmessage.interfaces.IMessageSource, name='session')
+        source.send(message, type)
+
+
+class CodeView(grokcore.view.CodeView, BaseView):
+    """ CHECK THIS """
+
+
+class View(grokcore.view.View, BaseView):
     """The base class for views in Grok applications.
 
     Each class that inherits from `grok.View` is designed to "render" a
@@ -285,25 +310,9 @@
     rendered under ``self.context``.
 
     """
-    interface.implements(interfaces.IGrokView)
 
-    def application_url(self, name=None):
-        """Return the URL of the nearest enclosing `grok.Application`."""
-        obj = self.context
-        while obj is not None:
-            if isinstance(obj, Application):
-                return self.url(obj, name)
-            obj = obj.__parent__
-        raise ValueError("No application found.")
 
-    def flash(self, message, type='message'):
-        """Send a short message to the user."""
-        # XXX this has no tests or documentation, anywhere
-        source = component.getUtility(
-            z3c.flashmessage.interfaces.IMessageSource, name='session')
-        source.send(message, type)
 
-
 class Form(grokcore.formlib.Form, View):
     """The base class for forms in Grok applications.
 



More information about the Checkins mailing list