1
= View to export Vocabularies as JSON =
3
This view provides a simple means for AJAX widgets to retrieve vocabulary
4
entries until vocabularies are integrated into the REST API.
6
>>> from canonical.launchpad.interfaces.launchpad import ILaunchpadRoot
8
>>> from urllib import urlencode
9
>>> root = getUtility(ILaunchpadRoot)
10
>>> def print_json(json):
11
... data = simplejson.loads(json)
12
... print simplejson.dumps(data, sort_keys=True, indent=4)
13
>>> def create_vocabulary_view(form, context=root):
14
... # The BatchNavigator looks in the query string for GET requests.
15
... query_string = urlencode(form)
16
... return create_view(context, '+huge-vocabulary',
17
... form=form, query_string=query_string)
19
The view requires the name of the vocabulary.
21
>>> view = create_vocabulary_view({})
22
>>> print_json(view())
23
Traceback (most recent call last):
25
MissingInputError: ('name', '', None)
27
Since it is exporting huge vocabularies, it requires a search term.
29
>>> form = dict(name='ValidPerson')
30
>>> view = create_vocabulary_view(form)
31
>>> print_json(view())
32
Traceback (most recent call last):
34
MissingInputError: ('search_text', '', None)
36
The name must be a valid vocabulary.
38
>>> form = dict(name='invalid-vocabulary', search_text='foo')
39
>>> view = create_vocabulary_view(form)
40
>>> print_json(view())
41
Traceback (most recent call last):
43
UnexpectedFormData: Unknown vocabulary 'invalid-vocabulary'
45
To use the new disclosure functionality, we need to turn on the feature flag.
46
>>> from lp.services.features.testing import FeatureFixture
47
>>> feature_flag = {'disclosure.picker_enhancements.enabled': 'on'}
48
>>> flags = FeatureFixture(feature_flag)
53
>>> form = dict(name='ValidPersonOrTeam', search_text='guadamen')
54
>>> view = create_vocabulary_view(form)
55
>>> print_json(view())
59
"alt_title": "guadamen",
60
"alt_title_link": "http://launchpad.dev/~guadamen",
61
"api_uri": "/~guadamen",
63
"link_css": "js-action",
74
>>> form = dict(name='ValidPersonOrTeam', search_text='admin')
75
>>> view = create_vocabulary_view(form)
76
>>> result = simplejson.loads(view())
77
>>> result['total_size']
79
>>> len(result['entries'])
82
Size and offset parameters can be passed in to switch between batches.
84
>>> form = dict(name='ValidPersonOrTeam', search_text='admin',
85
... start='0', batch='1')
86
>>> view = create_vocabulary_view(form)
87
>>> print_json(view())
91
"alt_title": "commercial-admins",
92
"alt_title_link": "http://launchpad.dev/~commercial-admins",
93
"api_uri": "/~commercial-admins",
95
"link_css": "js-action",
97
"title": "Commercial Subscription Admins",
98
"value": "commercial-admins"
104
>>> form = dict(name='ValidPersonOrTeam', search_text='admin',
105
... start='1', batch='1')
106
>>> view = create_vocabulary_view(form)
107
>>> print_json(view())
111
"alt_title": "launchpad-buildd-admins",
113
"http://launchpad.dev/~launchpad-buildd-admins",
114
"api_uri": "/~launchpad-buildd-admins",
115
"css": "sprite team",
116
"link_css": "js-action",
118
"title": "Launchpad Buildd Admins",
119
"value": "launchpad-buildd-admins"
125
If a person is affiliated with the view context, the relevant badge(s) will be
126
included in the picker entry.
128
>>> from zope.component import getUtility
129
>>> from lp.bugs.interfaces.bugtask import IBugTaskSet
130
>>> bugtask = getUtility(IBugTaskSet).get(2)
131
>>> form = dict(name='ValidPersonOrTeam', search_text='name12',
132
... start='0', batch='1')
133
>>> view = create_vocabulary_view(form, context=bugtask)
134
>>> print_json(view())
138
"alt_title": "name12",
139
"alt_title_link": "http://launchpad.dev/~name12",
140
"api_uri": "/~name12",
143
"alt": "Affiliated with Launchpad itself",
144
"url": "/@@/product-badge"
147
"css": "sprite person",
148
"description": "<email address hidden>",
149
"link_css": "js-action",
150
"metadata": "person",
151
"title": "Sample Person",
158
Long descriptions will be truncated.
160
>>> form = dict(name='ProjectGroup', search_text='apache')
161
>>> view = create_vocabulary_view(form)
162
>>> print_json(view())
166
"api_uri": "/apache",
167
"css": "sprite project",
168
"description": "The Apache projects are characterized by...
176
Hidden email addresses should also be hidden when IPerson objects are
177
retrieved through vocabularies.
179
>>> form = dict(name='ValidPersonOrTeam', search_text='name12',
180
... start='0', batch='1')
181
>>> view = create_vocabulary_view(form)
182
>>> print_json(view())
186
"alt_title": "name12",
187
"alt_title_link": "http://launchpad.dev/~name12",
188
"api_uri": "/~name12",
189
"css": "sprite person",
190
"description": "<email address hidden>",
191
"link_css": "js-action",
192
"metadata": "person",
193
"title": "Sample Person",
200
IRC nicknames should be displayed after any email address.
202
>>> form = dict(name='ValidPersonOrTeam', search_text='mark',
203
... start='0', batch='1')
204
>>> view = create_vocabulary_view(form)
205
>>> print_json(view())
210
"alt_title_link": "http://launchpad.dev/~mark",
212
"css": "sprite person",
213
"description": "<email address hidden> (mark on irc.freenode.net)",
214
"link_css": "js-action",
215
"metadata": "person",
216
"title": "Mark Shuttleworth",
223
Clean up the feature flag.