[Checkins] SVN: five.grok/branches/sylvain-viewlets/ Remove useless spaces. Add implementation for viewlet (grokker included).
Sylvain Viollon
sylvain at infrae.com
Wed Oct 15 18:21:17 EDT 2008
Log message for revision 92267:
Remove useless spaces. Add implementation for viewlet (grokker included).
Changed:
U five.grok/branches/sylvain-viewlets/README.txt
U five.grok/branches/sylvain-viewlets/src/five/grok/__init__.py
U five.grok/branches/sylvain-viewlets/src/five/grok/components.py
U five.grok/branches/sylvain-viewlets/src/five/grok/directives.py
U five.grok/branches/sylvain-viewlets/src/five/grok/ftesting.zcml
U five.grok/branches/sylvain-viewlets/src/five/grok/meta.py
U five.grok/branches/sylvain-viewlets/src/five/grok/testing.py
-=-
Modified: five.grok/branches/sylvain-viewlets/README.txt
===================================================================
--- five.grok/branches/sylvain-viewlets/README.txt 2008-10-15 21:57:23 UTC (rev 92266)
+++ five.grok/branches/sylvain-viewlets/README.txt 2008-10-15 22:21:16 UTC (rev 92267)
@@ -4,7 +4,7 @@
Introduction
------------
-five.grok is a web framework development layer for Zope 2, based on Grok
+five.grok is a web framework development layer for Zope 2, based on Grok
concepts. The development techniques are similar to the ones for Grok.
It is currently experimental, don't use in production.
Modified: five.grok/branches/sylvain-viewlets/src/five/grok/__init__.py
===================================================================
--- five.grok/branches/sylvain-viewlets/src/five/grok/__init__.py 2008-10-15 21:57:23 UTC (rev 92266)
+++ five.grok/branches/sylvain-viewlets/src/five/grok/__init__.py 2008-10-15 22:21:16 UTC (rev 92267)
@@ -3,10 +3,11 @@
from grokcore.view import *
from grokcore.formlib import *
-from five.grok.components import View, Model, Form, AddForm, EditForm, DisplayForm
-from five.grok.components import ViewletManager
+from five.grok.components import View, Model, Form, AddForm
+from five.grok.components import EditForm, DisplayForm
+from five.grok.components import ViewletManager, Viewlet
-from five.grok.directives import view
+from five.grok.directives import view, viewletmanager
# Override the one from grokcore.view so that we get Zope 2 semantics
from five.grok.components import ZopeTwoPageTemplate as PageTemplate
Modified: five.grok/branches/sylvain-viewlets/src/five/grok/components.py
===================================================================
--- five.grok/branches/sylvain-viewlets/src/five/grok/components.py 2008-10-15 21:57:23 UTC (rev 92266)
+++ five.grok/branches/sylvain-viewlets/src/five/grok/components.py 2008-10-15 22:21:16 UTC (rev 92267)
@@ -1,7 +1,7 @@
import martian
from zope.annotation.interfaces import IAttributeAnnotatable
-from zope.viewlet.interfaces import IViewletManager
+from zope.viewlet.interfaces import IViewletManager, IViewlet
from zope.security.interfaces import IPermission
from zope.app.pagetemplate.viewpagetemplatefile import ViewMapper
from zope import interface, component
@@ -19,6 +19,7 @@
from Products.Five.browser import resource
from Products.Five.formlib import formbase
from Products.Five.viewlet.manager import ViewletManagerBase
+from Products.Five.viewlet.viewlet import ViewletBase
from Products.PageTemplates.Expressions import SecureModuleImporter
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
from OFS.SimpleItem import SimpleItem
@@ -52,10 +53,10 @@
# TODO: This should probably move to Products.Five.browser
class ViewAwareZopePageTemplate(ZopePageTemplate):
-
+
def pt_getEngine(self):
return getEngine()
-
+
def pt_getContext(self):
try:
root = self.getPhysicalRoot()
@@ -105,7 +106,7 @@
def setFromFilename(self, filename, _prefix=None):
self._template = ViewPageTemplateFile(filename, _prefix)
-
+
def render(self, view):
namespace = self.getNamespace(view)
template = self._template.__of__(view)
@@ -144,7 +145,7 @@
def __init__(self, *args):
super(GrokForm, self).__init__(*args)
self.__name__ = self.__view_name__
- # super seems not to work correctly since this is needed again.
+ # super seems not to work correctly since this is needed again.
self.static = component.queryAdapter(
self.request, interface.Interface,
name = self.module_info.package_dotted_name)
@@ -256,10 +257,34 @@
[(name, viewlet.__of__(parent)) for name, viewlet in viewlets])
def render(self):
- """See zope.contentprovider.interfaces.IContentProvider"""
+ """See zope.contentprovider.interfaces.IContentProvider
+ """
# Now render the view
if getattr(self, 'template', None):
return self.template.render(self)
- else:
- return u'\n'.join([viewlet.render() for viewlet in self.viewlets])
+ return u'\n'.join([viewlet.render() for viewlet in self.viewlets])
+
+
+class Viewlet(ContentProviderBase, ViewletBase):
+
+ interface.implements(IViewlet)
+
+ martian.baseclass()
+
+ def __init__(self, context, request, view, viewletmanager):
+ ContentProviderBase.__init__(self, context, request, view)
+ self.viewletmanager = viewletmanager
+
+ def default_namespace(self):
+ namespace = super(ContentProvider, self).default_namespace()
+ namespace['viewlet'] = self
+ namespace['viewletmanager'] = self.viewletmanager
+ return namespace
+
+ def update(self):
+ pass
+
+ def render(self):
+ return self.template.render(self)
+
Modified: five.grok/branches/sylvain-viewlets/src/five/grok/directives.py
===================================================================
--- five.grok/branches/sylvain-viewlets/src/five/grok/directives.py 2008-10-15 21:57:23 UTC (rev 92266)
+++ five.grok/branches/sylvain-viewlets/src/five/grok/directives.py 2008-10-15 22:21:16 UTC (rev 92267)
@@ -1,8 +1,15 @@
+from zope import interface
import martian
class view(martian.Directive):
scope = martian.CLASS_OR_MODULE
store = martian.ONCE
- default = None
+ default = interface.Interface
validate = martian.validateInterfaceOrClass
+
+class viewletmanager(martian.Directive):
+ scope = martian.CLASS_OR_MODULE
+ store = martian.ONCE
+ default = interface.Interface
+ validate = martian.validateInterfaceOrClass
Modified: five.grok/branches/sylvain-viewlets/src/five/grok/ftesting.zcml
===================================================================
--- five.grok/branches/sylvain-viewlets/src/five/grok/ftesting.zcml 2008-10-15 21:57:23 UTC (rev 92266)
+++ five.grok/branches/sylvain-viewlets/src/five/grok/ftesting.zcml 2008-10-15 22:21:16 UTC (rev 92267)
@@ -9,7 +9,7 @@
<!-- And also grok all the ftests /-->
<grok:grok package="five.grok.ftests" />
-
+
<include package="zope.app.basicskin" />
<include package="zope.app.rotterdam" />
Modified: five.grok/branches/sylvain-viewlets/src/five/grok/meta.py
===================================================================
--- five.grok/branches/sylvain-viewlets/src/five/grok/meta.py 2008-10-15 21:57:23 UTC (rev 92266)
+++ five.grok/branches/sylvain-viewlets/src/five/grok/meta.py 2008-10-15 22:21:16 UTC (rev 92267)
@@ -21,7 +21,7 @@
class ViewSecurityGrokker(martian.ClassGrokker):
martian.component(five.grok.View)
martian.directive(grokcore.security.require, name='permission')
-
+
def execute(self, factory, config, permission, **kw):
if permission is None:
permission = 'zope.Public'
@@ -41,6 +41,7 @@
return True
+
class StaticResourcesGrokker(martian.GlobalGrokker):
def grok(self, name, module, module_info, config, **kw):
@@ -99,11 +100,6 @@
def execute(self, provider, name, context, view, layer, config, **kw):
"""Register a content provider.
"""
-
- if view is None:
- # Can't set default on the directive because of import loop.
- view = interface.Interface
-
templates = provider.module_info.getAnnotation('grok.templates', None)
if templates is not None:
config.action(
@@ -129,3 +125,38 @@
return False
templates.checkTemplates(module_info, provider, 'viewlet manager',
has_render, has_no_render)
+
+
+class ViewletGrokker(ViewletManagerGrokker):
+
+ martian.component(components.Viewlet)
+ martian.directive(five.grok.viewletmanager)
+
+ def execute(self, provider, name, context, view,
+ layer, viewletmanager, config, **kw):
+ """Register a viewlet.
+ """
+ templates = provider.module_info.getAnnotation('grok.templates', None)
+ if templates is not None:
+ config.action(
+ discriminator=None,
+ callable=self.checkTemplates,
+ args=(templates, provider.module_info, provider)
+ )
+
+ for_ = (context, layer, view, viewletmanager)
+ config.action(
+ discriminator=('adapter', for_, IViewlet, name),
+ callable=provideAdapter,
+ args=(provider, for_, IViewlet, name),
+ )
+
+ return True
+
+ def checkTemplates(self, templates, module_info, provider):
+ def has_render(provider):
+ return provider.render != components.Viewlet.render
+ def has_no_render(provider):
+ return not has_render(provider)
+ templates.checkTemplates(module_info, provider, 'viewlet',
+ has_render, has_no_render)
Modified: five.grok/branches/sylvain-viewlets/src/five/grok/testing.py
===================================================================
--- five.grok/branches/sylvain-viewlets/src/five/grok/testing.py 2008-10-15 21:57:23 UTC (rev 92266)
+++ five.grok/branches/sylvain-viewlets/src/five/grok/testing.py 2008-10-15 22:21:16 UTC (rev 92267)
@@ -49,7 +49,7 @@
result = zcml.the_multi_grokker.grok(name, component,
module_info=module_info,
config=config)
- config.execute_actions()
+ config.execute_actions()
return result
def warn(message, category=None, stacklevel=1):
@@ -121,5 +121,3 @@
GrokFunctionalLayer = Layer
-
-
More information about the Checkins
mailing list