15 |
15 |
16 # import standard library |
16 # import standard library |
17 |
17 |
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 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 |
22 from pyams_i18n.interfaces import II18n, II18nManager, INegotiator |
24 from pyams_i18n.interfaces import II18n, II18nManager, INegotiator |
23 |
25 |
24 # import packages |
26 # import packages |
25 from pyams_content.component.paragraph import BaseParagraph, BaseParagraphContentChecker, BaseParagraphFactory |
27 from pyams_content.component.paragraph import BaseParagraph, BaseParagraphContentChecker, BaseParagraphFactory |
|
28 from pyams_content.features.renderer import RenderedContentMixin |
26 from pyams_utils.adapter import adapter_config |
29 from pyams_utils.adapter import adapter_config |
27 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 |
28 from pyams_utils.text import get_text_start |
32 from pyams_utils.text import get_text_start |
29 from pyams_utils.traversing import get_parent |
33 from pyams_utils.traversing import get_parent |
|
34 from pyams_utils.vocabulary import vocabulary_config |
30 from zope.interface import implementer |
35 from zope.interface import implementer |
31 from zope.schema.fieldproperty import FieldProperty |
36 from zope.schema.fieldproperty import FieldProperty |
|
37 from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm |
32 |
38 |
33 from pyams_content import _ |
39 from pyams_content import _ |
34 |
40 |
35 |
41 |
36 @implementer(IKeypointsParagraph) |
42 @implementer(IKeypointsParagraph) |
37 class KeypointsParagraph(BaseParagraph): |
43 class KeypointsParagraph(RenderedContentMixin, BaseParagraph): |
38 """Key points paragraph""" |
44 """Key points paragraph""" |
39 |
45 |
40 icon_class = 'fa-key' |
46 icon_class = 'fa-key' |
41 icon_hint = _("Key points") |
47 icon_hint = _("Key points") |
42 |
48 |
44 def title(self): |
50 def title(self): |
45 body = II18n(self).query_attribute('body') |
51 body = II18n(self).query_attribute('body') |
46 return get_text_start(body, 50, 10) |
52 return get_text_start(body, 50, 10) |
47 |
53 |
48 body = FieldProperty(IKeypointsParagraph['body']) |
54 body = FieldProperty(IKeypointsParagraph['body']) |
|
55 renderer = FieldProperty(IKeypointsParagraph['renderer']) |
49 |
56 |
50 |
57 |
51 @utility_config(name=KEYPOINTS_PARAGRAPH_TYPE, provides=IParagraphFactory) |
58 @utility_config(name=KEYPOINTS_PARAGRAPH_TYPE, provides=IParagraphFactory) |
52 class KeypointsParagraphFactory(BaseParagraphFactory): |
59 class KeypointsParagraphFactory(BaseParagraphFactory): |
53 """Key points paragraph factory""" |
60 """Key points paragraph factory""" |
78 if len(langs) == 1: |
85 if len(langs) == 1: |
79 output.append(translate(MISSING_VALUE).format(field=field_title)) |
86 output.append(translate(MISSING_VALUE).format(field=field_title)) |
80 else: |
87 else: |
81 output.append(translate(MISSING_LANG_VALUE).format(field=field_title, lang=lang)) |
88 output.append(translate(MISSING_LANG_VALUE).format(field=field_title, lang=lang)) |
82 return output |
89 return output |
|
90 |
|
91 |
|
92 @vocabulary_config(name=KEYPOINTS_PARAGRAPH_RENDERERS) |
|
93 class KeypointsParagraphRendererVocabulary(SimpleVocabulary): |
|
94 """Key points paragraph renderers vocabulary""" |
|
95 |
|
96 def __init__(self, context=None): |
|
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) |