|
1 # |
|
2 # Copyright (c) 2012 Thierry Florac <tflorac AT onf.fr> |
|
3 # All Rights Reserved. |
|
4 # |
|
5 |
|
6 |
|
7 # import standard packages |
|
8 |
|
9 # import Zope3 interfaces |
|
10 from z3c.json.interfaces import IJSONWriter |
|
11 from zope.tales.interfaces import ITALESFunctionNamespace |
|
12 |
|
13 # import local interfaces |
|
14 from ztfy.myams.interfaces import IMyAMSApplication, IObjectData |
|
15 from ztfy.myams.interfaces.configuration import IMyAMSConfiguration |
|
16 from ztfy.myams.tal.interfaces import IMyAMSTalesAPI |
|
17 |
|
18 # import Zope3 packages |
|
19 from zope.component import getUtility |
|
20 from zope.interface import implements |
|
21 from zope.security.proxy import removeSecurityProxy |
|
22 |
|
23 # import local packages |
|
24 from ztfy.utils.traversing import getParent |
|
25 |
|
26 |
|
27 class MyAMSTalesAdapter(object): |
|
28 """myams: TALES adapter""" |
|
29 |
|
30 implements(IMyAMSTalesAPI, ITALESFunctionNamespace) |
|
31 |
|
32 def __init__(self, context): |
|
33 self.context = context |
|
34 |
|
35 def setEngine(self, engine): |
|
36 self.request = engine.vars['request'] |
|
37 |
|
38 def data(self): |
|
39 data = IObjectData(self.context, None) |
|
40 if (data is not None) and data.object_data: |
|
41 writer = getUtility(IJSONWriter) |
|
42 return writer.write(data.object_data) |
|
43 |
|
44 def configuration(self): |
|
45 application = getParent(self.context, IMyAMSApplication) |
|
46 if application is not None: |
|
47 return IMyAMSConfiguration(application, None) |
|
48 |
|
49 def resources(self): |
|
50 application = getParent(self.context, IMyAMSApplication) |
|
51 if application is not None: |
|
52 for resource in application.resources: |
|
53 removeSecurityProxy(resource).need() |