17 |
17 |
18 # import interfaces |
18 # import interfaces |
19 from pyams_portal.interfaces import IPortalTemplateContainer, IPortalTemplateContainerConfiguration, \ |
19 from pyams_portal.interfaces import IPortalTemplateContainer, IPortalTemplateContainerConfiguration, \ |
20 IPortalTemplate, IPortalTemplateConfiguration, IPortalPortletsConfiguration, IPortlet, IPortletConfiguration, \ |
20 IPortalTemplate, IPortalTemplateConfiguration, IPortalPortletsConfiguration, IPortlet, IPortletConfiguration, \ |
21 PORTLETS_CONFIGURATION_KEY, TEMPLATE_CONTAINER_CONFIGURATION_KEY, TEMPLATE_CONFIGURATION_KEY |
21 PORTLETS_CONFIGURATION_KEY, TEMPLATE_CONTAINER_CONFIGURATION_KEY, TEMPLATE_CONFIGURATION_KEY |
22 from zope.annotation.interfaces import IAnnotations |
|
23 from zope.lifecycleevent.interfaces import IObjectAddedEvent, IObjectRemovedEvent |
22 from zope.lifecycleevent.interfaces import IObjectAddedEvent, IObjectRemovedEvent |
24 from zope.traversing.interfaces import ITraversable |
23 from zope.traversing.interfaces import ITraversable |
25 |
24 |
26 # import packages |
25 # import packages |
27 from persistent import Persistent |
26 from persistent import Persistent |
28 from persistent.list import PersistentList |
27 from persistent.list import PersistentList |
29 from persistent.mapping import PersistentMapping |
28 from persistent.mapping import PersistentMapping |
30 from pyams_portal.portlet import PortalPortletsConfiguration |
29 from pyams_portal.portlet import PortalPortletsConfiguration |
31 from pyams_portal.slot import SlotConfiguration |
30 from pyams_portal.slot import SlotConfiguration |
32 from pyams_utils.adapter import adapter_config, ContextAdapter |
31 from pyams_utils.adapter import adapter_config, ContextAdapter, get_annotation_adapter |
33 from pyams_utils.registry import get_local_registry, get_utility |
32 from pyams_utils.registry import get_local_registry, get_utility |
34 from pyams_utils.request import check_request |
33 from pyams_utils.request import check_request |
35 from pyams_utils.vocabulary import vocabulary_config |
34 from pyams_utils.vocabulary import vocabulary_config |
36 from pyramid.events import subscriber |
35 from pyramid.events import subscriber |
37 from pyramid.threadlocal import get_current_registry |
36 from pyramid.threadlocal import get_current_registry |
38 from zope.componentvocabulary.vocabulary import UtilityVocabulary |
37 from zope.componentvocabulary.vocabulary import UtilityVocabulary |
39 from zope.container.contained import Contained |
38 from zope.container.contained import Contained |
40 from zope.container.folder import Folder |
39 from zope.container.folder import Folder |
41 from zope.copy import clone |
|
42 from zope.interface import implementer |
40 from zope.interface import implementer |
43 from zope.lifecycleevent import ObjectCreatedEvent |
|
44 from zope.location import locate |
41 from zope.location import locate |
45 from zope.schema.fieldproperty import FieldProperty |
42 from zope.schema.fieldproperty import FieldProperty |
46 from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm |
43 from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm |
47 |
44 |
48 |
45 |
69 |
66 |
70 |
67 |
71 @adapter_config(context=IPortalTemplateContainer, provides=IPortalTemplateContainerConfiguration) |
68 @adapter_config(context=IPortalTemplateContainer, provides=IPortalTemplateContainerConfiguration) |
72 def portal_template_container_configuration_adapter(context): |
69 def portal_template_container_configuration_adapter(context): |
73 """Portal template container configuration factory""" |
70 """Portal template container configuration factory""" |
74 annotations = IAnnotations(context) |
71 return get_annotation_adapter(context, TEMPLATE_CONTAINER_CONFIGURATION_KEY, PortalTemplateContainerConfiguration) |
75 config = annotations.get(TEMPLATE_CONTAINER_CONFIGURATION_KEY) |
|
76 if config is None: |
|
77 config = annotations[TEMPLATE_CONTAINER_CONFIGURATION_KEY] = PortalTemplateContainerConfiguration() |
|
78 get_current_registry().notify(ObjectCreatedEvent(config)) |
|
79 locate(config, context) |
|
80 return config |
|
81 |
72 |
82 |
73 |
83 # |
74 # |
84 # Portal template base class |
75 # Portal template base class |
85 # |
76 # |
319 |
310 |
320 |
311 |
321 @adapter_config(context=IPortalTemplate, provides=IPortalTemplateConfiguration) |
312 @adapter_config(context=IPortalTemplate, provides=IPortalTemplateConfiguration) |
322 def portal_template_configuration_factory(context): |
313 def portal_template_configuration_factory(context): |
323 """Portal template configuration adapter""" |
314 """Portal template configuration adapter""" |
324 annotations = IAnnotations(context) |
315 return get_annotation_adapter(context, TEMPLATE_CONFIGURATION_KEY, PortalTemplateConfiguration) |
325 config = annotations.get(TEMPLATE_CONFIGURATION_KEY) |
|
326 if config is None: |
|
327 config = annotations[TEMPLATE_CONFIGURATION_KEY] = PortalTemplateConfiguration() |
|
328 get_current_registry().notify(ObjectCreatedEvent(config)) |
|
329 locate(config, context) |
|
330 return config |
|
331 |
316 |
332 |
317 |
333 @adapter_config(name='portlet', context=IPortalTemplate, provides=ITraversable) |
318 @adapter_config(name='portlet', context=IPortalTemplate, provides=ITraversable) |
334 class PortalTemplatePortletTraverser(ContextAdapter): |
319 class PortalTemplatePortletTraverser(ContextAdapter): |
335 """++portlet++ template traverser""" |
320 """++portlet++ template traverser""" |
347 # |
332 # |
348 |
333 |
349 @adapter_config(context=IPortalTemplate, provides=IPortalPortletsConfiguration) |
334 @adapter_config(context=IPortalTemplate, provides=IPortalPortletsConfiguration) |
350 def portal_template_portlets_configuration_adapter(template): |
335 def portal_template_portlets_configuration_adapter(template): |
351 """Portal template portlets configuration adapter""" |
336 """Portal template portlets configuration adapter""" |
352 annotations = IAnnotations(template) |
337 return get_annotation_adapter(template, PORTLETS_CONFIGURATION_KEY, PortalPortletsConfiguration) |
353 config = annotations.get(PORTLETS_CONFIGURATION_KEY) |
|
354 if config is None: |
|
355 config = annotations[PORTLETS_CONFIGURATION_KEY] = PortalPortletsConfiguration() |
|
356 get_current_registry().notify(ObjectCreatedEvent(config)) |
|
357 locate(config, template) |
|
358 return config |
|