Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
size = schema.TextLine(title=u"Size", default=u"Quite normal")
class Index(grok.DisplayForm):
grok.context(Mammoth)
index = grok.PageTemplate("""
<p>
Test display: application
</p>""")
class Edit(grok.EditForm):
grok.context(Mammoth)
edit = grok.PageTemplate("""
<p></p>
"""
import grok
from zope import schema
from zope.interface import Interface, implements
class IMammoth(Interface):
name = schema.TextLine(title=u"Name")
class Mammoth(grok.Model):
implements(IMammoth)
name = u'Manfred'
class Index(grok.View):
def render(self):
return "%s, the Mammoth reports: %s" % (self.context.name,
self.context.report)
class Edit(grok.EditForm):
def update(self):
self.context.report = ("The form's update() was called and my name "
"was %s." % self.context.name)
class EditRedirect(grok.EditForm):
def update(self):
# redirect upon form submit so that no changes are ever saved
if 'form.name' in self.request:
Same for the edit form::
>>> browser.open('http://localhost/world/arthur/@@edit')
>>> print(browser.contents)
<p> Test edit: application http://localhost/world </p>
"""
import grok
from zope import schema
class IceWorld(grok.Application, grok.Container):
pass
class Mammoth(grok.Model):
class fields:
name = schema.TextLine(title=u"Name")
size = schema.TextLine(title=u"Size", default=u"Quite normal")
class Index(grok.DisplayForm):
grok.context(Mammoth)
index = grok.PageTemplate("""
<p>
Test display: application
</p>""")
class Edit(grok.EditForm):
"""
import grok
from zope import schema
class Mammoth(grok.Model):
class fields:
name = schema.TextLine(title=u"Name")
size = schema.TextLine(title=u"Size", default=u"Quite normal")
class Edit(grok.EditForm):
pass
class Edit2(grok.EditForm):
pass
edit2 = grok.PageTemplate('<p>Test edit</p>')
class Edit3(grok.EditForm):
grok.template('edit2')
class Display(grok.DisplayForm):
pass
class Display2(grok.DisplayForm):
pass
display2 = grok.PageTemplate('<p>Test display</p>')
class Display3(grok.DisplayForm):
grok.template('display2')
>>> browser.open('http://localhost/applications')
>>> ctrl = browser.getControl(name='items')
>>> ctrl.getControl(value='manfred').selected = True
>>> browser.getControl('Delete Selected').click()
"""
import grok
class Mammoth(grok.Application, grok.Container):
pass
class ExternalView(grok.View):
"""A view that calls grokadminmacros 'illegally'.
"""
grok.context(Mammoth)
externalview = grok.PageTemplate("""\
from zope.schema import TextLine
from zope.interface import Interface
from zope.component import queryUtility
from zope.catalog.interfaces import ICatalog
class Herd(grok.Container, grok.Application):
pass
class IPachyderm(Interface):
tusks = TextLine(title=u"About the tusks")
class TuskIndex(grok.Indexes):
grok.context(IPachyderm)
grok.site(Herd)
tusks = index.Text()
@grok.subscribe(Herd, grok.IObjectAddedEvent)
@grok.subscribe(Herd, grok.IApplicationAddedEvent)
def CatalogTester(application, event):
catalog = queryUtility(ICatalog, context=application)
if catalog is None:
print("Catalog can not be found !")
else:
print(catalog)
grok.require(EditPermission)
def render(self):
return 'Let\'s make it even prettier.'
class EraseCavePainting(grok.View):
grok.context(zope.interface.Interface)
grok.require(ErasePermission)
def render(self):
return 'Oops, mistake, let\'s erase it.'
class ApproveCavePainting(grok.View):
grok.context(zope.interface.Interface)
grok.require(ApprovePermission)
def render(self):
return 'Painting owners cannot approve their paintings.'
# the fallback behaviour
pass
class Ellie(grok.View):
grok.context(Herd)
grok.name('ellie')
def render(self):
return "Hi, it's me, the Ellie view!"
class Mammoth(grok.Model):
def __init__(self, name):
self.name = name
class MammothIndex(grok.View):
grok.context(Mammoth)
grok.name('index')
def render(self):
return "Hello " + self.context.name.title()
import grok
from grok import index
class Herd(grok.Container, grok.Application):
pass
class IMammoth(Interface):
name = schema.TextLine(title=u'Name')
age = schema.Int(title=u'Age')
def message():
"""Message the mammoth has for the world."""
class MammothIndexes(grok.Indexes):
grok.site(Herd)
grok.context(IMammoth)
foo = index.Field()
class Gold(grok.Permission):
grok.name('bone.gold')
class CaveWoman(grok.Model):
pass
class CaveMan(grok.Model):
pass
class CaveView(grok.View):
grok.context(Interface)
class FireView(grok.View):
grok.context(Interface)
grok.template('caveview')
class Pot(grok.ViewletManager):
grok.context(Interface)
grok.name('pot')
class TRexBone(grok.Viewlet):
grok.context(Interface)
grok.viewletmanager(Pot)
def render(self):
return "T-Rex Bone"
class BrackerBone(grok.Viewlet):
grok.context(Interface)
grok.viewletmanager(Pot)