forked from eea/eea.facetednavigation
-
Notifications
You must be signed in to change notification settings - Fork 22
/
tree.txt
263 lines (199 loc) · 8.12 KB
/
tree.txt
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
Tree module
===========
@view faceted.path.tree.json
@view faceted.path.breadcrumbs.json
This module defines browser views to be used with AJAX interface.
There are some rules that this widget should follow:
- In order to not mess up faceted query in edit mode root and default value
should by filled up from canonical language (no language independent).
- In view mode root should be language dependent if it has a translation for
current language or, it should return nothing if there is no translation
for root.
Set up
------
Imports
>>> from zope.component import getMultiAdapter
>>> from eea.facetednavigation.interfaces import ICriteria
Add english folder
>>> self.loginAsPortalOwner()
>>> fid = portal.invokeFactory('Folder', 'english')
>>> english = portal._getOb(fid)
>>> english.processForm(values={'title': 'English'}, data=1, metadata=1)
>>> english.setLanguage('en')
>>> request = english.REQUEST
Add translations
>>> _ = english.addTranslation('fr')
>>> french = english.getTranslation('fr')
>>> french.processForm(values={'title': 'French'}, data=1, metadata=1)
>>> french.absolute_url(1)
'plone/french'
>>> _ = english.addTranslation('it')
>>> italian = english.getTranslation('it')
>>> italian.processForm(values={'title': 'Italian'}, data=1, metadata=1)
>>> italian.absolute_url(1)
'plone/italian'
Make them faceted navigable
>>> subtyper = getMultiAdapter((english, request), name=u'faceted_subtyper')
>>> subtyper.enable()
>>> sync = getMultiAdapter((english, request), name=u'faceted_sync_translations')
>>> _ = sync()
Cleanup default widgets to avoid surprises
>>> criteria = ICriteria(english)
>>> cids = criteria.keys()
>>> for cid in cids:
... criteria.delete(cid)
>>> criteria.keys()
[]
Add some children
>>> fid = english.invokeFactory('Folder', 'english-child')
>>> child = english._getOb(fid)
>>> child.processForm(values={'title': 'English child'}, data=1, metadata=1)
>>> child.setLanguage('en')
>>> fid = child.invokeFactory('Folder', 'english-nephew')
>>> nephew = child._getOb(fid)
>>> nephew.processForm(values={'title': 'English nephew'}, data=1, metadata=1)
>>> nephew.setLanguage('en')
Add french translations but no Italian
>>> _ = child.addTranslation('fr')
>>> french_child = child.getTranslation('fr')
>>> french_child.processForm(values={'title': 'French child'}, data=1, metadata=1)
>>> french_child.absolute_url(1)
'plone/french/french-child'
>>> _ = nephew.addTranslation('fr')
>>> french_nephew = nephew.getTranslation('fr')
>>> french_nephew.processForm(values={'title': 'French nephew'}, data=1, metadata=1)
>>> french_nephew.absolute_url(1)
'plone/french/french-child/french-nephew'
Now that our sandbox is set up, let's see how it works
>>> handler = getMultiAdapter((english, request), name=u'faceted_configure')
@@faceted.path.tree.json
------------------------
@param cid = faceted path widget id (criterion id)
@param path = search in path
@param mode = tell if you are in view or edit mode
@return JsTree JSON object. See http://jstree.com/documentation#json
Used to display navigation tree in view and edit mode.
>>> tree_en = getMultiAdapter((english, request), name=u'faceted.path.tree.json')
>>> tree_fr = getMultiAdapter((french, request), name=u'faceted.path.tree.json')
>>> tree_it = getMultiAdapter((italian, request), name=u'faceted.path.tree.json')
Edit mode
~~~~~~~~~
In edit mode all languages should return the same tree as it is used only to
set default value.
>>> _ = handler(addPropertiesWidget_button=True, wtype='path', hidden=True,
... index='path', root='/english/english-child', default='/english-nephew')
English
'[
{"attributes": {"path": "/english-child", "id": "c0-english-child"},
"state": "closed",
"data": {"title": "english-child"}
}
]'
>>> tree_en(cid='c0', path='', mode='edit')
'[{..."path": "/english-nephew"...}]'
French
'[
{"attributes": {"path": "/english-child", "id": "c0-english-child"},
"state": "closed",
"data": {"title": "english-child"}
}
]'
>>> tree_fr(cid='c0', path='', mode='edit')
'[{..."path": "/english-nephew"...}]'
Italian
'[
{"attributes": {"path": "/english-child", "id": "c0-english-child"},
"state": "closed",
"data": {"title": "english-child"}
}
]'
>>> tree_it(cid='c0', path='', mode='edit')
'[{..."path": "/english-nephew"...}]'
View mode
~~~~~~~~~
In view mode navigation tree is language dependent
>>> _ = handler(updateCriterion_button='Save', cid='c0', hidden=0,
... root='/english', default='/english-child')
English
'[
{"attributes": {"path": "/english-child", "id": "c0-english-child"},
"state": "closed",
"data": {"title": "english-child"}
}
]'
>>> tree_en(cid='c0', path='', mode='view')
'[{..."path": "/english-child"...}]'
>>> tree_en(cid='c0', path='/english-child', mode='view')
'[{..."path": "/english-child/english-nephew"...}]'
French
'[
{"attributes": {"path": "/french-child", "id": "c0-french-child"},
"state": "closed",
"data": {"title": "french-child"}
}
]'
>>> tree_fr(cid='c0', path='', mode='view')
'[{..."path": "/french-child"...}]'
>>> tree_fr(cid='c0', path='/french-child', mode='view')
'[{..."path": "/french-child/french-nephew"...}]'
Italian has no children so return nothing
'[]'
>>> tree_it(cid='c0', path='', mode='view')
'[]'
>>> tree_it(cid='c0', path='/english-child', mode='view')
'[]'
Let's get deeper
>>> _ = handler(updateCriterion_button='Save', cid='c0', hidden=0,
... root='/english/english-child', default='/english-nephew')
English
'[
{"attributes": {"path": "/english-nephew", "id": "c0-english-nephew"},
"state": "closed",
"data": {"title": "english-nephew"}
}
]'
>>> tree_en(cid='c0', path='', mode='view')
'[{..."path": "/english-nephew"...}]'
>>> tree_en(cid='c0', path='/english-nephew', mode='view')
'[]'
French
'[
{"attributes": {"path": "/french-nephew", "id": "c0-french-nephew"},
"state": "closed",
"data": {"title": "french-nephew"}
}
]'
>>> tree_fr(cid='c0', path='', mode='view')
'[{..."path": "/french-nephew"...}]'
>>> tree_fr(cid='c0', path='/french-nephew', mode='view')
'[]'
There is no root for Italian translation so return nothing
'[]'
>>> tree_it(cid='c0', path='', mode='view')
'[]'
>>> tree_it(cid='c0', path='/english-child', mode='view')
'[]'
@@faceted.path.breadcrumbs.json
-------------------------------
@param cid = faceted path widget id (criterion id)
@param path = search in path to be converted to breadcrumbs
@return a breadcrumbs JSON object like:
[
{'url': '/publications', 'title': 'Publications'},
{'url': '/publications/a-publication', 'title': 'A publication'},
]
Used to display 'Current filters' in criteria widget. View only
>>> breadcrumbs_en = getMultiAdapter((english, request), name=u'faceted.path.breadcrumbs.json')
>>> breadcrumbs_fr = getMultiAdapter((french, request), name=u'faceted.path.breadcrumbs.json')
>>> breadcrumbs_it = getMultiAdapter((italian, request), name=u'faceted.path.breadcrumbs.json')
>>> _ = handler(updateCriterion_button='Save', cid='c0', hidden=0,
... root='/english', default='/english-child')
English
>>> breadcrumbs_en(cid='c0', path='/english-child/english-nephew')
'[{"url": "/english-child", "title": "English child"}, {"url": "/english-child/english-nephew", "title": "English nephew"}]'
French
>>> breadcrumbs_fr(cid='c0', path='/french-child/french-nephew')
'[{"url": "/french-child", "title": "French child"}, {"url": "/french-child/french-nephew", "title": "French nephew"}]'
Italian
>>> breadcrumbs_it(cid='c0', path='/english-child/english-nephew')
'[]'