27 from zope.traversing.interfaces import ITraversable |
27 from zope.traversing.interfaces import ITraversable |
28 |
28 |
29 # import packages |
29 # import packages |
30 from persistent import Persistent |
30 from persistent import Persistent |
31 from pyams_content.features.checker import BaseContentChecker |
31 from pyams_content.features.checker import BaseContentChecker |
32 from pyams_content.features.renderer import RenderedContentMixin, IContentRenderer |
32 from pyams_content.features.renderer import RenderedContentMixin, RenderersVocabulary |
33 from pyams_i18n.property import I18nFileProperty |
33 from pyams_i18n.property import I18nFileProperty |
34 from pyams_utils.adapter import adapter_config, ContextAdapter |
34 from pyams_utils.adapter import adapter_config, ContextAdapter |
|
35 from pyams_utils.factory import factory_config |
35 from pyams_utils.registry import query_utility, get_utility |
36 from pyams_utils.registry import query_utility, get_utility |
36 from pyams_utils.request import check_request |
37 from pyams_utils.request import check_request |
37 from pyams_utils.traversing import get_parent |
38 from pyams_utils.traversing import get_parent |
38 from pyams_utils.vocabulary import vocabulary_config |
39 from pyams_utils.vocabulary import vocabulary_config |
39 from pyramid.events import subscriber |
40 from pyramid.events import subscriber |
41 from zope.container.contained import Contained |
42 from zope.container.contained import Contained |
42 from zope.interface import implementer, alsoProvides |
43 from zope.interface import implementer, alsoProvides |
43 from zope.lifecycleevent import ObjectCreatedEvent, ObjectAddedEvent |
44 from zope.lifecycleevent import ObjectCreatedEvent, ObjectAddedEvent |
44 from zope.location import locate |
45 from zope.location import locate |
45 from zope.schema.fieldproperty import FieldProperty |
46 from zope.schema.fieldproperty import FieldProperty |
46 from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm |
|
47 |
47 |
48 from pyams_content import _ |
48 from pyams_content import _ |
49 |
49 |
50 |
50 |
51 @implementer(IIllustration) |
51 @implementer(IIllustration) |
52 class Illustration(Persistent, Contained, RenderedContentMixin): |
52 @factory_config(provided=IIllustration) |
|
53 class Illustration(RenderedContentMixin, Persistent, Contained): |
53 """Illustration persistent class""" |
54 """Illustration persistent class""" |
54 |
55 |
55 _data = I18nFileProperty(IIllustration['data']) |
56 _data = I18nFileProperty(IIllustration['data']) |
56 title = FieldProperty(IIllustration['title']) |
57 title = FieldProperty(IIllustration['title']) |
57 alt_title = FieldProperty(IIllustration['alt_title']) |
58 alt_title = FieldProperty(IIllustration['alt_title']) |
176 if illustration is not None: |
177 if illustration is not None: |
177 return IContentChecker(illustration) |
178 return IContentChecker(illustration) |
178 |
179 |
179 |
180 |
180 @vocabulary_config(name=ILLUSTRATION_RENDERERS) |
181 @vocabulary_config(name=ILLUSTRATION_RENDERERS) |
181 class IllustrationRendererVocabulary(SimpleVocabulary): |
182 class IllustrationRendererVocabulary(RenderersVocabulary): |
182 """Illustration renderers vocabulary""" |
183 """Illustration renderers vocabulary""" |
183 |
184 |
184 def __init__(self, context=None): |
185 content_interface = IIllustration |
185 request = check_request() |
|
186 translate = request.localizer.translate |
|
187 registry = request.registry |
|
188 if not IIllustration.providedBy(context): |
|
189 context = Illustration() |
|
190 terms = [SimpleTerm(name, title=translate(adapter.label)) |
|
191 for name, adapter in sorted(registry.getAdapters((context, request), IContentRenderer), |
|
192 key=lambda x: x[1].weight)] |
|
193 super(IllustrationRendererVocabulary, self).__init__(terms) |
|