# Make sure that catalog brains can have a 'price' attribute.

from getpaid.core.interfaces import IPayable
from Products.CMFPlone import CatalogTool
from Products.PloneGetPaid.interfaces import IPayableMarker

try:
    # Plone 3.3*
    from plone.indexer.decorator import indexer

    @indexer(IPayableMarker)
    def get_price(object):
        adapted = IPayable(object, None)
        if adapted is not None:
            return adapted.price
        return None

except ImportError:
    # Plone 3.2.x code

    def get_price(object, portal, **kw):
        if not IPayableMarker.providedBy(object):
            return None
        adapted = IPayable(object, None)
        if adapted is not None:
            return adapted.price
        return None

    CatalogTool.registerIndexableAttribute('price', get_price)
from Products.CMFCore import utils as cmfutils
from Products.CMFPlone import CatalogTool
from zope import interface
from p4a.z2utils.utils import interfaceToName

# Plone 3 provides this so we want to use plone 3's instead if possible
if not hasattr(CatalogTool, 'object_provides'):
    def object_provides(object, portal, **kw):
        """Returns a list of strings representing all interfaces provided by
        an object.

        """

        return [interfaceToName(portal, i)
                for i in interface.providedBy(object).flattened()]

    CatalogTool.registerIndexableAttribute('object_provides', object_provides)

def ensure_object_provides(context):
    """Make sure the closest catalog to context has an index representing
    the object_provides index.
    """

    catalog = cmfutils.getToolByName(context, 'portal_catalog')
    if 'object_provides' not in catalog.indexes():
        catalog.manage_addIndex('object_provides', 'KeywordIndex')
        catalog.manage_reindexIndex('object_provides')
Exemple #3
0
from Products.CMFPlone import CatalogTool
from zope import interface
from p4a.z2utils.utils import interfaceToName

# Plone 3 provides this so we want to use plone 3's instead if possible
if not hasattr(CatalogTool, 'object_provides'):

    def object_provides(object, portal, **kw):
        """Returns a list of strings representing all interfaces provided by
        an object.

        """

        return [
            interfaceToName(portal, i)
            for i in interface.providedBy(object).flattened()
        ]

    CatalogTool.registerIndexableAttribute('object_provides', object_provides)


def ensure_object_provides(context):
    """Make sure the closest catalog to context has an index representing
    the object_provides index.
    """

    catalog = cmfutils.getToolByName(context, 'portal_catalog')
    if 'object_provides' not in catalog.indexes():
        catalog.manage_addIndex('object_provides', 'KeywordIndex')
        catalog.manage_reindexIndex('object_provides')
    implements(IFloorInfo)
    adapts(IATImage)

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

    def set_floor(self, floor):
        annotation = IAnnotations(self.context)
        annotation[FLOORKEY] = floor
    def get_floor(self):
        annotation = IAnnotations(self.context)
        return annotation.get(FLOORKEY)
    floor = property(get_floor, set_floor)

    def set_is_floorplan(self, floorplan):
        annotation = IAnnotations(self.context)
        annotation[FLOORPLANKEY] = floorplan
    def get_is_floorplan(self):
        annotation = IAnnotations(self.context)
        return annotation.get(FLOORPLANKEY, False)
    is_floorplan = property(get_is_floorplan, set_is_floorplan)


def is_floorplan(object, portal, **kw):
    adapted = IFloorInfo(object, None)
    if adapted is not None:
        return adapted.is_floorplan
    return False

catalogtool.registerIndexableAttribute('is_floorplan', is_floorplan)