20 ASSOCIATION_PARAGRAPH_RENDERERS |
20 ASSOCIATION_PARAGRAPH_RENDERERS |
21 from pyams_content.component.extfile.interfaces import IExtFileContainerTarget |
21 from pyams_content.component.extfile.interfaces import IExtFileContainerTarget |
22 from pyams_content.component.links.interfaces import ILinkContainerTarget |
22 from pyams_content.component.links.interfaces import ILinkContainerTarget |
23 from pyams_content.component.paragraph.interfaces import IParagraphFactory |
23 from pyams_content.component.paragraph.interfaces import IParagraphFactory |
24 from pyams_content.features.checker.interfaces import IContentChecker, MISSING_VALUE, MISSING_LANG_VALUE |
24 from pyams_content.features.checker.interfaces import IContentChecker, MISSING_VALUE, MISSING_LANG_VALUE |
25 from pyams_content.features.renderer.interfaces import IContentRenderer |
|
26 from pyams_i18n.interfaces import II18n, II18nManager, INegotiator |
25 from pyams_i18n.interfaces import II18n, II18nManager, INegotiator |
27 |
26 |
28 # import packages |
27 # import packages |
29 from pyams_content.component.paragraph import BaseParagraph, BaseParagraphContentChecker, BaseParagraphFactory |
28 from pyams_content.component.paragraph import BaseParagraph, BaseParagraphContentChecker, BaseParagraphFactory |
30 from pyams_content.features.renderer import RenderedContentMixin |
29 from pyams_content.features.renderer import RenderersVocabulary |
31 from pyams_utils.adapter import adapter_config |
30 from pyams_utils.adapter import adapter_config |
|
31 from pyams_utils.factory import factory_config |
32 from pyams_utils.registry import utility_config, get_utility |
32 from pyams_utils.registry import utility_config, get_utility |
33 from pyams_utils.request import check_request |
33 from pyams_utils.request import check_request |
34 from pyams_utils.traversing import get_parent |
34 from pyams_utils.traversing import get_parent |
35 from pyams_utils.vocabulary import vocabulary_config |
35 from pyams_utils.vocabulary import vocabulary_config |
36 from zope.interface import implementer |
36 from zope.interface import implementer |
37 from zope.schema.fieldproperty import FieldProperty |
37 from zope.schema.fieldproperty import FieldProperty |
38 from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm |
|
39 |
38 |
40 from pyams_content import _ |
39 from pyams_content import _ |
41 |
40 |
42 |
41 |
43 @implementer(IAssociationParagraph, IExtFileContainerTarget, ILinkContainerTarget) |
42 @implementer(IAssociationParagraph, IExtFileContainerTarget, ILinkContainerTarget) |
44 class AssociationParagraph(RenderedContentMixin, BaseParagraph): |
43 @factory_config(provided=IAssociationParagraph) |
|
44 class AssociationParagraph(BaseParagraph): |
45 """Associations paragraph""" |
45 """Associations paragraph""" |
46 |
46 |
47 icon_class = 'fa-link' |
47 icon_class = 'fa-link' |
48 icon_hint = _("Associations paragraph") |
48 icon_hint = _("Associations paragraph") |
49 |
49 |
89 output.append(translate(MISSING_LANG_VALUE).format(field=field_title, lang=lang)) |
89 output.append(translate(MISSING_LANG_VALUE).format(field=field_title, lang=lang)) |
90 return output |
90 return output |
91 |
91 |
92 |
92 |
93 @vocabulary_config(name=ASSOCIATION_PARAGRAPH_RENDERERS) |
93 @vocabulary_config(name=ASSOCIATION_PARAGRAPH_RENDERERS) |
94 class AssociationParagraphRendererVocabulary(SimpleVocabulary): |
94 class AssociationParagraphRendererVocabulary(RenderersVocabulary): |
95 """Associations paragraph renderers vocabulary""" |
95 """Associations paragraph renderers vocabulary""" |
96 |
96 |
97 def __init__(self, context=None): |
97 content_interface = IAssociationParagraph |
98 request = check_request() |
|
99 translate = request.localizer.translate |
|
100 registry = request.registry |
|
101 if not IAssociationParagraph.providedBy(context): |
|
102 context = AssociationParagraph() |
|
103 terms = [SimpleTerm(name, title=translate(adapter.label)) |
|
104 for name, adapter in sorted(registry.getAdapters((context, request), IContentRenderer), |
|
105 key=lambda x: x[1].weight)] |
|
106 super(AssociationParagraphRendererVocabulary, self).__init__(terms) |
|