[Checkins] SVN: five.grok/branches/sylvain-viewlets/src/five/grok/ Fix viewlet implementation, add tests for it.
Sylvain Viollon
sylvain at infrae.com
Sun Oct 26 20:14:32 EDT 2008
Log message for revision 92608:
Fix viewlet implementation, add tests for it.
Changed:
U five.grok/branches/sylvain-viewlets/src/five/grok/components.py
A five.grok/branches/sylvain-viewlets/src/five/grok/ftests/viewlet/manager_template.py
A five.grok/branches/sylvain-viewlets/src/five/grok/ftests/viewlet/security.py
A five.grok/branches/sylvain-viewlets/src/five/grok/ftests/viewlet/simple.py
A five.grok/branches/sylvain-viewlets/src/five/grok/ftests/viewlet/simple2.py
U five.grok/branches/sylvain-viewlets/src/five/grok/meta.py
-=-
Modified: five.grok/branches/sylvain-viewlets/src/five/grok/components.py
===================================================================
--- five.grok/branches/sylvain-viewlets/src/five/grok/components.py 2008-10-26 20:41:03 UTC (rev 92607)
+++ five.grok/branches/sylvain-viewlets/src/five/grok/components.py 2008-10-27 00:14:30 UTC (rev 92608)
@@ -222,7 +222,7 @@
martian.baseclass()
def __init__(self, context, request, view, manager):
- super(ViewletManager, self).__init__(context, request, view, manager)
+ super(Viewlet, self).__init__(context, request, view, manager)
if not (self.static is None):
# XXX See View
self.static = self.static.__of__(self)
Added: five.grok/branches/sylvain-viewlets/src/five/grok/ftests/viewlet/manager_template.py
===================================================================
--- five.grok/branches/sylvain-viewlets/src/five/grok/ftests/viewlet/manager_template.py (rev 0)
+++ five.grok/branches/sylvain-viewlets/src/five/grok/ftests/viewlet/manager_template.py 2008-10-27 00:14:30 UTC (rev 92608)
@@ -0,0 +1,39 @@
+"""
+ >>> from five.grok.ftests.viewlet.manager_template import *
+ >>> id = getRootFolder()._setObject("manfred", Mammoth(id='manfred'))
+
+ >>> from Products.Five.testbrowser import Browser
+ >>> browser = Browser()
+ >>> browser.handleErrors = False
+ >>> browser.open("http://localhost/manfred/@@painting")
+ >>> print browser.contents
+ <html>
+ <body>
+ <p>Moderne art is sometimes <b>special</b></p>
+ </body>
+ </html>
+
+"""
+from five import grok
+
+class Mammoth(grok.Model):
+ pass
+
+class Painting(grok.View):
+ pass
+
+class Art(grok.ViewletManager):
+
+ grok.view(Painting)
+
+painting = grok.PageTemplate("""\
+<html>
+<body>
+<tal:replace tal:replace="structure provider:art" />
+</body>
+</html>
+""")
+
+art = grok.PageTemplate("""\
+<p>Moderne art is sometimes <b>special</b></p>
+""")
Added: five.grok/branches/sylvain-viewlets/src/five/grok/ftests/viewlet/security.py
===================================================================
--- five.grok/branches/sylvain-viewlets/src/five/grok/ftests/viewlet/security.py (rev 0)
+++ five.grok/branches/sylvain-viewlets/src/five/grok/ftests/viewlet/security.py 2008-10-27 00:14:30 UTC (rev 92608)
@@ -0,0 +1,53 @@
+"""
+ >>> from five.grok.ftests.viewlet.security import *
+ >>> id = getRootFolder()._setObject("manfred", Mammoth(id='manfred'))
+
+ >>> from Products.Five.testbrowser import Browser
+ >>> browser = Browser()
+ >>> browser.handleErrors = False
+ >>> browser.open("http://localhost/manfred/@@painting")
+ >>> print browser.contents
+ <html>
+ <body>
+ <p>A common gallery with rembrandt</p>
+ </body>
+ </html>
+
+"""
+from five import grok
+
+class Mammoth(grok.Model):
+ pass
+
+class Painting(grok.View):
+ pass
+
+painting = grok.PageTemplate("""\
+<html>
+<body>
+<tal:replace tal:replace="structure provider:museum" />
+</body>
+</html>
+""")
+
+class Museum(grok.ViewletManager):
+
+ grok.view(Painting)
+
+
+class Gallery(grok.Viewlet):
+
+ grok.view(Painting)
+ grok.viewletmanager(Museum)
+
+ def render(self):
+ return u'<p>A common gallery with rembrandt</p>'
+
+class Reserve(grok.Viewlet):
+
+ grok.view(Painting)
+ grok.viewletmanager(Museum)
+ grok.require('zope2.ViewManagementScreens')
+
+ def render(self):
+ return u'<p>Non exposed content</p>'
Added: five.grok/branches/sylvain-viewlets/src/five/grok/ftests/viewlet/simple.py
===================================================================
--- five.grok/branches/sylvain-viewlets/src/five/grok/ftests/viewlet/simple.py (rev 0)
+++ five.grok/branches/sylvain-viewlets/src/five/grok/ftests/viewlet/simple.py 2008-10-27 00:14:30 UTC (rev 92608)
@@ -0,0 +1,64 @@
+"""
+ >>> from five.grok.ftests.viewlet.simple import *
+ >>> id = getRootFolder()._setObject("manfred", Mammoth(id='manfred'))
+
+ >>> from Products.Five.testbrowser import Browser
+ >>> browser = Browser()
+ >>> browser.handleErrors = False
+ >>> browser.open("http://localhost/manfred/@@painting")
+ >>> print browser.contents
+ <html>
+ <body>
+ <h2>Modern Art</h2>
+ <h2>Classic Art</h2>
+ </body>
+ </html>
+
+"""
+from five import grok
+
+class Mammoth(grok.Model):
+ pass
+
+class Painting(grok.View):
+ pass
+
+painting = grok.PageTemplate("""\
+<html>
+<body>
+<tal:replace tal:replace="structure provider:art" />
+<tal:replace tal:replace="structure provider:nothing" />
+</body>
+</html>
+""")
+
+class Art(grok.ViewletManager):
+
+ grok.view(Painting)
+
+
+class Nothing(grok.ViewletManager):
+
+ grok.view(Painting)
+
+
+class Modern(grok.Viewlet):
+
+ grok.order(10)
+ grok.view(Painting)
+ grok.viewletmanager(Art)
+
+
+modern = grok.PageTemplate("""\
+<h2>Modern Art</h2>
+""")
+
+class Classic(grok.Viewlet):
+
+ grok.order(20)
+ grok.view(Painting)
+ grok.viewletmanager(Art)
+
+classic = grok.PageTemplate("""\
+<h2>Classic Art</h2>
+""")
Added: five.grok/branches/sylvain-viewlets/src/five/grok/ftests/viewlet/simple2.py
===================================================================
--- five.grok/branches/sylvain-viewlets/src/five/grok/ftests/viewlet/simple2.py (rev 0)
+++ five.grok/branches/sylvain-viewlets/src/five/grok/ftests/viewlet/simple2.py 2008-10-27 00:14:30 UTC (rev 92608)
@@ -0,0 +1,53 @@
+"""
+ >>> from five.grok.ftests.viewlet.simple2 import *
+ >>> id = getRootFolder()._setObject("manfred", Mammoth(id='manfred'))
+
+ >>> from Products.Five.testbrowser import Browser
+ >>> browser = Browser()
+ >>> browser.handleErrors = False
+ >>> browser.open("http://localhost/manfred/@@painting")
+ >>> print browser.contents
+ <html>
+ <body>
+ <p>Classic art is not recent.</p>
+ <p>Mordern art is recent</p>
+ </body>
+ </html>
+
+"""
+from five import grok
+
+class Mammoth(grok.Model):
+ pass
+
+class Painting(grok.View):
+ pass
+
+painting = grok.PageTemplate("""\
+<html>
+<body>
+<tal:replace tal:replace="structure provider:art" />
+</body>
+</html>
+""")
+
+class Art(grok.ViewletManager):
+
+ grok.view(Painting)
+
+class Modern(grok.Viewlet):
+
+ grok.view(Painting)
+ grok.viewletmanager(Art)
+
+ def render(self):
+ return u'<p>Mordern art is recent</p>'
+
+class Classic(grok.Viewlet):
+
+ grok.view(Painting)
+ grok.viewletmanager(Art)
+
+classic = grok.PageTemplate("""\
+<p>Classic art is not recent.</p>
+""")
Modified: five.grok/branches/sylvain-viewlets/src/five/grok/meta.py
===================================================================
--- five.grok/branches/sylvain-viewlets/src/five/grok/meta.py 2008-10-26 20:41:03 UTC (rev 92607)
+++ five.grok/branches/sylvain-viewlets/src/five/grok/meta.py 2008-10-27 00:14:30 UTC (rev 92608)
@@ -109,11 +109,12 @@
callable = protectClass,
args = (factory, permission)
)
- config.action(
- discriminator = ('five:protectName', factory, attributes),
- callable = protectname,
- args = (factory, attributes, permission)
- )
+ for attribute in attributes:
+ config.action(
+ discriminator = ('five:protectName', factory, attribute),
+ callable = protectName,
+ args = (factory, attribute, permission)
+ )
# Protect the class
config.action(
More information about the Checkins
mailing list