15 |
15 |
16 # import standard library |
16 # import standard library |
17 |
17 |
18 # import interfaces |
18 # import interfaces |
19 from pyams_content.features.checker.interfaces import IContentChecker, MISSING_VALUE, MISSING_LANG_VALUE, ERROR_VALUE |
19 from pyams_content.features.checker.interfaces import IContentChecker, MISSING_VALUE, MISSING_LANG_VALUE, ERROR_VALUE |
20 from pyams_content.shared.logo.interfaces import ILogosParagraph, LOGOS_PARAGRAPH_TYPE |
20 from pyams_content.shared.logo.interfaces import ILogosParagraph, LOGOS_PARAGRAPH_TYPE, LOGOS_PARAGRAPH_RENDERERS |
21 from pyams_i18n.interfaces import II18nManager, INegotiator, II18n |
21 from pyams_i18n.interfaces import II18nManager, INegotiator, II18n |
22 from pyams_workflow.interfaces import IWorkflow, IWorkflowState |
22 from pyams_workflow.interfaces import IWorkflow, IWorkflowState |
23 |
23 |
24 # import packages |
24 # import packages |
25 from pyams_content.component.paragraph import BaseParagraph, IParagraphFactory, BaseParagraphFactory, \ |
25 from pyams_content.component.paragraph import BaseParagraph, IParagraphFactory, BaseParagraphFactory, \ |
26 BaseParagraphContentChecker |
26 BaseParagraphContentChecker |
|
27 from pyams_content.features.renderer import RenderedContentMixin, IContentRenderer |
27 from pyams_sequence.utility import get_reference_target |
28 from pyams_sequence.utility import get_reference_target |
28 from pyams_utils.adapter import adapter_config |
29 from pyams_utils.adapter import adapter_config |
29 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 |
30 from pyams_utils.traversing import get_parent |
32 from pyams_utils.traversing import get_parent |
|
33 from pyams_utils.vocabulary import vocabulary_config |
31 from zope.interface import implementer |
34 from zope.interface import implementer |
32 from zope.schema.fieldproperty import FieldProperty |
35 from zope.schema.fieldproperty import FieldProperty |
|
36 from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm |
33 |
37 |
34 from pyams_content import _ |
38 from pyams_content import _ |
35 |
39 |
36 |
40 |
37 @implementer(ILogosParagraph) |
41 @implementer(ILogosParagraph) |
38 class LogosParagraph(BaseParagraph): |
42 class LogosParagraph(RenderedContentMixin, BaseParagraph): |
39 """Logos paragraph""" |
43 """Logos paragraph""" |
40 |
44 |
41 icon_class = 'fa-th-large' |
45 icon_class = 'fa-th-large' |
42 icon_hint = _("Logos") |
46 icon_hint = _("Logos") |
43 |
47 |
44 references = FieldProperty(ILogosParagraph['references']) |
48 references = FieldProperty(ILogosParagraph['references']) |
|
49 renderer = FieldProperty(ILogosParagraph['renderer']) |
45 |
50 |
46 def get_targets(self, state=None, with_reference=False): |
51 def get_targets(self, state=None, with_reference=False): |
47 for reference in self.references or (): |
52 for reference in self.references or (): |
48 if with_reference: |
53 if with_reference: |
49 yield reference, get_reference_target(reference, state) |
54 yield reference, get_reference_target(reference, state) |
101 output.append(translate(ERROR_VALUE).format( |
106 output.append(translate(ERROR_VALUE).format( |
102 field=field_title, |
107 field=field_title, |
103 message=translate(_("logo '{0}' is not published")).format( |
108 message=translate(_("logo '{0}' is not published")).format( |
104 II18n(target).query_attribute('title', request=request)))) |
109 II18n(target).query_attribute('title', request=request)))) |
105 return output |
110 return output |
|
111 |
|
112 |
|
113 @vocabulary_config(name=LOGOS_PARAGRAPH_RENDERERS) |
|
114 class LogosParagraphRendererVocabulary(SimpleVocabulary): |
|
115 """Logos paragraph renderers vocabulary""" |
|
116 |
|
117 def __init__(self, context=None): |
|
118 request = check_request() |
|
119 translate = request.localizer.translate |
|
120 registry = request.registry |
|
121 if not ILogosParagraph.providedBy(context): |
|
122 context = LogosParagraph() |
|
123 terms = [SimpleTerm(name, title=translate(adapter.label)) |
|
124 for name, adapter in sorted(registry.getAdapters((context, request), IContentRenderer), |
|
125 key=lambda x: x[1].weight)] |
|
126 super(LogosParagraphRendererVocabulary, self).__init__(terms) |