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>
>>> 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)
@grok.implementer(IMarker)
class Corridors(grok.Container):
pass
class IMammothSkin(IDefaultBrowserLayer):
grok.skin('mammothskin')
class Third(grok.View):
grok.context(IMarker)
def render(self):
return self.application_url('third', skin=IMammothSkin)
class Fourth(grok.View):
grok.context(IMarker)
def render(self):
return self.application_url(
'fourth', skin=IMammothSkin, data={'key': 'value'})
class CRest(grok.REST):
grok.layer(LayerC)
grok.context(MyApp)
def some_method_thats_not_in_HTTP(self):
pass
class DRest(grok.REST):
grok.context(MyContent)
def GET(self):
return "GET2"
class SecurityRest(grok.REST):
grok.context(MyContent)
grok.layer(LayerSecurity)
@grok.require(grok.Public)
def GET(self):
return "GET3"
@grok.require('zope.ManageContent')
def POST(self):
return "POST3"
@grok.require('zope.ManageContent')
def PUT(self):
return "PUT3"
@grok.require('zope.ManageContent')
def DELETE(self):
class DocGrokInterfaceView(DocGrokClassView):
grok.context(DocGrokInterface)
grok.name('index')
class DocGrokGrokApplicationView(DocGrokClassView):
grok.context(DocGrokGrokApplication)
grok.name('index')
class DocGrokTextFileView(DocGrokView):
grok.context(DocGrokTextFile)
grok.name('index')
def getContent(self):
lines = self.context.getContent()
if self.context.path.endswith('.stx'):
format = 'zope.source.stx'
else:
format = 'zope.source.rest'
return renderText(lines, format=format)
def getPackagePathParts(self):
return self.getPathParts(
self.context.getPackagePath())