How to use the grok.local_utility 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 / catalog / setuporder.py View on Github external
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 / utility / multiple_class.py View on Github external
"""
import grok
from zope import interface

class IFireplace(interface.Interface):
    pass

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

class Fireplace2(grok.LocalUtility):
    grok.implements(IFireplace)
    
class Cave(grok.Model, grok.Site):
    grok.local_utility(Fireplace, name='Foo')
    grok.local_utility(Fireplace2, name='Foo')
github zopefoundation / grok / src / grok / ftests / catalog / addform.py View on Github external
We found Ellie!

"""
import grok
from zope import schema, interface, component
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 Zoo(grok.Site, grok.Container):
    grok.local_utility(IntIds, provides=IIntIds)
    grok.local_utility(Catalog, provides=ICatalog, setup=setup_catalog)

class IMammoth(interface.Interface):
    name = schema.TextLine(title=u"Name")
    size = schema.TextLine(title=u"Size")

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

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)
github zopefoundation / grok / src / grok / ftests / utility / local.py View on Github external
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')
    grok.local_utility(Mammoth, provides=IMammoth)
    grok.local_utility(SabretoothTiger, name='tiger')
    grok.local_utility(CavePainting, name='blackandwhite', provides=IPainting)
    grok.local_utility(ColoredCavePainting, name='color')
github zopefoundation / grok / src / grok / ftests / utility / subclass.py View on Github external
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')

# this cave subclasses from Cave twice
class ScaryCave(VeryHollowCave, Cave):
    pass
github zopefoundation / grok / src / grok / ftests / utility / local.py View on Github external
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')
    grok.local_utility(Mammoth, provides=IMammoth)
    grok.local_utility(SabretoothTiger, name='tiger')
    grok.local_utility(CavePainting, name='blackandwhite', provides=IPainting)
    grok.local_utility(ColoredCavePainting, name='color')
github zopefoundation / grok / src / grok / ftests / utility / multiple_directive.py View on Github external
"""
import grok
from zope import interface

class IFireplace(interface.Interface):
    pass

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

class Fireplace2(grok.LocalUtility):
    grok.implements(IFireplace)
    
class Cave(grok.Model, grok.Site):
    grok.local_utility(Fireplace, provides=IFireplace)
    grok.local_utility(Fireplace2, provides=IFireplace)
github zopefoundation / grok / doc / design / utility.py View on Github external
grok.global_utility(factory, provides=IFace, name=u'')

class Calculator(grok.LocalUtility):
    grok.utility_provides(ICalculator)

class Anything(grok.Model):
    pass

class NonPersistent(object):
    pass

class SpecialAnything(Anything):
    pass

class Foo(grok.Model, grok.Site):    
    grok.local_utility(Anything, hide=False, name_in_container='foo',
                       persistent=None)
    grok.local_adapter()
    grok.local_view()

class Foo2(Foo):
    grok.local_utility(SpecialAnything)