19 from pyams_content.component.illustration.interfaces import IIllustration, IIllustrationTarget, \ |
19 from pyams_content.component.illustration.interfaces import IIllustration, IIllustrationTarget, \ |
20 ILLUSTRATION_KEY, ILLUSTRATION_RENDERERS |
20 ILLUSTRATION_KEY, ILLUSTRATION_RENDERERS |
21 from pyams_content.features.checker.interfaces import IContentChecker, MISSING_VALUE, MISSING_LANG_VALUE |
21 from pyams_content.features.checker.interfaces import IContentChecker, MISSING_VALUE, MISSING_LANG_VALUE |
22 from pyams_file.interfaces import IFileInfo, IImage, IResponsiveImage |
22 from pyams_file.interfaces import IFileInfo, IImage, IResponsiveImage |
23 from pyams_i18n.interfaces import INegotiator, II18n, II18nManager |
23 from pyams_i18n.interfaces import INegotiator, II18n, II18nManager |
24 from zope.annotation.interfaces import IAnnotations |
|
25 from zope.lifecycleevent.interfaces import IObjectAddedEvent, IObjectModifiedEvent |
24 from zope.lifecycleevent.interfaces import IObjectAddedEvent, IObjectModifiedEvent |
26 from zope.location.interfaces import ISublocations |
25 from zope.location.interfaces import ISublocations |
27 from zope.traversing.interfaces import ITraversable |
26 from zope.traversing.interfaces import ITraversable |
28 |
27 |
29 # import packages |
28 # import packages |
30 from persistent import Persistent |
29 from persistent import Persistent |
31 from pyams_content.features.checker import BaseContentChecker |
30 from pyams_content.features.checker import BaseContentChecker |
32 from pyams_content.features.renderer import RenderedContentMixin, RenderersVocabulary |
31 from pyams_content.features.renderer import RenderedContentMixin, RenderersVocabulary |
33 from pyams_i18n.property import I18nFileProperty |
32 from pyams_i18n.property import I18nFileProperty |
34 from pyams_utils.adapter import adapter_config, ContextAdapter |
33 from pyams_utils.adapter import adapter_config, ContextAdapter, get_annotation_adapter |
35 from pyams_utils.factory import factory_config |
34 from pyams_utils.factory import factory_config |
36 from pyams_utils.registry import query_utility, get_utility |
35 from pyams_utils.registry import query_utility, get_utility |
37 from pyams_utils.request import check_request |
36 from pyams_utils.request import check_request |
38 from pyams_utils.traversing import get_parent |
37 from pyams_utils.traversing import get_parent |
39 from pyams_utils.vocabulary import vocabulary_config |
38 from pyams_utils.vocabulary import vocabulary_config |
40 from pyramid.events import subscriber |
39 from pyramid.events import subscriber |
41 from pyramid.threadlocal import get_current_registry |
40 from pyramid.threadlocal import get_current_registry |
42 from zope.container.contained import Contained |
41 from zope.container.contained import Contained |
43 from zope.interface import implementer, alsoProvides |
42 from zope.interface import implementer, alsoProvides |
44 from zope.lifecycleevent import ObjectCreatedEvent, ObjectAddedEvent |
43 from zope.lifecycleevent import ObjectCreatedEvent, ObjectAddedEvent |
45 from zope.location import locate |
|
46 from zope.schema.fieldproperty import FieldProperty |
44 from zope.schema.fieldproperty import FieldProperty |
47 |
45 |
48 from pyams_content import _ |
46 from pyams_content import _ |
49 |
47 |
50 |
48 |
73 |
71 |
74 |
72 |
75 @adapter_config(context=IIllustrationTarget, provides=IIllustration) |
73 @adapter_config(context=IIllustrationTarget, provides=IIllustration) |
76 def illustration_factory(context): |
74 def illustration_factory(context): |
77 """Illustration factory""" |
75 """Illustration factory""" |
78 annotations = IAnnotations(context) |
76 |
79 illustration = annotations.get(ILLUSTRATION_KEY) |
77 def illustration_callback(illustration): |
80 if illustration is None: |
78 get_current_registry().notify(ObjectAddedEvent(illustration, context, illustration.__name__)) |
81 illustration = annotations[ILLUSTRATION_KEY] = Illustration() |
79 |
82 registry = get_current_registry() |
80 return get_annotation_adapter(context, ILLUSTRATION_KEY, Illustration, |
83 registry.notify(ObjectCreatedEvent(illustration)) |
81 name='++illustration++', |
84 locate(illustration, context, '++illustration++') |
82 callback=illustration_callback) |
85 registry.notify(ObjectAddedEvent(illustration, context, '++illustration++')) |
|
86 return illustration |
|
87 |
83 |
88 |
84 |
89 def update_illustration_properties(illustration): |
85 def update_illustration_properties(illustration): |
90 """Update missing file properties""" |
86 """Update missing file properties""" |
91 request = check_request() |
87 request = check_request() |