changeset 1034 | 87f03e244266 |
parent 571 | b2e79295caec |
child 1037 | 5a697cde9826 |
1033:6ca1041099d3 | 1034:87f03e244266 |
---|---|
10 # FOR A PARTICULAR PURPOSE. |
10 # FOR A PARTICULAR PURPOSE. |
11 # |
11 # |
12 |
12 |
13 __docformat__ = 'restructuredtext' |
13 __docformat__ = 'restructuredtext' |
14 |
14 |
15 |
|
16 # import standard library |
|
17 import os |
15 import os |
18 |
16 |
19 # import interfaces |
17 from pyramid.events import subscriber |
18 from pyramid.threadlocal import get_current_registry |
|
19 from zope.interface import alsoProvides, implementer |
|
20 from zope.lifecycleevent import ObjectModifiedEvent |
|
21 from zope.lifecycleevent.interfaces import IObjectAddedEvent, IObjectModifiedEvent, IObjectRemovedEvent |
|
22 from zope.schema.fieldproperty import FieldProperty |
|
23 from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary |
|
24 |
|
25 from pyams_content.component.association import AssociationItem |
|
20 from pyams_content.component.association.interfaces import IAssociationInfo |
26 from pyams_content.component.association.interfaces import IAssociationInfo |
21 from pyams_content.component.extfile.interfaces import IBaseExtFile, IExtFile, IExtImage, IExtVideo, IExtAudio, \ |
27 from pyams_content.component.extfile.interfaces import IBaseExtFile, IExtAudio, IExtFile, IExtFileManagerInfo, \ |
22 IExtMedia |
28 IExtImage, IExtMedia, IExtVideo |
23 from pyams_content.features.checker.interfaces import IContentChecker, MISSING_VALUE, MISSING_LANG_VALUE |
29 from pyams_content.features.checker import BaseContentChecker |
30 from pyams_content.features.checker.interfaces import IContentChecker, MISSING_LANG_VALUE, MISSING_VALUE |
|
24 from pyams_content.shared.common.interfaces import IWfSharedContent |
31 from pyams_content.shared.common.interfaces import IWfSharedContent |
32 from pyams_file.file import EXTENSIONS_THUMBNAILS |
|
25 from pyams_file.interfaces import IFileInfo, IImage, IResponsiveImage |
33 from pyams_file.interfaces import IFileInfo, IImage, IResponsiveImage |
26 from pyams_i18n.interfaces import II18n, INegotiator, II18nManager |
34 from pyams_i18n.interfaces import II18n, II18nManager, INegotiator |
27 from zope.lifecycleevent.interfaces import IObjectAddedEvent, IObjectModifiedEvent, IObjectRemovedEvent |
|
28 |
|
29 # import packages |
|
30 from pyams_content.component.association import AssociationItem |
|
31 from pyams_content.features.checker import BaseContentChecker |
|
32 from pyams_file.file import EXTENSIONS_THUMBNAILS |
|
33 from pyams_i18n.property import I18nFileProperty |
35 from pyams_i18n.property import I18nFileProperty |
34 from pyams_utils.adapter import adapter_config, ContextAdapter |
36 from pyams_utils.adapter import ContextAdapter, adapter_config |
35 from pyams_utils.registry import query_utility, get_utility |
37 from pyams_utils.registry import get_utility, query_utility |
36 from pyams_utils.request import check_request |
38 from pyams_utils.request import check_request |
37 from pyams_utils.size import get_human_size |
39 from pyams_utils.size import get_human_size |
38 from pyams_utils.traversing import get_parent |
40 from pyams_utils.traversing import get_parent |
39 from pyams_utils.vocabulary import vocabulary_config |
41 from pyams_utils.vocabulary import vocabulary_config |
40 from pyramid.events import subscriber |
|
41 from pyramid.threadlocal import get_current_registry |
|
42 from zope.interface import implementer, alsoProvides |
|
43 from zope.lifecycleevent import ObjectModifiedEvent |
|
44 from zope.schema.fieldproperty import FieldProperty |
|
45 from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm |
|
46 |
42 |
47 from pyams_content import _ |
43 from pyams_content import _ |
48 |
44 |
49 |
45 |
50 EXTERNAL_FILES_FACTORIES = {} |
46 EXTERNAL_FILES_FACTORIES = {} |
85 def pictogram(self): |
81 def pictogram(self): |
86 return self.context.icon_class |
82 return self.context.icon_class |
87 |
83 |
88 @property |
84 @property |
89 def user_title(self): |
85 def user_title(self): |
86 request = check_request() |
|
87 manager_info = IExtFileManagerInfo(request.root) |
|
90 title = II18n(self.context).query_attribute('title') |
88 title = II18n(self.context).query_attribute('title') |
91 if not title: |
89 if not title: |
92 title = self.context.filename |
90 title = self.context.filename |
93 return title |
91 return '{0} {1}'.format(II18n(manager_info).query_attribute('default_title_prefix', request=request) or '', |
92 title) |
|
94 |
93 |
95 @property |
94 @property |
96 def user_icon(self): |
95 def user_icon(self): |
97 filename = self.context.filename |
96 filename = self.context.filename |
98 if filename: |
97 if filename: |
171 icon_class = 'fa-file-text-o' |
170 icon_class = 'fa-file-text-o' |
172 icon_hint = _("Standard file") |
171 icon_hint = _("Standard file") |
173 |
172 |
174 data = I18nFileProperty(IExtFile['data']) |
173 data = I18nFileProperty(IExtFile['data']) |
175 |
174 |
175 |
|
176 register_file_factory('file', ExtFile, _("Standard file")) |
176 register_file_factory('file', ExtFile, _("Standard file")) |
177 |
177 |
178 |
178 |
179 @adapter_config(context=IExtFile, provides=IContentChecker) |
179 @adapter_config(context=IExtFile, provides=IContentChecker) |
180 class ExtFileContentChecker(BaseContentChecker): |
180 class ExtFileContentChecker(BaseContentChecker): |
183 @property |
183 @property |
184 def label(self): |
184 def label(self): |
185 request = check_request() |
185 request = check_request() |
186 translate = request.localizer.translate |
186 translate = request.localizer.translate |
187 return II18n(self.context).query_attribute('title', request) or \ |
187 return II18n(self.context).query_attribute('title', request) or \ |
188 '({0})'.format(translate(self.context.icon_hint).lower()) |
188 '({0})'.format(translate(self.context.icon_hint).lower()) |
189 |
189 |
190 interface = IExtFile |
190 interface = IExtFile |
191 |
191 |
192 def inner_check(self, request): |
192 def inner_check(self, request): |
193 output = [] |
193 output = [] |
195 manager = get_parent(self.context, II18nManager) |
195 manager = get_parent(self.context, II18nManager) |
196 if manager is not None: |
196 if manager is not None: |
197 langs = manager.get_languages() |
197 langs = manager.get_languages() |
198 else: |
198 else: |
199 negotiator = get_utility(INegotiator) |
199 negotiator = get_utility(INegotiator) |
200 langs = (negotiator.server_language, ) |
200 langs = (negotiator.server_language,) |
201 i18n = II18n(self.context) |
201 i18n = II18n(self.context) |
202 for attr in ('title', 'data'): |
202 for attr in ('title', 'data'): |
203 for lang in langs: |
203 for lang in langs: |
204 value = i18n.get_attribute(attr, lang, request) |
204 value = i18n.get_attribute(attr, lang, request) |
205 if not value: |
205 if not value: |
233 self._data = value |
233 self._data = value |
234 for data in self._data.values(): |
234 for data in self._data.values(): |
235 if IImage.providedBy(data): |
235 if IImage.providedBy(data): |
236 alsoProvides(data, IResponsiveImage) |
236 alsoProvides(data, IResponsiveImage) |
237 |
237 |
238 |
|
238 register_file_factory('image', ExtImage, _("Image")) |
239 register_file_factory('image', ExtImage, _("Image")) |
239 |
240 |
240 |
241 |
241 @adapter_config(context=IExtImage, provides=IContentChecker) |
242 @adapter_config(context=IExtImage, provides=IContentChecker) |
242 class ExtImageContentChecker(ExtFileContentChecker): |
243 class ExtImageContentChecker(ExtFileContentChecker): |
252 icon_class = 'fa-file-video-o' |
253 icon_class = 'fa-file-video-o' |
253 icon_hint = _("Video") |
254 icon_hint = _("Video") |
254 |
255 |
255 data = I18nFileProperty(IExtVideo['data']) |
256 data = I18nFileProperty(IExtVideo['data']) |
256 |
257 |
258 |
|
257 register_file_factory('video', ExtVideo, _("Video")) |
259 register_file_factory('video', ExtVideo, _("Video")) |
258 |
260 |
259 |
261 |
260 @adapter_config(context=IExtVideo, provides=IContentChecker) |
262 @adapter_config(context=IExtVideo, provides=IContentChecker) |
261 class ExtVideoContentChecker(ExtFileContentChecker): |
263 class ExtVideoContentChecker(ExtFileContentChecker): |
271 icon_class = 'fa-file-audio-o' |
273 icon_class = 'fa-file-audio-o' |
272 icon_hint = _("Audio file") |
274 icon_hint = _("Audio file") |
273 |
275 |
274 data = I18nFileProperty(IExtAudio['data']) |
276 data = I18nFileProperty(IExtAudio['data']) |
275 |
277 |
278 |
|
276 register_file_factory('audio', ExtAudio, _("Audio file")) |
279 register_file_factory('audio', ExtAudio, _("Audio file")) |
277 |
280 |
278 |
281 |
279 @adapter_config(context=IExtAudio, provides=IContentChecker) |
282 @adapter_config(context=IExtAudio, provides=IContentChecker) |
280 class ExtAudioContentChecker(ExtFileContentChecker): |
283 class ExtAudioContentChecker(ExtFileContentChecker): |