~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/canonical/launchpad/doc/vocabulary-json.txt

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-08-04 20:34:35 UTC
  • mfrom: (13608.1.4 person-picker-expand-1)
  • Revision ID: launchpad@pqm.canonical.com-20110804203435-o5cob6ra9jw8hev1
[r=jcsackett][bug=800361,
        798759] Restore picker expander and place it behind its own flag.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
= View to export Vocabularies as  JSON =
2
 
 
3
 
This view provides a simple means for AJAX widgets to retrieve vocabulary
4
 
entries until vocabularies are integrated into the REST API.
5
 
 
6
 
    >>> from canonical.launchpad.interfaces.launchpad import ILaunchpadRoot
7
 
    >>> import simplejson
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)
18
 
 
19
 
The view requires the name of the vocabulary.
20
 
 
21
 
    >>> view = create_vocabulary_view({})
22
 
    >>> print_json(view())
23
 
    Traceback (most recent call last):
24
 
    ...
25
 
    MissingInputError: ('name', '', None)
26
 
 
27
 
Since it is exporting huge vocabularies, it requires a search term.
28
 
 
29
 
    >>> form = dict(name='ValidPerson')
30
 
    >>> view = create_vocabulary_view(form)
31
 
    >>> print_json(view())
32
 
    Traceback (most recent call last):
33
 
    ...
34
 
    MissingInputError: ('search_text', '', None)
35
 
 
36
 
The name must be a valid vocabulary.
37
 
 
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):
42
 
    ...
43
 
    UnexpectedFormData: Unknown vocabulary 'invalid-vocabulary'
44
 
 
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)
49
 
    >>> flags.setUp()
50
 
 
51
 
A successful search.
52
 
 
53
 
    >>> form = dict(name='ValidPersonOrTeam', search_text='guadamen')
54
 
    >>> view = create_vocabulary_view(form)
55
 
    >>> print_json(view())
56
 
    {
57
 
        "entries": [
58
 
            {
59
 
                "alt_title": "guadamen",
60
 
                "alt_title_link": "http://launchpad.dev/~guadamen",
61
 
                "api_uri": "/~guadamen",
62
 
                "css": "sprite team",
63
 
                "link_css": "js-action",
64
 
                "metadata": "team",
65
 
                "title": "GuadaMen",
66
 
                "value": "guadamen"
67
 
            }
68
 
        ],
69
 
        "total_size": 1
70
 
    }
71
 
 
72
 
Multiple entries.
73
 
 
74
 
    >>> form = dict(name='ValidPersonOrTeam', search_text='admin')
75
 
    >>> view = create_vocabulary_view(form)
76
 
    >>> result = simplejson.loads(view())
77
 
    >>> result['total_size']
78
 
    6
79
 
    >>> len(result['entries'])
80
 
    5
81
 
 
82
 
Size and offset parameters can be passed in to switch between batches.
83
 
 
84
 
    >>> form = dict(name='ValidPersonOrTeam', search_text='admin',
85
 
    ...             start='0', batch='1')
86
 
    >>> view = create_vocabulary_view(form)
87
 
    >>> print_json(view())
88
 
    {
89
 
        "entries": [
90
 
            {
91
 
                "alt_title": "commercial-admins",
92
 
                "alt_title_link": "http://launchpad.dev/~commercial-admins",
93
 
                "api_uri": "/~commercial-admins",
94
 
                "css": "sprite team",
95
 
                "link_css": "js-action",
96
 
                "metadata": "team",
97
 
                "title": "Commercial Subscription Admins",
98
 
                "value": "commercial-admins"
99
 
            }
100
 
        ],
101
 
        "total_size": 6
102
 
    }
103
 
 
104
 
    >>> form = dict(name='ValidPersonOrTeam', search_text='admin',
105
 
    ...             start='1', batch='1')
106
 
    >>> view = create_vocabulary_view(form)
107
 
    >>> print_json(view())
108
 
    {
109
 
        "entries": [
110
 
            {
111
 
                "alt_title": "launchpad-buildd-admins",
112
 
                "alt_title_link":
113
 
                    "http://launchpad.dev/~launchpad-buildd-admins",
114
 
                "api_uri": "/~launchpad-buildd-admins",
115
 
                "css": "sprite team",
116
 
                "link_css": "js-action",
117
 
                "metadata": "team",
118
 
                "title": "Launchpad Buildd Admins",
119
 
                "value": "launchpad-buildd-admins"
120
 
            }
121
 
        ],
122
 
        "total_size": 6
123
 
    }
124
 
 
125
 
If a person is affiliated with the view context, the relevant badge(s) will be
126
 
included in the picker entry.
127
 
 
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())
135
 
    {
136
 
        "entries": [
137
 
            {
138
 
                "alt_title": "name12",
139
 
                "alt_title_link": "http://launchpad.dev/~name12",
140
 
                "api_uri": "/~name12",
141
 
                "badges": [
142
 
                     {
143
 
                         "alt": "Affiliated with Launchpad itself",
144
 
                         "url": "/@@/product-badge"
145
 
                     }
146
 
                 ],
147
 
                "css": "sprite person",
148
 
                "description": "<email address hidden>",
149
 
                "link_css": "js-action",
150
 
                "metadata": "person",
151
 
                "title": "Sample Person",
152
 
                "value": "name12"
153
 
            }
154
 
        ],
155
 
        "total_size": 1
156
 
    }
157
 
 
158
 
Long descriptions will be truncated.
159
 
 
160
 
    >>> form = dict(name='ProjectGroup', search_text='apache')
161
 
    >>> view = create_vocabulary_view(form)
162
 
    >>> print_json(view())
163
 
    {
164
 
        "entries": [
165
 
            {
166
 
                "api_uri": "/apache",
167
 
                "css": "sprite project",
168
 
                "description": "The Apache projects are characterized by...
169
 
                "title": "Apache",
170
 
                "value": "apache"
171
 
            }
172
 
        ],
173
 
        "total_size": 1
174
 
    }
175
 
 
176
 
Hidden email addresses should also be hidden when IPerson objects are
177
 
retrieved through vocabularies.
178
 
 
179
 
    >>> form = dict(name='ValidPersonOrTeam', search_text='name12',
180
 
    ...             start='0', batch='1')
181
 
    >>> view = create_vocabulary_view(form)
182
 
    >>> print_json(view())
183
 
    {
184
 
        "entries": [
185
 
            {
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",
194
 
                "value": "name12"
195
 
            }
196
 
        ],
197
 
        "total_size": 1
198
 
    }
199
 
 
200
 
IRC nicknames should be displayed after any email address.
201
 
 
202
 
    >>> form = dict(name='ValidPersonOrTeam', search_text='mark',
203
 
    ...             start='0', batch='1')
204
 
    >>> view = create_vocabulary_view(form)
205
 
    >>> print_json(view())
206
 
    {
207
 
        "entries": [
208
 
            {
209
 
                "alt_title": "mark",
210
 
                "alt_title_link": "http://launchpad.dev/~mark",
211
 
                "api_uri": "/~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",
217
 
                "value": "mark"
218
 
            }
219
 
        ],
220
 
        "total_size": 1
221
 
    }
222
 
 
223
 
Clean up the feature flag.
224
 
    >>> flags.cleanUp()