|
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.shared.view.interfaces import IViewsManager, VIEW_CONTENT_TYPE |
|
20 from zope.annotation.interfaces import IAttributeAnnotatable |
|
21 from zope.component.interfaces import ISite |
|
22 from zope.lifecycleevent.interfaces import IObjectAddedEvent |
|
23 |
|
24 # import packages |
|
25 from pyams_content.shared.common.manager import SharedTool |
|
26 from pyams_content.shared.view import View |
|
27 from pyams_utils.traversing import get_parent |
|
28 from pyramid.events import subscriber |
|
29 from zope.interface import implementer |
|
30 |
|
31 |
|
32 @implementer(IViewsManager, IAttributeAnnotatable) |
|
33 class ViewsManager(SharedTool): |
|
34 """Views manager class""" |
|
35 |
|
36 shared_content_type = VIEW_CONTENT_TYPE |
|
37 shared_content_factory = View |
|
38 |
|
39 |
|
40 @subscriber(IObjectAddedEvent, context_selector=IViewsManager) |
|
41 def handle_added_views_manager(event): |
|
42 """Register views manager when added""" |
|
43 site = get_parent(event.newParent, ISite) |
|
44 registry = site.getSiteManager() |
|
45 if registry is not None: |
|
46 registry.registerUtility(event.object, IViewsManager) |