How to use the grok.context 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 / 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 / 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)
github zopefoundation / grok / src / grok / ftests / url / application.py View on Github external
@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'})
github zopefoundation / grok / src / grok / ftests / rest / rest.py View on Github external
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):
github zopefoundation / grok / src / grok / admin / view.py View on Github external
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())