|
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 from chameleon import PageTemplateFile |
|
16 from persistent.interfaces import IPersistent |
|
17 from z3c.pt.pagetemplate import PageTemplateFile as Z3cPageTemplateFile |
|
18 from zope.annotation.attribute import AttributeAnnotations |
|
19 from zope.annotation.interfaces import IAnnotations, IAttributeAnnotatable |
|
20 from zope.keyreference.interfaces import IKeyReference |
|
21 from zope.keyreference.persistent import KeyReferenceToPersistent |
|
22 |
|
23 from pyams_utils.container import ParentSelector |
|
24 from pyams_utils.context import ContextSelector |
|
25 from pyams_utils.i18n import set_locales |
|
26 from pyams_utils.request import RequestSelector, get_annotations, get_debug |
|
27 from pyams_utils.site import site_factory |
|
28 from pyams_utils.tales import ExtensionExpr |
|
29 from pyams_utils.url import get_display_context |
|
30 from pyams_utils.traversing import NamespaceTraverser |
|
31 |
|
32 |
|
33 def include_package(config): |
|
34 """Pyramid package include""" |
|
35 |
|
36 # add translations |
|
37 config.add_translation_dirs('pyams_utils:locales') |
|
38 |
|
39 # define locale |
|
40 set_locales(config.registry.settings) |
|
41 |
|
42 # define root factory |
|
43 config.set_root_factory(site_factory) |
|
44 |
|
45 # add request annotations |
|
46 config.add_request_method(get_annotations, 'annotations', reify=True) |
|
47 config.add_request_method(get_debug, 'debug', reify=True) |
|
48 config.add_request_method(get_display_context, 'display_context', property=True) |
|
49 |
|
50 # add traverser handling namespaces via "++ns++(options)" URLs |
|
51 config.add_traverser(NamespaceTraverser) |
|
52 |
|
53 # add custom subscriber predicate to filter events via supported interface(s) |
|
54 config.add_subscriber_predicate('context_selector', ContextSelector) |
|
55 config.add_subscriber_predicate('parent_selector', ParentSelector) |
|
56 config.add_subscriber_predicate('request_selector', RequestSelector) |
|
57 |
|
58 # load registry components |
|
59 config.registry.registerAdapter(AttributeAnnotations, (IAttributeAnnotatable, ), IAnnotations) |
|
60 config.registry.registerAdapter(KeyReferenceToPersistent, (IPersistent, ), IKeyReference) |
|
61 |
|
62 try: |
|
63 import pyams_zmi |
|
64 except ImportError: |
|
65 config.scan(ignore='pyams_utils.zmi') |
|
66 else: |
|
67 config.scan() |
|
68 |
|
69 if hasattr(config, 'load_zcml'): |
|
70 config.load_zcml('configure.zcml') |
|
71 |
|
72 PageTemplateFile.expression_types['tales'] = ExtensionExpr |
|
73 Z3cPageTemplateFile.expression_types['tales'] = ExtensionExpr |