src/pyams_content/shared/view/theme.py
changeset 1428 48c1ee485dc0
parent 1389 1485db1e2b5e
child 1440 d78e15b0ca36
equal deleted inserted replaced
1427:43bd56f3a726 1428:48c1ee485dc0
     7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
     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
     8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
     9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
    10 # FOR A PARTICULAR PURPOSE.
    10 # FOR A PARTICULAR PURPOSE.
    11 #
    11 #
    12 
       
    13 __docformat__ = 'restructuredtext'
       
    14 
    12 
    15 from hypatia.interfaces import ICatalog
    13 from hypatia.interfaces import ICatalog
    16 from hypatia.query import Any
    14 from hypatia.query import Any
    17 from persistent import Persistent
    15 from persistent import Persistent
    18 from zope.container.contained import Contained
    16 from zope.container.contained import Contained
    30 from pyams_utils.adapter import ContextAdapter, adapter_config, get_annotation_adapter
    28 from pyams_utils.adapter import ContextAdapter, adapter_config, get_annotation_adapter
    31 from pyams_utils.factory import factory_config
    29 from pyams_utils.factory import factory_config
    32 from pyams_utils.registry import get_utility, query_utility
    30 from pyams_utils.registry import get_utility, query_utility
    33 
    31 
    34 
    32 
       
    33 __docformat__ = 'restructuredtext'
       
    34 
       
    35 
    35 #
    36 #
    36 # Tags management
    37 # Tags management
    37 #
    38 #
    38 
    39 
    39 @factory_config(IViewTagsSettings)
    40 @factory_config(IViewTagsSettings)
   116 class ViewThemesSettings(Persistent, Contained):
   117 class ViewThemesSettings(Persistent, Contained):
   117     """View themes settings"""
   118     """View themes settings"""
   118 
   119 
   119     select_context_themes = FieldProperty(IViewThemesSettings['select_context_themes'])
   120     select_context_themes = FieldProperty(IViewThemesSettings['select_context_themes'])
   120     themes = FieldProperty(IViewThemesSettings['themes'])
   121     themes = FieldProperty(IViewThemesSettings['themes'])
       
   122     include_subthemes = FieldProperty(IViewThemesSettings['include_subthemes'])
   121 
   123 
   122     @property
   124     @property
   123     def is_using_context(self):
   125     def is_using_context(self):
   124         return self.select_context_themes
   126         return self.select_context_themes
   125 
   127 
   129             themes_info = IThemesInfo(context, None)
   131             themes_info = IThemesInfo(context, None)
   130             if themes_info is not None:
   132             if themes_info is not None:
   131                 themes |= set(themes_info.themes or ())
   133                 themes |= set(themes_info.themes or ())
   132         if self.themes:
   134         if self.themes:
   133             themes |= set(self.themes)
   135             themes |= set(self.themes)
       
   136         if self.include_subthemes:
       
   137             for theme in themes.copy():
       
   138                 themes |= set(theme.gel_all_childs())
   134         return themes
   139         return themes
   135 
   140 
   136     def get_themes_index(self, context):
   141     def get_themes_index(self, context):
   137         intids = get_utility(IIntIds)
   142         intids = get_utility(IIntIds)
   138         return [intids.register(term) for term in self.get_themes(context)]
   143         return [intids.register(term) for term in self.get_themes(context)]