src/pyams_content/features/alert/container.py
changeset 558 d9c6b1d7fefa
parent 506 174894a2293d
child 841 d50743e69693
equal deleted inserted replaced
557:a78ade534b97 558:d9c6b1d7fefa
    15 
    15 
    16 # import standard library
    16 # import standard library
    17 
    17 
    18 # import interfaces
    18 # import interfaces
    19 from pyams_content.features.alert.interfaces import IAlertContainer, IAlertItem, IAlertTarget, ALERT_CONTAINER_KEY
    19 from pyams_content.features.alert.interfaces import IAlertContainer, IAlertItem, IAlertTarget, ALERT_CONTAINER_KEY
    20 from zope.annotation.interfaces import IAnnotations
       
    21 from zope.location.interfaces import ISublocations
    20 from zope.location.interfaces import ISublocations
    22 from zope.traversing.interfaces import ITraversable
    21 from zope.traversing.interfaces import ITraversable
    23 
    22 
    24 # import packages
    23 # import packages
    25 from pyams_catalog.utils import index_object
    24 from pyams_catalog.utils import index_object
    26 from pyams_utils.adapter import adapter_config, ContextAdapter
    25 from pyams_utils.adapter import adapter_config, ContextAdapter, get_annotation_adapter
    27 from pyams_utils.registry import get_current_registry
       
    28 from zope.container.ordered import OrderedContainer
    26 from zope.container.ordered import OrderedContainer
    29 from zope.interface import implementer
    27 from zope.interface import implementer
    30 from zope.lifecycleevent import ObjectCreatedEvent
       
    31 from zope.location import locate
    28 from zope.location import locate
    32 
    29 
    33 
    30 
    34 @implementer(IAlertContainer)
    31 @implementer(IAlertContainer)
    35 class AlertContainer(OrderedContainer):
    32 class AlertContainer(OrderedContainer):
    53 
    50 
    54 
    51 
    55 @adapter_config(context=IAlertTarget, provides=IAlertContainer)
    52 @adapter_config(context=IAlertTarget, provides=IAlertContainer)
    56 def alert_container_factory(target):
    53 def alert_container_factory(target):
    57     """Alert container factory"""
    54     """Alert container factory"""
    58     annotations = IAnnotations(target)
    55     return get_annotation_adapter(target, ALERT_CONTAINER_KEY, AlertContainer, name='++alert++')
    59     container = annotations.get(ALERT_CONTAINER_KEY)
       
    60     if container is None:
       
    61         container = annotations[ALERT_CONTAINER_KEY] = AlertContainer()
       
    62         get_current_registry().notify(ObjectCreatedEvent(container))
       
    63         locate(container, target, '++alert++')
       
    64     return container
       
    65 
    56 
    66 
    57 
    67 @adapter_config(name='alert', context=IAlertTarget, provides=ITraversable)
    58 @adapter_config(name='alert', context=IAlertTarget, provides=ITraversable)
    68 class AlertContainerNamespace(ContextAdapter):
    59 class AlertContainerNamespace(ContextAdapter):
    69     """Alert container ++alert++ namespace"""
    60     """Alert container ++alert++ namespace"""