How to use grok - 10 common examples

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 / form / form.py View on Github external
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>
github zopefoundation / grok / src / grok / ftests / form / update.py View on Github external
"""
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:
github zopefoundation / grok / src / grok / ftests / form / form.py View on Github external
Same for the edit form::

  &gt;&gt;&gt; browser.open('http://localhost/world/arthur/@@edit')
  &gt;&gt;&gt; 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):
github zopefoundation / grok / src / grok / ftests / form / templateform.py View on Github external
"""
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')
github zopefoundation / grok / src / grok / ftests / admin / macros.py View on Github external
&gt;&gt;&gt; browser.open('http://localhost/applications')
  &gt;&gt;&gt; ctrl = browser.getControl(name='items')
  &gt;&gt;&gt; ctrl.getControl(value='manfred').selected = True
  &gt;&gt;&gt; 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 / lifecycle / lifecycle_events.py View on Github external
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)
github zopefoundation / grok / src / grok / ftests / security / roles.py View on Github external
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.'
github zopefoundation / grok / src / grok / ftests / traversal / items_before_views.py View on Github external
# 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()
github zopefoundation / grok / src / grok / ftests / catalog / indexes_nonexistent.py View on Github external
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 / src / grok / ftests / viewlet / viewlet_security.py View on Github external
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)