How to use the grok.View 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 / 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 / url / application.py View on Github external
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):
    grok.context(IMarker)

    def render(self):
        return self.application_url(
            'fourth', skin=IMammothSkin, data={'key': 'value'})
github zopefoundation / grok / src / grok / ftests / template / language_file.py View on Github external
class PercentPageTemplateFileFactory(grok.GlobalUtility):
    """Glue class suggested by doc/minitutorials/template-languages.txt."""
    
    grok.implements(grok.interfaces.ITemplateFileFactory)
    grok.name('pct')

    def __call__(self, filename, _prefix=None):
        return PercentPageTemplate(filename=filename, _prefix=_prefix)


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

class Index(grok.View):
    def namespace(self):
        return { 'bear_name': self.context.name }

index = PercentPageTemplate(filename='language_file.txt',
                            _prefix=os.path.dirname(__file__))
github zopefoundation / grok / src / grok / ftests / url / redirect.py View on Github external
>>> browser.handleErrors = False
  >>> browser.open('http://localhost/manfred')
  >>> browser.url
  'http://localhost/manfred/another'
  
"""
import grok

class Mammoth(grok.Model):
    pass

class Index(grok.View):
    def render(self):
        self.redirect(self.url('another'))

class Another(grok.View):
    def render(self):
        return "Another view"
github zopefoundation / grok / src / grok / ftests / form / addform.py View on Github external
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)

    @grok.action('Add entry')
    def add(self, **data):
        # pass data into Mammoth constructor
        self.context['manfred'] = manfred = Mammoth(**data)
        self.redirect(self.url(manfred))
github zopefoundation / grok / src / grok / ftests / view / index.py View on Github external
>>> print browser.contents
  
  
  <h1>Hello, world!</h1>
  <span>Blue</span>
  <span>Blue</span>
  
  

"""
import grok

class Mammoth(grok.Model):
    teeth = u"Blue"

class Index(grok.View):
    pass

index = grok.PageTemplate("""\
github zopefoundation / grok / src / grok / ftests / traversal / modeltraverse.py View on Github external
self.name = name

    def getMammoth(self, name):
        return Mammoth(name)

    def traverse(self, name):
        return self.getMammoth(name)

class Mammoth(grok.Model):

    def __init__(self, name):
        self.name = name

grok.context(Mammoth)

class Index(grok.View):
    pass

index = grok.PageTemplate("""\
github zopefoundation / grok / src / grok / ftests / security / handle_exception.py View on Github external
Traceback (most recent call last):
  urllib.error.HTTPError: HTTP Error 500: Internal Server Error
  >>> browser.contents
  'It is gone!'

"""

import grok
from zope.interface import Interface


class CaveWasRobbedError(Exception):
    pass


class Cave(grok.View):
    """Home of Grok.
    """
    grok.context(Interface)

    fire = 'It is gone!'

    def render(self):
        raise CaveWasRobbedError("EVERYTHING GONE! GROK ANGRY!")


class CaveErrorView(grok.View):
    """Default view for the CaveWasRobbedError.
    """
    grok.name("index")
    grok.context(CaveWasRobbedError)
github zopefoundation / grok / src / grok / ftests / security / roles.py View on Github external
grok.context(zope.interface.Interface)
    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 / 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