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