#
# Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
__docformat__ = 'restructuredtext'
from persistent import Persistent
from zope.container.contained import Contained
from zope.schema.fieldproperty import FieldProperty
from pyams_content.component.theme.interfaces import IThemesManagerTarget, IThemesManager, THEMES_MANAGER_KEY, \
IThemesTarget, IThemesInfo, THEMES_INFO_KEY, ITagsManager, ITagsManagerTarget, TAGS_MANAGER_KEY, ITagsInfo, \
ITagsTarget, TAGS_INFO_KEY, ICollectionsManager, ICollectionsManagerTarget, COLLECTIONS_MANAGER_KEY, \
ICollectionsInfo, ICollectionsTarget, COLLECTIONS_INFO_KEY
from pyams_content.features.checker import BaseContentChecker
from pyams_content.features.checker.interfaces import IContentChecker, ERROR_VALUE
from pyams_utils.adapter import adapter_config, get_annotation_adapter
from pyams_utils.factory import factory_config
from pyams_content import _
#
# Tags management
#
[docs]@adapter_config(name='tags', context=ITagsTarget, provides=IContentChecker)
class TagsContentChecker(BaseContentChecker):
"""Tags info content checker"""
label = _("Tags")
weight = 205
[docs] def inner_check(self, request):
output = []
translate = request.localizer.translate
tags = ITagsInfo(self.context)
if not tags.tags:
output.append(translate(ERROR_VALUE).format(field=translate(ITagsInfo['tags'].title),
message=translate(_("no defined tag"))))
return output
#
# Themes management
#
[docs]@factory_config(IThemesManager)
class ThemesManager(Persistent, Contained):
"""Themes manager persistent class"""
thesaurus_name = FieldProperty(IThemesManager['thesaurus_name'])
extract_name = FieldProperty(IThemesManager['extract_name'])
[docs]@adapter_config(context=IThemesManagerTarget, provides=IThemesManager)
def themes_manager_factory(target):
"""Themes manager factory"""
return get_annotation_adapter(target, THEMES_MANAGER_KEY, IThemesManager,
name='++themes-manager++')
[docs]@factory_config(IThemesInfo)
class ThemesInfo(Persistent, Contained):
"""Themes info persistent class"""
themes = FieldProperty(IThemesInfo['themes'])
[docs]@adapter_config(context=IThemesTarget, provides=IThemesInfo)
def themes_info_factory(target):
"""Themes info factory"""
return get_annotation_adapter(target, THEMES_INFO_KEY, IThemesInfo,
name='++themes++')
[docs]@adapter_config(name='themes', context=IThemesTarget, provides=IContentChecker)
class ThemesContentChecker(BaseContentChecker):
"""Themes info content checker"""
label = _("Themes")
weight = 210
[docs] def inner_check(self, request):
output = []
translate = request.localizer.translate
themes = IThemesInfo(self.context)
if not themes.themes:
output.append(translate(ERROR_VALUE).format(field=translate(IThemesInfo['themes'].title),
message=translate(_("no defined theme"))))
return output
#
# Collections management
#
[docs]@factory_config(ICollectionsManager)
class CollectionsManager(Persistent, Contained):
"""Collections manager persistent class"""
thesaurus_name = FieldProperty(ICollectionsManager['thesaurus_name'])
extract_name = FieldProperty(ICollectionsManager['extract_name'])
[docs]@adapter_config(context=ICollectionsManagerTarget, provides=ICollectionsManager)
def collections_manager_factory(target):
"""Collections manager factory"""
return get_annotation_adapter(target, COLLECTIONS_MANAGER_KEY, ICollectionsManager,
name='++collections-manager++')
[docs]@factory_config(ICollectionsInfo)
class CollectionsInfo(Persistent, Contained):
"""Collections info persistent class"""
collections = FieldProperty(ICollectionsInfo['collections'])
[docs]@adapter_config(context=ICollectionsTarget, provides=ICollectionsInfo)
def collections_info_factory(target):
"""Collections info factory"""
return get_annotation_adapter(target, COLLECTIONS_INFO_KEY, ICollectionsInfo,
name='++collections++')
[docs]@adapter_config(name='collections', context=ICollectionsTarget, provides=IContentChecker)
class CollectionsContentChecker(BaseContentChecker):
"""Collections info content checker"""
label = _("Collections")
weight = 215
[docs] def inner_check(self, request):
output = []
translate = request.localizer.translate
collections = ICollectionsInfo(self.context)
if not collections.collections:
output.append(translate(ERROR_VALUE).format(field=translate(ICollectionsInfo['collections'].title),
message=translate(_("no defined collection"))))
return output