23 from pyams_content.component.extfile import IExtFile |
23 from pyams_content.component.extfile import IExtFile |
24 from pyams_content.component.links.interfaces import IBaseLink, IInternalLink |
24 from pyams_content.component.links.interfaces import IBaseLink, IInternalLink |
25 from pyams_content.component.paragraph.interfaces import IParagraphContainer, IParagraphContainerTarget |
25 from pyams_content.component.paragraph.interfaces import IParagraphContainer, IParagraphContainerTarget |
26 from pyams_content.features.renderer.interfaces import IContentRenderer |
26 from pyams_content.features.renderer.interfaces import IContentRenderer |
27 from pyams_default_theme import _ |
27 from pyams_default_theme import _ |
28 from pyams_default_theme.component.association.interfaces import IAssociationParagraphRemoteContentRendererSettings, \ |
28 from pyams_default_theme.component.association.interfaces import IAssociationParagraphDefaultRendererSettings, \ |
29 IAssociationParagraphSlicedRemoteContentRendererSettings |
29 IAssociationParagraphRemoteContentRendererSettings, IAssociationParagraphSlicedRemoteContentRendererSettings |
30 from pyams_default_theme.features.renderer import BaseContentRenderer |
30 from pyams_default_theme.features.renderer import BaseContentRenderer |
31 from pyams_skin.layer import IPyAMSLayer |
31 from pyams_skin.layer import IPyAMSLayer |
32 from pyams_template.template import template_config |
32 from pyams_template.template import template_config |
33 from pyams_utils.adapter import adapter_config, get_annotation_adapter |
33 from pyams_utils.adapter import adapter_config, get_annotation_adapter |
34 from pyams_utils.factory import factory_config |
34 from pyams_utils.factory import factory_config |
36 |
36 |
37 # |
37 # |
38 # Associations paragraph default renderer |
38 # Associations paragraph default renderer |
39 # |
39 # |
40 |
40 |
|
41 ASSOCIATION_PARAGRAPH_DEFAULT_RENDERER_SETTINGS_KEY = 'pyams_content.association.renderer:default' |
|
42 |
|
43 |
|
44 @factory_config(IAssociationParagraphDefaultRendererSettings) |
|
45 class AssociationParagraphDefaultRendererSettings(Persistent, Location): |
|
46 """Association paragraph default renderer settings""" |
|
47 |
|
48 description_format = FieldProperty(IAssociationParagraphDefaultRendererSettings['description_format']) |
|
49 |
|
50 |
|
51 @adapter_config(context=IAssociationParagraph, provides=IAssociationParagraphDefaultRendererSettings) |
|
52 def association_paragraph_default_renderer_settings_factory(context): |
|
53 """Associations paragraph default renderer settings factory""" |
|
54 return get_annotation_adapter(context, ASSOCIATION_PARAGRAPH_DEFAULT_RENDERER_SETTINGS_KEY, |
|
55 IAssociationParagraphDefaultRendererSettings) |
|
56 |
|
57 |
41 @adapter_config(name='default', context=(IAssociationParagraph, IPyAMSLayer), provides=IContentRenderer) |
58 @adapter_config(name='default', context=(IAssociationParagraph, IPyAMSLayer), provides=IContentRenderer) |
42 @template_config(template='templates/association-default.pt', layer=IPyAMSLayer) |
59 @template_config(template='templates/association-default.pt', layer=IPyAMSLayer) |
43 class AssociationParagraphDefaultRenderer(BaseContentRenderer): |
60 class AssociationParagraphDefaultRenderer(BaseContentRenderer): |
44 """Associations paragraph default renderer""" |
61 """Associations paragraph default renderer""" |
45 |
62 |
46 label = _("Default associations renderer") |
63 label = _("Default associations renderer") |
47 i18n_context_attrs = ('title',) |
64 i18n_context_attrs = ('title',) |
48 |
65 |
49 links = None |
66 settings_interface = IAssociationParagraphDefaultRendererSettings |
50 attachments = None |
67 |
|
68 def __init__(self, *args, **kwargs): |
|
69 super(AssociationParagraphDefaultRenderer, self).__init__(*args, **kwargs) |
|
70 self.attachments = [] |
|
71 self.links = [] |
51 |
72 |
52 def get_associations(self): |
73 def get_associations(self): |
53 yield from IAssociationContainer(self.context).get_visible_items(self.request) |
74 yield from IAssociationContainer(self.context).get_visible_items(self.request) |
54 |
75 |
55 @staticmethod |
76 @staticmethod |
56 def get_link_info(link): |
77 def get_link_info(link): |
57 return IAssociationInfo(link) |
78 return IAssociationInfo(link) |
58 |
79 |
59 def update(self): |
80 def update(self): |
60 super().update() |
81 super().update() |
61 self.attachments = [] |
|
62 self.links = [] |
|
63 for item in self.get_associations(): |
82 for item in self.get_associations(): |
64 if IExtFile.providedBy(item): |
83 if IExtFile.providedBy(item): |
65 self.attachments.append(item) |
84 self.attachments.append(item) |
66 elif IBaseLink.providedBy(item): |
85 elif IBaseLink.providedBy(item): |
67 self.links.append(item) |
86 self.links.append(item) |
69 |
88 |
70 # |
89 # |
71 # Associations paragraph remote content renderer |
90 # Associations paragraph remote content renderer |
72 # |
91 # |
73 |
92 |
74 ASSOCIATION_PARAGRAPH_SLICED_REMOTE_CONTENT_RENDERER_SETTINGS_KEY = 'pyams_content.association.renderer:sliced-remote-content' |
93 ASSOCIATION_PARAGRAPH_SLICED_REMOTE_CONTENT_RENDERER_SETTINGS_KEY = \ |
75 ASSOCIATION_PARAGRAPH_REMOTE_CONTENT_RENDERER_SETTINGS_KEY = 'pyams_content.association.renderer:remote-content' |
94 'pyams_content.association.renderer:sliced-remote-content' |
|
95 ASSOCIATION_PARAGRAPH_REMOTE_CONTENT_RENDERER_SETTINGS_KEY = \ |
|
96 'pyams_content.association.renderer:remote-content' |
76 |
97 |
77 |
98 |
78 @factory_config(IAssociationParagraphSlicedRemoteContentRendererSettings) |
99 @factory_config(IAssociationParagraphSlicedRemoteContentRendererSettings) |
79 class AssociationParagraphSlicedRemoteContentRendererSettings(Persistent, Location): |
100 class AssociationParagraphSlicedRemoteContentRendererSettings(Persistent, Location): |
80 """Associations paragraph sliced remote content renderer settings""" |
101 """Associations paragraph sliced remote content renderer settings""" |