|
1 # |
|
2 # Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net> |
|
3 # All Rights Reserved. |
|
4 # |
|
5 # This software is subject to the provisions of the Zope Public License, |
|
6 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. |
|
7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED |
|
8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS |
|
10 # FOR A PARTICULAR PURPOSE. |
|
11 # |
|
12 |
|
13 __docformat__ = 'restructuredtext' |
|
14 |
|
15 |
|
16 # import standard library |
|
17 |
|
18 # import interfaces |
|
19 from pyams_content.component.illustration.interfaces import IIllustrationTarget |
|
20 from pyams_content.component.paragraph.interfaces import IParagraphFactory |
|
21 from pyams_content.component.paragraph.interfaces.audio import IAudioParagraph, AUDIO_PARAGRAPH_TYPE, \ |
|
22 AUDIO_PARAGRAPH_RENDERERS, AUDIO_PARAGRAPH_NAME |
|
23 from pyams_content.features.checker.interfaces import IContentChecker, MISSING_VALUE, MISSING_LANG_VALUE |
|
24 from pyams_i18n.interfaces import II18nManager, INegotiator, II18n |
|
25 |
|
26 # import packages |
|
27 from pyams_content.component.paragraph import BaseParagraph, BaseParagraphContentChecker, BaseParagraphFactory |
|
28 from pyams_content.features.renderer import RenderersVocabulary |
|
29 from pyams_file.property import FileProperty |
|
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 |
|
33 from pyams_utils.traversing import get_parent |
|
34 from pyams_utils.vocabulary import vocabulary_config |
|
35 from zope.interface import implementer |
|
36 from zope.schema.fieldproperty import FieldProperty |
|
37 |
|
38 |
|
39 @implementer(IAudioParagraph, IIllustrationTarget) |
|
40 @factory_config(provided=IAudioParagraph) |
|
41 class AudioParagraph(BaseParagraph): |
|
42 """Audio paragraph class""" |
|
43 |
|
44 icon_class = 'fa-volume-up' |
|
45 icon_hint = AUDIO_PARAGRAPH_NAME |
|
46 |
|
47 body = FieldProperty(IAudioParagraph['body']) |
|
48 description = FieldProperty(IAudioParagraph['description']) |
|
49 author = FieldProperty(IAudioParagraph['author']) |
|
50 data = FileProperty(IAudioParagraph['data']) |
|
51 renderer = FieldProperty(IAudioParagraph['renderer']) |
|
52 |
|
53 |
|
54 @utility_config(name=AUDIO_PARAGRAPH_TYPE, provides=IParagraphFactory) |
|
55 class AudioParagraphFactory(BaseParagraphFactory): |
|
56 """Audio paragraph factory""" |
|
57 |
|
58 name = AUDIO_PARAGRAPH_NAME |
|
59 content_type = AudioParagraph |
|
60 |
|
61 |
|
62 @adapter_config(context=IAudioParagraph, provides=IContentChecker) |
|
63 class AudioParagraphContentChecker(BaseParagraphContentChecker): |
|
64 """Audio paragraph content checker""" |
|
65 |
|
66 def inner_check(self, request): |
|
67 output = [] |
|
68 translate = request.localizer.translate |
|
69 manager = get_parent(self.context, II18nManager) |
|
70 if manager is not None: |
|
71 langs = manager.get_languages() |
|
72 else: |
|
73 negotiator = get_utility(INegotiator) |
|
74 langs = (negotiator.server_language, ) |
|
75 i18n = II18n(self.context) |
|
76 for lang in langs: |
|
77 value = i18n.get_attribute('title', lang, request) |
|
78 if not value: |
|
79 field_title = translate(IAudioParagraph['title'].title) |
|
80 if len(langs) == 1: |
|
81 output.append(translate(MISSING_VALUE).format(field=field_title)) |
|
82 else: |
|
83 output.append(translate(MISSING_LANG_VALUE).format(field=field_title, lang=lang)) |
|
84 for attr in ('author', 'data'): |
|
85 value = getattr(self.context, attr) |
|
86 if not value: |
|
87 output.append(translate(MISSING_VALUE).format(field=translate(IAudioParagraph[attr].title))) |
|
88 return output |
|
89 |
|
90 |
|
91 @vocabulary_config(name=AUDIO_PARAGRAPH_RENDERERS) |
|
92 class AudioParagraphRendererVocabulary(RenderersVocabulary): |
|
93 """Audio paragraph renderers vocabulary""" |
|
94 |
|
95 content_interface = IAudioParagraph |