--- a/src/pyams_content/component/association/container.py Fri Nov 10 11:56:04 2017 +0100
+++ b/src/pyams_content/component/association/container.py Fri Nov 10 11:56:30 2017 +0100
@@ -18,12 +18,14 @@
# import interfaces
from pyams_content.component.association.interfaces import IAssociationContainer, IAssociationTarget, \
ASSOCIATION_CONTAINER_KEY, IAssociationInfo
+from pyams_content.features.checker.interfaces import IContentChecker
from zope.annotation.interfaces import IAnnotations
from zope.location.interfaces import ISublocations
from zope.traversing.interfaces import ITraversable
# import packages
from pyams_catalog.utils import index_object
+from pyams_content.features.checker import BaseContentChecker
from pyams_utils.adapter import adapter_config, ContextAdapter
from pyams_utils.traversing import get_parent
from pyams_utils.vocabulary import vocabulary_config
@@ -34,6 +36,8 @@
from zope.location import locate
from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
+from pyams_content import _
+
@implementer(IAssociationContainer)
class AssociationContainer(OrderedContainer):
@@ -67,7 +71,7 @@
@adapter_config(name='ass', context=IAssociationTarget, provides=ITraversable)
class AssociationContainerNamespace(ContextAdapter):
- """Associations container ++association++ namespace"""
+ """Associations container ++ass++ namespace"""
def traverse(self, name, furtherpath=None):
return IAssociationContainer(self.context)
@@ -81,6 +85,29 @@
return IAssociationContainer(self.context).values()
+@adapter_config(name='associations', context=IAssociationTarget, provides=IContentChecker)
+class AssociationsContentChecker(BaseContentChecker):
+ """Associations content checker"""
+
+ label = _("Associations")
+ sep = '\n'
+ weight = 100
+
+ def inner_check(self, request):
+ output = []
+ registry = request.registry
+ for association in IAssociationContainer(self.context).values():
+ if not association.visible:
+ continue
+ info = IAssociationInfo(association)
+ for name, checker in sorted(registry.getAdapters((association, ), IContentChecker),
+ key=lambda x: x[1].weight):
+ output.append('- {0} :'.format(info.user_title or
+ '({0})'.format(info.inner_title)))
+ output.append(checker.get_check_output(request))
+ return output
+
+
@vocabulary_config(name='PyAMS content associations')
class ContentAssociationsVocabulary(SimpleVocabulary):
"""Content associations vocabulary"""
--- a/src/pyams_content/component/association/paragraph.py Fri Nov 10 11:56:04 2017 +0100
+++ b/src/pyams_content/component/association/paragraph.py Fri Nov 10 11:56:30 2017 +0100
@@ -20,10 +20,15 @@
from pyams_content.component.extfile.interfaces import IExtFileContainerTarget
from pyams_content.component.links.interfaces import ILinkContainerTarget
from pyams_content.component.paragraph.interfaces import IParagraphFactory
+from pyams_content.features.checker.interfaces import IContentChecker, MISSING_VALUE, MISSING_LANG_VALUE
+from pyams_i18n.interfaces import II18n, II18nManager, INegotiator
# import packages
-from pyams_content.component.paragraph import BaseParagraph
-from pyams_utils.registry import utility_config
+from pyams_content.component.paragraph import BaseParagraph, BaseParagraphContentChecker
+from pyams_utils.adapter import adapter_config
+from pyams_utils.registry import utility_config, get_utility
+from pyams_utils.request import check_request
+from pyams_utils.traversing import get_parent
from zope.interface import implementer
from pyams_content import _
@@ -43,3 +48,35 @@
name = _("Associations paragraph")
content_type = AssociationParagraph
+
+
+@adapter_config(context=IAssociationParagraph, provides=IContentChecker)
+class AssociationParagraphContentChecker(BaseParagraphContentChecker):
+ """Associations paragraph content checker"""
+
+ @property
+ def label(self):
+ request = check_request()
+ translate = request.localizer.translate
+ return II18n(self.context).query_attribute('title', request) or \
+ '({0})'.format(translate(self.context.icon_hint).lower())
+
+ def inner_check(self, request):
+ output = []
+ translate = request.localizer.translate
+ manager = get_parent(self.context, II18nManager)
+ if manager is not None:
+ langs = manager.get_languages()
+ else:
+ negotiator = get_utility(INegotiator)
+ langs = (negotiator.server_language, )
+ i18n = II18n(self.context)
+ for lang in langs:
+ value = i18n.get_attribute('title', lang, request)
+ if not value:
+ field_title = translate(IAssociationParagraph['title'].title)
+ if len(langs) == 1:
+ output.append(translate(MISSING_VALUE).format(field=field_title))
+ else:
+ output.append(translate(MISSING_LANG_VALUE).format(field=field_title, lang=lang))
+ return output