How to use the grok.Model 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
Same for the edit form::

  >>> browser.open('http://localhost/world/arthur/@@edit')
  >>> 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 / catalog / setuporder.py View on Github external
import grok
from zope import schema, interface
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 IMammoth(interface.Interface):

    name = schema.TextLine()

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

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

class BaseHerd(grok.Container, grok.Site):
    grok.local_utility(IntIds, provides=IIntIds)

class Herd(BaseHerd):
    grok.local_utility(Catalog, provides=ICatalog, setup=setup_catalog)
github zopefoundation / grok / src / grok / ftests / traversal / traverser.py View on Github external
"""
import grok

class Herd(grok.Model):

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

class HerdTraverser(grok.Traverser):
    grok.context(Herd)

    def traverse(self, name):
        return Mammoth(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 / catalog / indexes_set.py View on Github external
import grok
from grok import index

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

class IMammoth(Interface):
    features = Attribute('Features')

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

    features = index.Set()

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

    def __init__(self, name, features):
        self.name = name
        self.features = features
github zopefoundation / grok / src / grok / ftests / url / application.py View on Github external
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)

    def render(self):
        return self.application_url('third', skin=IMammothSkin)

class Fourth(grok.View):
github zopefoundation / grok / src / grok / ftests / form / addform.py View on Github external
>>> print browser.contents
  Hi, my name is Ellie the Mammoth, and I\'m "Really small"

"""
import grok
from zope import schema
from zope.interface import Interface, implements

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)
github zopefoundation / grok / src / grok / ftests / catalog / indexes.py View on Github external
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()

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

    def __init__(self, name, age, message):
        self.name = name
        self.age = age
        self._message = message

    def message(self):
        return self._message
github zopefoundation / grok / src / grok / ftests / viewlet / order.py View on Github external
viewletmanager to override the sort() method::

  &gt;&gt;&gt; from zope.testbrowser.testing import Browser
  &gt;&gt;&gt; browser = Browser()
  &gt;&gt;&gt; browser.handleErrors = False
  &gt;&gt;&gt; browser.open("http://localhost/fred/@@orderview2")
  &gt;&gt;&gt; print browser.contents
  Cave
  Barney
  

"""

import grok

class Fred(grok.Model):
    pass

class OrderView(grok.View):
    pass

class CaveManager(grok.ViewletManager):
    grok.view(OrderView)
    grok.name('cave')

class CaveViewlet(grok.Viewlet):
    grok.order(30)
    grok.viewletmanager(CaveManager)

    def render(self):
        return "Cave"
github zopefoundation / grok / src / grok / ftests / view / view.py View on Github external
&gt;&gt;&gt; from zope.testbrowser.testing import Browser
  &gt;&gt;&gt; browser = Browser()
  &gt;&gt;&gt; browser.handleErrors = False
  &gt;&gt;&gt; browser.open("http://localhost/manfred/@@painting")
  &gt;&gt;&gt; print browser.contents
  
  
  <h1>Hello, world!</h1>
  
  

"""
import grok

class Mammoth(grok.Model):
    pass

class Painting(grok.View):
    pass

painting = grok.PageTemplate("""\
github zopefoundation / grok / grokblog / src / grokblog / entry.py View on Github external
from datetime import datetime
from docutils.core import publish_parts

from zope import schema, interface

import grok

from grokblog.blog import Blog
from grokblog import interfaces

class Entry(grok.Model):
    interface.implements(interfaces.IEntry)

    def __init__(self, title, summary, rightsinfo):
        self.title = title
        self.updated = datetime.now()
        self.published = datetime.now()
        self.summary = summary
        self.rightsinfo = rightsinfo
        
class RestructuredTextEntry(Entry):
    interface.implements(interfaces.IRestructuredTextEntry)

    def __init__(self, title, summary, rightsinfo, content):
        super(RestructuredTextEntry, self).__init__(title, summary, rightsinfo)
        self.content = content