/
render.py
123 lines (103 loc) · 3.83 KB
/
render.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
"""
Use adapters based on zope3 interfaces to model Breve tree rendering.
Perhaps later create maker interfaces for docutils publishing.
"""
import _conf
import api
from tag import bluelines, atom
from interface import *
from zope.interface import directlyProvides, interface, declarations,\
implements, providedBy
from breve import Template
from gate import compy
from docutils import nodes
components = compy.getRegistry()
# Generic handler to provide IBlueLinesXML trees using Breve templates
def _blml_tree(name, data, fragments={}): # {{{
"""
See templates in var/breve/xml, using nodes from tags.bluelines.
"""
tpl = Template(bluelines.tags, root=_conf.TPL_ROOT, xmlns=bluelines.xmlns)
auth = api.get_current_user()
brevetree = tpl._evaluate(
_conf.BREVE_TPL('xml', name),
fragments=fragments,
vars={
'__'+name+'__': data,
'API': _conf.API,
'__auth__': auth,
},
)
return bluelines.tags.blueLines(
version=_conf.VERSION,
base=_conf.BASE_URL,
auth=auth.email,
)[brevetree]
# }}}
def _blml_query(q): # {{{
listSchema = components.lookup1(q.schema, IListSchema)
brevetree = components.lookup1(listSchema, IBlueLinesXML, 'api')(q.value)
auth = api.get_current_user()
return bluelines.tags.blueLines(
version=_conf.VERSION,
base=_conf.BASE_URL,
auth=auth.email,
)[
bluelines.tags.query(**q.props)[
brevetree.children[0]
]
]
# }}}
# Register the IBlueLinesXML target interface for model schemas
breveXMLAdapter_types = [
(IUser, 'user'),
(IAlias, 'alias'),
(ISource, 'source'),
(ISourceInfo, 'info'),
(IBuilderConfig, 'config'),
(IProcessConfig, 'config'),
(IPublishConfig, 'config'),
(IError, 'error'),
]
breveXMLAdapter_listTypes = [
(IUserDir, 'user_dir'),
(IAliasDir, 'alias_dir'),
(IUserList, 'user_list'),
(IAliasList, 'alias_list'),
(ISourceList, 'source_list'),
(ISourceInfoList, 'info_list'),
(IConfigList, 'config_list'),
]
def _bl_adapter(tplName):
def _x(model):
return _blml_tree(tplName, model)
return _x
for schema , tplName in breveXMLAdapter_types:
components.register([schema], IBlueLinesXML, 'api', _bl_adapter(tplName))
for listSchema, tplName in breveXMLAdapter_listTypes:
#model = components.lookup1(schema, IModel)
components.register([listSchema], IBlueLinesXML, 'api', _bl_adapter(tplName))
#components.register([ISchema], IBlueLinesXML, 'api', _render_schema)
#components.register([IModel], IBlueLinesXML, 'api', _render_model)
components.register([IQuery], IBlueLinesXML, 'api', _blml_query)
def _blml_api_result(r):
return str(r)
components.register([IResult], IBlueLinesXML, 'api', _blml_api_result)
# TODO: adapt model ('schema-instance') to XML instead of schema
#components.register([IStatModel], IBlueLinesXML, 'api', )
#components.register([IQuery], IBlueLinesXML, 'api', )
#components.register([IQuery], IBlueLinesForm, 'api', )
"""
#items = q.fetch(100,0)
return components.lookup1(schema, )(props, q)
from gate import compy
print compy.getRegistry().queryAdapter(interface.IAlias, interface.IModel)
print compy.getRegistry().lookup1(interface.IAlias, interface.IModel)
components.queryAdapter(data, )
#logging.info("got instance %s", instance)
#logging.info([instance, targetInterface, name])
adapter = getRegistry().lookup1(sourceInterface, targetInterface,
name)
assert adapter
adapted = adapter(instance)
"""