How to use the grok.Container function in grok

To help you get started, we’ve selected a few grok examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zopefoundation / grok / src / grok / ftests / security / grok_view.py View on Github external
>>> root = getRootFolder()
  >>> root['app'] = App()

Now we can look at the view::

  >>> from zope.testbrowser.wsgi import Browser
  >>> browser = Browser()
  >>> browser.handleErrors = False
  >>> browser.open('http://localhost/app/@@index')
  >>> print(browser.contents)
  Hello world

"""
import grok

class App(grok.Application, grok.Container):
    pass

class Index(grok.View):
    def render(self):
        return "Hello world"
github zopefoundation / grok / src / grok / ftests / catalog / indexes_multiple.py View on Github external
>>> from zope.app.intid.interfaces import IIntIds
  >>> from zope import component
  >>> intids = component.getUtility(IIntIds)
  >>> sm.unregisterUtility(intids, provided=IIntIds)
  True

Unfortunately ftests don't have good isolation from each other yet.
"""

from zope.interface import Interface
from zope import schema

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 IMammoth2(Interface):
    name2 = schema.TextLine(title=u'Name')
    age2 = schema.Int(title=u'Age')
    def message2():
        """Message the mammoth has for the world."""

class MammothIndexes(grok.Indexes):
    grok.site(Herd)
github zopefoundation / grok / src / grok / ftests / site / site.py View on Github external
>>> nonsitecontainer['manfred'] = manfred
  >>> ISite.providedBy(manfred)
  True
  >>> nonsitecontainer['herd'] = herd
  >>> ISite.providedBy(herd)
  True
"""
import grok


class Mammoth(grok.Model, grok.Site):
    pass


class Herd(grok.Container, grok.Site):
    pass


class NonSite(grok.Model):
    pass


class NonSiteContainer(grok.Container):
    pass
github zopefoundation / grok / src / grok / ftests / catalog / indexes_site.py View on Github external
>>> sm.unregisterUtility(catalog, provided=ICatalog)
  True
  >>> from zope.app.intid.interfaces import IIntIds
  >>> from zope import component
  >>> intids = component.getUtility(IIntIds)
  >>> sm.unregisterUtility(intids, provided=IIntIds)
  True
"""

from zope.interface import Interface
from zope import schema

import grok
from grok import index

class Herd(grok.Container, grok.Site):
    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)

    name = index.Field()
    age = index.Field()
    message = index.Text()
github zopefoundation / grok / src / grok / ftests / traversal / containertraverser.py View on Github external
<h1>Hello, Ellie!</h1>
  
  

Also try traversing (an empty and therefore False in a Boolean sense) container
as a subitem of a container:

  &gt;&gt;&gt; herd['subherd'] = Herd()
  &gt;&gt;&gt; browser.open("http://localhost/herd/subherd/special")
  &gt;&gt;&gt; print(browser.contents)
  special view

"""
import grok

class Herd(grok.Container):
    pass

class Traverser(grok.Traverser):
    grok.context(Herd)
    def traverse(self, name):
        if name == 'special':
            return Special()
        return None

class Mammoth(grok.Model):
    def __init__(self, name):
        self.name = name

class Special(grok.Model):
    pass
github zopefoundation / grok / src / grok / ftests / catalog / addform.py View on Github external
>>> print browser.contents
  We found Ellie!

"""
import grok
from zope import schema, interface, component
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 Zoo(grok.Site, grok.Container):
    grok.local_utility(IntIds, provides=IIntIds)
    grok.local_utility(Catalog, provides=ICatalog, setup=setup_catalog)

class IMammoth(interface.Interface):
    name = schema.TextLine(title=u"Name")
    size = schema.TextLine(title=u"Size")

class Mammoth(grok.Model):
    grok.implements(IMammoth)

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)
github zopefoundation / grok / src / grok / ftests / catalog / indexes_app_interface.py View on Github external
from zope.interface import Interface
from zope import schema

import grok
from grok import index


class IHerd(Interface):
    pass


class Herd(grok.Container, grok.Application):
    grok.implements(IHerd)


class Herd2(grok.Container, grok.Application):
    grok.implements(IHerd)


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(IHerd)
    grok.context(IMammoth)

    name = index.Field()
    age = index.Field()