How to use the grok.Application 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 / catalog / indexes_no_app.py View on Github external
special indexes declaration.  We do need to specify a site (such as
the application) for the Indexes however, otherwise we get a GrokError:

  >>> import grok
  >>> grok.grok('grok.ftests.catalog.indexes_no_app')
  Traceback (most recent call last):
    ...
  GrokError: No site specified for grok.Indexes subclass in module
  .
  Use grok.site() to specify.
  
"""
import grok
from grok import index

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

class Mammoth(grok.Model):
    pass

class MammothIndexes(grok.Indexes):
    grok.context(Mammoth)
    grok.name('foo_catalog')
    
    name = index.Field()
    age = index.Field()
    message = index.Text()
github zopefoundation / grok / src / grok / ftests / url / application.py View on Github external
pass

class Index(grok.View):
    grok.context(IMarker)

    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)
github zopefoundation / grok / src / grok / ftests / lifecycle / create_application.py View on Github external
Traceback (most recent call last):
  ...
  zope.schema._bootstrapinterfaces.WrongType: 

"""
from __future__ import print_function
import grok


class Mammoth(grok.Model):
    """A furry creature with tusks.
    """
    pass


class Cave(grok.Container, grok.Application):
    """A shelter for homeless cavemen.
    """
    pass


@grok.subscribe(Cave, grok.IObjectCreatedEvent)
@grok.subscribe(Cave, grok.IObjectAddedEvent)
@grok.subscribe(Cave, grok.IApplicationAddedEvent)
def EventPrinter(application, event):
    print(application.__class__.__name__, event)
github zopefoundation / grok / src / grok / ftests / catalog / indexes_attribute.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.Application):
    pass

class IMammoth(Interface):
    name = schema.TextLine(title=u'Name')
    age = schema.Int(title=u'Age')

class MammothIndexes(grok.Indexes):
    grok.site(Herd)
    grok.context(IMammoth)

    name = index.Field()
    how_old = index.Field(attribute='age')

class Mammoth(grok.Model):
    grok.implements(IMammoth)
github zopefoundation / grok / src / grok / ftests / security / security_view.py View on Github external
>>> from zope.interface import classImplements
  >>> import grokcore.view
  >>> classImplements(Index, grokcore.view.IGrokSecurityView)

Now we can watch the view::

  >>> browser.open('http://localhost/app/@@index')
  >>> print(browser.contents)
  Hello from index

"""
import grok
from zope.publisher.browser import BrowserPage

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

class Index(BrowserPage):
    def __call__(self):
        return 'Hello from index'
github zopefoundation / grok / src / grok / ftests / catalog / indexes.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 Herd2(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)

    name = index.Field()
github zopefoundation / grok / src / grok / ftests / admin / macros.py View on Github external
...

So developers get informed, that they called the wrong macro view.

Let's clean up.

  >>> 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("""\
github zopefoundation / grok / src / grok / ftests / catalog / indexes_nonexistent.py View on Github external
>>> sm.unregisterUtility(catalog, provided=ICatalog)
  True
  >>> from zope.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.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()
github zopefoundation / grok / doc / groktut / the_rules_of_persistence / src / sample / app.py View on Github external
import grok

class Sample(grok.Application, grok.Container):
    def __init__(self):
        super(Sample, self).__init__()
        self.list = []
    
class Index(grok.View):
    pass

class Edit(grok.View):
    def update(self, text=None):
        if text is None:
            return
        # this code has a BUG!
        self.context.list.append(text)
        self.redirect(self.url('index'))
github zopefoundation / grok / doc / groktut / making_our_page_dynamic / src / sample / app.py View on Github external
import grok

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

class Index(grok.View):
    pass