[Checkins] SVN: grokcore.view/trunk/src/grokcore/view/ Moved the methods static and default_namespace to the BaseView so we have it in View AND CodeView.
Christian Klinger
cklinger at novareto.de
Tue Sep 15 12:33:15 EDT 2009
Log message for revision 104106:
Moved the methods static and default_namespace to the BaseView so we have it in View AND CodeView.
Changed:
U grokcore.view/trunk/src/grokcore/view/components.py
U grokcore.view/trunk/src/grokcore/view/interfaces.py
-=-
Modified: grokcore.view/trunk/src/grokcore/view/components.py
===================================================================
--- grokcore.view/trunk/src/grokcore/view/components.py 2009-09-15 16:32:11 UTC (rev 104105)
+++ grokcore.view/trunk/src/grokcore/view/components.py 2009-09-15 16:33:14 UTC (rev 104106)
@@ -37,6 +37,14 @@
def __init__(self, context, request):
super(BaseView, self).__init__(context, request)
self.__name__ = getattr(self, '__view_name__', None)
+ if getattr(self, 'module_info', None) is not None:
+ self.static = component.queryAdapter(
+ self.request,
+ interface.Interface,
+ name=self.module_info.package_dotted_name
+ )
+ else:
+ self.static = None
def update(self, **kwargs):
pass
@@ -75,7 +83,18 @@
def response(self):
return self.request.response
+ def default_namespace(self):
+ namespace = {}
+ namespace['context'] = self.context
+ namespace['request'] = self.request
+ namespace['static'] = self.static
+ namespace['view'] = self
+ return namespace
+ def namespace(self):
+ return {}
+
+
class CodeView(BaseView):
interface.implements(interfaces.IGrokCodeView)
@@ -100,15 +119,6 @@
def __init__(self, context, request):
super(View, self).__init__(context, request)
- if getattr(self, 'module_info', None) is not None:
- self.static = component.queryAdapter(
- self.request,
- interface.Interface,
- name=self.module_info.package_dotted_name
- )
- else:
- self.static = None
-
def __call__(self, *args, **kwargs):
mapply(self.update, (), self.request)
if self.request.response.getStatus() in (302, 303):
@@ -118,17 +128,6 @@
return self.template.render(self)
- def default_namespace(self):
- namespace = {}
- namespace['context'] = self.context
- namespace['request'] = self.request
- namespace['static'] = self.static
- namespace['view'] = self
- return namespace
-
- def namespace(self):
- return {}
-
def __getitem__(self, key):
# This is BBB code for Zope page templates only:
if not isinstance(self.template, PageTemplate):
Modified: grokcore.view/trunk/src/grokcore/view/interfaces.py
===================================================================
--- grokcore.view/trunk/src/grokcore/view/interfaces.py 2009-09-15 16:32:11 UTC (rev 104105)
+++ grokcore.view/trunk/src/grokcore/view/interfaces.py 2009-09-15 16:33:14 UTC (rev 104106)
@@ -114,22 +114,6 @@
filled in from the request (in that case they *must* be
present in the request)."""
-
-class IGrokCodeView(IGrokBaseView):
-
- def render(**kw):
- """A view can either be rendered by an associated template, or
- it can implement this method to render itself from Python.
- This is useful if the view's output isn't XML/HTML but
- something computed in Python (plain text, PDF, etc.)
-
- render() can take arbitrary keyword parameters which will be
- filled in from the request (in that case they *must* be
- present in the request)."""
-
-
-class IGrokView(IGrokBaseView):
-
static = Attribute('static', "Directory resource containing "
"the static files of the view's package.")
@@ -150,7 +134,24 @@
"""
+class IGrokCodeView(IGrokBaseView):
+ def render(**kw):
+ """A view can either be rendered by an associated template, or
+ it can implement this method to render itself from Python.
+ This is useful if the view's output isn't XML/HTML but
+ something computed in Python (plain text, PDF, etc.)
+
+ render() can take arbitrary keyword parameters which will be
+ filled in from the request (in that case they *must* be
+ present in the request)."""
+
+
+class IGrokView(IGrokBaseView):
+ """Marker Interface for Views with a template
+ """
+
+
class ITemplateFileFactory(Interface):
"""Utility that generates templates from files in template directories.
"""
More information about the checkins
mailing list