Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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, interface
from zope.intid import IntIds
from zope.intid.interfaces import IIntIds
from zope.catalog.catalog import Catalog
from zope.catalog.interfaces import ICatalog
from zope.catalog.field import FieldIndex
def setup_catalog(catalog):
catalog['name'] = FieldIndex('name', IMammoth)
class IMammoth(interface.Interface):
name = schema.TextLine()
class Mammoth(grok.Model):
grok.implements(IMammoth)
def __init__(self, name):
self.name = name
class BaseHerd(grok.Container, grok.Site):
grok.local_utility(IntIds, provides=IIntIds)
class Herd(BaseHerd):
grok.local_utility(Catalog, provides=ICatalog, setup=setup_catalog)
"""
import grok
class Herd(grok.Model):
def __init__(self, name):
self.name = name
class HerdTraverser(grok.Traverser):
grok.context(Herd)
def traverse(self, name):
return Mammoth(name)
class Mammoth(grok.Model):
def __init__(self, name):
self.name = name
grok.context(Mammoth)
class Index(grok.View):
pass
index = grok.PageTemplate("""\
import grok
from grok import index
class Herd(grok.Container, grok.Application):
pass
class IMammoth(Interface):
features = Attribute('Features')
class MammothIndexes(grok.Indexes):
grok.site(Herd)
grok.context(IMammoth)
features = index.Set()
class Mammoth(grok.Model):
grok.implements(IMammoth)
def __init__(self, name, features):
self.name = name
self.features = features
def render(self):
return self.application_url()
class Second(grok.View):
grok.context(IMarker)
def render(self):
return self.application_url('second')
@grok.implementer(IMarker)
class Cave(grok.Application, grok.Container):
pass
@grok.implementer(IMarker)
class CaveMan(grok.Model):
pass
@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):
>>> print browser.contents
Hi, my name is Ellie the Mammoth, and I\'m "Really small"
"""
import grok
from zope import schema
from zope.interface import Interface, implements
class Zoo(grok.Container):
pass
class IMammoth(Interface):
name = schema.TextLine(title=u"Name")
size = schema.TextLine(title=u"Size", default=u"Quite normal")
class Mammoth(grok.Model):
implements(IMammoth)
def __init__(self, name='', size=''):
self.name = name
self.size = size
class Index(grok.View):
grok.context(Mammoth)
def render(self):
return 'Hi, my name is %s, and I\'m "%s"' % (self.context.name,
self.context.size)
class AddMammoth(grok.AddForm):
grok.context(Zoo)
form_fields = grok.AutoFields(Mammoth)
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)
name = index.Field()
age = index.Field()
message = index.Text()
class Mammoth(grok.Model):
grok.implements(IMammoth)
def __init__(self, name, age, message):
self.name = name
self.age = age
self._message = message
def message(self):
return self._message
viewletmanager to override the sort() method::
>>> from zope.testbrowser.testing import Browser
>>> browser = Browser()
>>> browser.handleErrors = False
>>> browser.open("http://localhost/fred/@@orderview2")
>>> print browser.contents
Cave
Barney
"""
import grok
class Fred(grok.Model):
pass
class OrderView(grok.View):
pass
class CaveManager(grok.ViewletManager):
grok.view(OrderView)
grok.name('cave')
class CaveViewlet(grok.Viewlet):
grok.order(30)
grok.viewletmanager(CaveManager)
def render(self):
return "Cave"
>>> from zope.testbrowser.testing import Browser
>>> browser = Browser()
>>> browser.handleErrors = False
>>> browser.open("http://localhost/manfred/@@painting")
>>> print browser.contents
<h1>Hello, world!</h1>
"""
import grok
class Mammoth(grok.Model):
pass
class Painting(grok.View):
pass
painting = grok.PageTemplate("""\
from datetime import datetime
from docutils.core import publish_parts
from zope import schema, interface
import grok
from grokblog.blog import Blog
from grokblog import interfaces
class Entry(grok.Model):
interface.implements(interfaces.IEntry)
def __init__(self, title, summary, rightsinfo):
self.title = title
self.updated = datetime.now()
self.published = datetime.now()
self.summary = summary
self.rightsinfo = rightsinfo
class RestructuredTextEntry(Entry):
interface.implements(interfaces.IRestructuredTextEntry)
def __init__(self, title, summary, rightsinfo, content):
super(RestructuredTextEntry, self).__init__(title, summary, rightsinfo)
self.content = content