How to use the grok.implements 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 / utility / local.py View on Github external
pass

class IClub(interface.Interface):
    pass

class ISpiky(interface.Interface):
    pass

class IMammoth(interface.Interface):
    pass

class Fireplace(grok.LocalUtility):
    grok.implements(IFireplace)

class Club(object):
    grok.implements(IClub)

class SpikyClub(object):
    grok.implements(IClub, ISpiky)

class Mammoth(grok.LocalUtility):
    grok.implements(IMammoth, IClub)

class SabretoothTiger(grok.LocalUtility):
    grok.implements(IMammoth, IClub)
    grok.provides(IMammoth)

class IPainting(persistent.interfaces.IPersistent):
    pass

class CavePainting(grok.LocalUtility):
    grok.implements(IPainting)
github zopefoundation / grok / src / grok / ftests / utility / local.py View on Github external
pass

class Fireplace(grok.LocalUtility):
    grok.implements(IFireplace)

class Club(object):
    grok.implements(IClub)

class SpikyClub(object):
    grok.implements(IClub, ISpiky)

class Mammoth(grok.LocalUtility):
    grok.implements(IMammoth, IClub)

class SabretoothTiger(grok.LocalUtility):
    grok.implements(IMammoth, IClub)
    grok.provides(IMammoth)

class IPainting(persistent.interfaces.IPersistent):
    pass

class CavePainting(grok.LocalUtility):
    grok.implements(IPainting)

class ColoredCavePainting(grok.LocalUtility):
    grok.implements(IPainting)
    grok.provides(IPainting)

class Cave(grok.Model, grok.Site):
    grok.local_utility(Fireplace)
    grok.local_utility(Club)
    grok.local_utility(SpikyClub, provides=IClub, name='spiky')
github zopefoundation / grok / src / grok / ftests / catalog / indexes_set.py View on Github external
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 / template / language_file.py View on Github external
"""Glue class suggested by doc/minitutorials/template-languages.txt."""

    def fromTemplate(self, template):
        return PercentTemplate(template)

    def fromFile(self, filename, _prefix=None):
        file = open(os.path.join(_prefix, filename))
        return PercentTemplate(file.read())

    def render(self, view):
        return self.getTemplate().render(**self.getNamespace(view))

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 / rest / rest.py View on Github external
class BodyTest(grok.REST):
    grok.context(MyContent)
    grok.layer(LayerContent)

    def POST(self):
        return self.body

    def PUT(self):
        return self.body

class MyInterfaceContent(grok.Model):
    grok.implements(IFoo)

class MyNoInterfaceContent(grok.Model):
    grok.implements(IFoo)

class InterfaceRest(grok.REST):
    grok.context(IFoo)
    grok.layer(LayerInterface)

    def GET(self):
        return "GET interface registered"

    def POST(self):
        return "POST interface registered"

    def PUT(self):
        return "PUT interface registered"

    def DELETE(self):
        return "DELETE interface registered"
github zopefoundation / grok / src / grok / ftests / utility / subclass.py View on Github external
"""
import grok
from zope import interface

class IFireplace(interface.Interface):
    pass

class IPainting(interface.Interface):
    pass

class Fireplace(grok.LocalUtility):
    grok.implements(IFireplace)

class Painting(grok.LocalUtility):
    grok.implements(IPainting)

class Cave(grok.Model, grok.Site):
    # we use name_in_container here to prevent multiple registrations
    # since storing the utilities multiple times under the same name
    # would raise a DuplicationError
    grok.local_utility(Fireplace, name_in_container='fireplace')

class BigCave(Cave):
    pass

class HollowCave(Cave):
    grok.local_utility(Painting)

class VeryHollowCave(HollowCave):
    grok.local_utility(Painting, name='great')
    grok.local_utility(Painting, name='bad')
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 / catalog / indexes_app_interface.py View on Github external
from zope import schema

import grok
from grok import index


class IHerd(Interface):
    pass


class Herd(grok.Container, grok.Application):
    grok.implements(IHerd)


class Herd2(grok.Container, grok.Application):
    grok.implements(IHerd)


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(IHerd)
    grok.context(IMammoth)

    name = index.Field()
    age = index.Field()
    message = index.Text()
github zopefoundation / grok / doc / design / annotations.py View on Github external
from BTrees.OOBTree import OOTreeSet

class Article(grok.Model):
    pass

class IComments(interface.Interface):

    def addComment(text):
        pass

    def getComments():
        pass

class Comments(grok.Annotation):
    grok.context(Article)  # this is actually the default
    grok.implements(IComments)
    grok.name('annotations.Comments')  # this is actually the default

    def __init__(self): 
        self.comments = OOTreeSet()

    def addComment(self, text):
        self.comments.insert(text)

    def getComments(self):
        return list(self.comments)