class DirectoryItemViewlet(grok.Viewlet): grok.context(IDirectoryItemBase) grok.name('seantis.dir.base.item.detail') grok.require('zope2.View') grok.viewletmanager(DirectoryItemViewletManager) template = grok.PageTemplate(u'<p tal:content="context/description" />')
""" 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)
</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):
<body> <h1>Hello, world!</h1> Color: <span>Blue</span> Color: <span>Blue</span> URL: <span>http://localhost/manfred/index</span> </body> </html> """ from five import grok class Mammoth(grok.Model): teeth = u"Blue" class Index(grok.View): pass index = grok.PageTemplate("""\ <html> <body> <h1>Hello, world!</h1> Color: <span tal:content="python:context.teeth">green</span> Color: <span tal:content="context/teeth">green</span> URL: <span tal:content="view/url">url</span> </body> </html> """)
>>> browser.open("http://localhost/manfred/update?another=Bar") Traceback (most recent call last): ... TypeError: Missing argument to update(): message """ from five import grok class Mammoth(grok.Model): pass class RenderWithArguments(grok.View): grok.name('render') def render(self, message, another): return "Message: %s\nAnother: %s" % (message, another) class UpdateWithArguments(grok.View): grok.name('update') grok.template('update') def update(self, message, another): self.message = message self.another = another update = grok.PageTemplate(filename="test.pt")
""" 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)
class MyRotterdamLayer(MySkinLayer): grok.skin('Rotterdam') class Mammoth(grok.Model): pass class CaveDrawings(grok.View): pass cavedrawings = grok.PageTemplate("""\ <html> <body> <h1>Hello, world!</h1> </body> </html> """) class MoreDrawings(grok.View): grok.layer(MyRotterdamLayer) def render(self): return "Pretty" class EvenMoreDrawings(grok.View): grok.layer(MySkinLayer)
pass class Grilled(grok.View): def update(self): self.spices = "Pepper and salt" class Painting(grok.View): pass painting = grok.PageTemplate("""\ <html metal:use-macro="context/@@layout/macros/main"> <div metal:fill-slot="slot"> GROK SLOT! </div> </html> """) class Layout(grok.View): pass layout = grok.PageTemplate("""\ <html metal:define-macro="main"> <body> <h1>GROK MACRO!</h1> <div metal:define-slot="slot"> </div>
</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> """)
>>> from Testing.testbrowser import Browser >>> browser = Browser() >>> browser.handleErrors = False >>> browser.open("http://localhost/manfred/@@painting") >>> print browser.contents <html> <body> <h1>Hello, world manfred!</h1> </body> </html> """ from five import grok class Mammoth(grok.Model): pass class Painting(grok.View): pass painting = grok.PageTemplate("""\ <html> <body> <h1>Hello, world <tal:replace tal:replace="here/getId" />!</h1> </body> </html> """)
>>> browser.open("http://localhost/manfred") >>> print browser.contents <html> <body> <h1>Hello I am manfred!</h1> </body> </html> """ from five import grok class Mammoth(grok.Model): def __init__(self, id): super(Mammoth, self).__init__(id) self.id = id class Index(grok.View): def namespace(self): return {'name': self.context.id} index = grok.PageTemplate("""\ <html> <body> <h1>Hello I am <tal:name tal:replace="name" />!</h1> </body> </html> """)