src/pyams_content/component/media/__init__.py
changeset 21 dc45cba8c8f8
equal deleted inserted replaced
20:b2284a8b9014 21:dc45cba8c8f8
       
     1 #
       
     2 # Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
       
     3 # All Rights Reserved.
       
     4 #
       
     5 # This software is subject to the provisions of the Zope Public License,
       
     6 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
       
     7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
       
     8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
       
     9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
       
    10 # FOR A PARTICULAR PURPOSE.
       
    11 #
       
    12 
       
    13 __docformat__ = 'restructuredtext'
       
    14 
       
    15 
       
    16 # import standard library
       
    17 
       
    18 # import interfaces
       
    19 from pyams_content.shared.common.interfaces import IWfSharedContent
       
    20 from pyams_file.interfaces import IMediaFile, IThumbnailFile
       
    21 from zope.lifecycleevent.interfaces import IObjectAddedEvent, IObjectModifiedEvent, IObjectRemovedEvent
       
    22 
       
    23 # import packages
       
    24 from pyams_utils.traversing import get_parent
       
    25 from pyramid.events import subscriber
       
    26 from pyramid.threadlocal import get_current_registry
       
    27 from zope.lifecycleevent import ObjectModifiedEvent
       
    28 
       
    29 
       
    30 @subscriber(IObjectAddedEvent, context_selector=IMediaFile)
       
    31 def handle_added_media(event):
       
    32     """Handle added media file"""
       
    33     media = event.object
       
    34     if IThumbnailFile.providedBy(media):
       
    35         return
       
    36     content = get_parent(media, IWfSharedContent)
       
    37     if content is not None:
       
    38         get_current_registry().notify(ObjectModifiedEvent(content))
       
    39 
       
    40 
       
    41 @subscriber(IObjectModifiedEvent, context_selector=IMediaFile)
       
    42 def handle_modified_media(event):
       
    43     """Handle modified media file"""
       
    44     media = event.object
       
    45     if IThumbnailFile.providedBy(media):
       
    46         return
       
    47     content = get_parent(media, IWfSharedContent)
       
    48     if content is not None:
       
    49         get_current_registry().notify(ObjectModifiedEvent(content))
       
    50 
       
    51 
       
    52 @subscriber(IObjectRemovedEvent, context_selector=IMediaFile)
       
    53 def handle_removed_media(event):
       
    54     """Handle removed media file"""
       
    55     media = event.object
       
    56     if IThumbnailFile.providedBy(media):
       
    57         return
       
    58     content = get_parent(media, IWfSharedContent)
       
    59     if content is not None:
       
    60         get_current_registry().notify(ObjectModifiedEvent(content))