src/pyams_content/component/theme/__init__.py
changeset 0 7c0001cacf8e
child 240 0eca05146080
equal deleted inserted replaced
-1:000000000000 0:7c0001cacf8e
       
     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.component.theme.interfaces import IThemesManagerTarget, IThemesManager, THEMES_MANAGER_KEY, IThemesInfo, \
       
    20     IThemesTarget, THEMES_INFO_KEY
       
    21 from zope.annotation.interfaces import IAnnotations
       
    22 
       
    23 # import packages
       
    24 from persistent import Persistent
       
    25 from pyams_utils.adapter import adapter_config
       
    26 from pyramid.threadlocal import get_current_registry
       
    27 from zope.container.contained import Contained
       
    28 from zope.interface import implementer
       
    29 from zope.lifecycleevent import ObjectCreatedEvent
       
    30 from zope.location import locate
       
    31 from zope.schema.fieldproperty import FieldProperty
       
    32 
       
    33 
       
    34 @implementer(IThemesManager)
       
    35 class ThemesManager(Persistent, Contained):
       
    36     """Themes manager persistent class"""
       
    37 
       
    38     thesaurus_name = FieldProperty(IThemesManager['thesaurus_name'])
       
    39     extract_name = FieldProperty(IThemesManager['extract_name'])
       
    40 
       
    41 
       
    42 @adapter_config(context=IThemesManagerTarget, provides=IThemesManager)
       
    43 def ThemesManagerFactory(target):
       
    44     """Themes manager factory"""
       
    45     annotations = IAnnotations(target)
       
    46     manager = annotations.get(THEMES_MANAGER_KEY)
       
    47     if manager is None:
       
    48         manager = annotations[THEMES_MANAGER_KEY] = ThemesManager()
       
    49         get_current_registry().notify(ObjectCreatedEvent(manager))
       
    50         locate(manager, target, '++themes-manager++')
       
    51     return manager
       
    52 
       
    53 
       
    54 @implementer(IThemesInfo)
       
    55 class ThemesInfo(Persistent, Contained):
       
    56     """Themes info persistent class"""
       
    57 
       
    58     themes = FieldProperty(IThemesInfo['themes'])
       
    59 
       
    60 
       
    61 @adapter_config(context=IThemesTarget, provides=IThemesInfo)
       
    62 def ThemesInfoFactory(target):
       
    63     """Themes info factory"""
       
    64     annotations = IAnnotations(target)
       
    65     info = annotations.get(THEMES_INFO_KEY)
       
    66     if info is None:
       
    67         info = annotations[THEMES_INFO_KEY] = ThemesInfo()
       
    68         get_current_registry().notify(ObjectCreatedEvent(info))
       
    69         locate(info, target, '++themes++')
       
    70     return info