Debian Codegraph @

src/launchpadlib/docs/people.rst

raw
1 ****************
2 People and Teams
3 ****************
4
5 The Launchpad web service, like Launchpad itself, exposes a unified
6 interface to people and teams. In other words, people and teams
7 occupy the same namespace. You treat people and teams as the same
8 type of object, and need to inspect the object to know whether you're
9 dealing with a person or a team.
10
11
12 People
13 ======
14
15 You can access Launchpad people through the web service interface.
16 The list of people is available from the service root.
17
18 >>> from launchpadlib.testing.helpers import salgado_with_full_permissions
19 >>> launchpad = salgado_with_full_permissions.login()
20 >>> people = launchpad.people
21
22 The list of people is not fetched until you actually use data.
23
24 >>> print(people._wadl_resource.representation)
25 None
26
27 >>> len(people)
28 4
29
30 >>> print(people._wadl_resource.representation)
31 {...}
32
33 The 'me' attribute is also available from the service root. It's a
34 quick way to get a reference to your own user account.
35
36 >>> me = launchpad.me
37 >>> print(me.name)
38 salgado
39
40 You can find a person by name.
41
42 >>> salgado = launchpad.people['salgado']
43 >>> print(salgado.name)
44 salgado
45 >>> print(salgado.display_name)
46 Guilherme Salgado
47 >>> salgado.is_team
48 False
49
50 But if no person by that name is registered, you get the expected KeyError.
51
52 >>> launchpad.people['not-a-registered-person']
53 Traceback (most recent call last):
54 ...
55 KeyError: 'not-a-registered-person'
56
57 It's not possible to slice a single person from the top-level
58 collection of people. launchpadlib will try to use the value you pass
59 in as a person's name, which will almost always fail.
60
61 >>> launchpad.people[1]
62 Traceback (most recent call last):
63 ...
64 KeyError: 1
65
66 You can find a person by email.
67
68 >>> email = salgado.preferred_email_address.email
69 >>> salgado = launchpad.people.getByEmail(email=email)
70 >>> print(salgado.name)
71 salgado
72
73 Besides a name and a display name, a person has many other attributes that you
74 can read.
75
76 XXX 05-Jun-2008 BarryWarsaw Some of these attributes are links to further
77 collections and are not yet tested. Tests will be added in future
78 branches.
79
80 >>> salgado.karma
81 0
82 >>> print(salgado.homepage_content)
83 None
84 >>> #salgado.mugshot
85 >>> #salgado.languages
86 >>> salgado.hide_email_addresses
87 False
88 >>> salgado.date_created
89 datetime.datetime(2005, 6, 6, 8, 59, 51, 596025, ...)
90 >>> print(salgado.time_zone)
91 UTC
92 >>> salgado.is_valid
93 True
94 >>> #salgado.wiki_names
95 >>> #salgado.irc_nicknames
96 >>> #salgado.jabber_ids
97 >>> #salgado.team_memberships
98 >>> #salgado.open_membership_invitations
99 >>> #salgado.teams_participated_in
100 >>> #salgado.teams_indirectly_participated_in
101 >>> #salgado.confirmed_email_addresses
102 >>> #salgado.preferred_email_address
103 >>> print(salgado.mailing_list_auto_subscribe_policy)
104 Ask me when I join a team
105 >>> print(salgado.visibility)
106 Public
107
108
109 Teams
110 =====
111
112 You also access teams using the same interface.
113
114 >>> team = launchpad.people['ubuntu-team']
115 >>> print(team.name)
116 ubuntu-team
117 >>> print(team.display_name)
118 Ubuntu Team
119 >>> team.is_team
120 True
121
122 Regular people have team attributes, but they're not used.
123
124 >>> print(salgado.team_owner)
125 None
126
127 You can find out how a person has membership in a team.
128
129 # XXX: salgado, 2008-08-01: Commented because method has been Unexported;
130 # it should be re-enabled after the operation is exported again.
131 # >>> path = salgado.findPathToTeam(
132 # ... team=launchpad.people['mailing-list-experts'])
133 # >>> [team.name for team in path]
134 # [u'admins', u'mailing-list-experts']
135
136 You can create a new team through the web interface. The simplest case of
137 this requires only the new team's name, owner and display name.
138
139 >>> launchpad.people['bassists']
140 Traceback (most recent call last):
141 ...
142 KeyError: 'bassists'
143
144 >>> bassists = launchpad.people.newTeam(
145 ... name='bassists', display_name='Awesome Rock Bass Players')
146 >>> print(bassists.name)
147 bassists
148 >>> print(bassists.display_name)
149 Awesome Rock Bass Players
150 >>> bassists.is_team
151 True
152
153 And of course, that team is now accessible directly.
154
155 >>> bassists = launchpad.people['bassists']
156 >>> print(bassists.name)
157 bassists
158 >>> print(bassists.display_name)
159 Awesome Rock Bass Players
160
161 You cannot create the same team twice.
162
163 >>> launchpad.people.newTeam(name='bassists', display_name='Bass Gods')
164 Traceback (most recent call last):
165 ...
166 lazr.restfulclient.errors.BadRequest: HTTP Error 400: Bad Request
167 ...
168
169 Actually, the exception contains other useful information.
170
171 >>> from launchpadlib.errors import HTTPError
172 >>> try:
173 ... launchpad.people.newTeam(
174 ... name='bassists', display_name='Bass Gods')
175 ... except HTTPError as e:
176 ... error = e
177 >>> error.response['status']
178 '400'
179 >>> print(error.content.decode())
180 name: bassists is already in use by another person or team.
181
182 Besides a name and a display name, a team has many other attributes that you
183 can read.
184
185 >>> bassists.karma
186 0
187 >>> print(bassists.homepage_content)
188 None
189 >>> bassists.hide_email_addresses
190 False
191 >>> bassists.date_created
192 datetime.datetime(...)
193 >>> print(bassists.time_zone)
194 UTC
195 >>> bassists.is_valid
196 True
197 >>> #bassists.team_memberships
198 >>> #bassists.open_membership_invitations
199 >>> #bassists.teams_participated_in
200 >>> #bassists.teams_indirectly_participated_in
201 >>> #bassists.confirmed_email_addresses
202 >>> #bassists.team_owner
203 >>> #bassists.preferred_email_address
204 >>> #bassists.members
205 >>> #bassists.admins
206 >>> #bassists.participants
207 >>> #bassists.deactivated_members
208 >>> #bassists.expired_members
209 >>> #bassists.invited_members
210 >>> #bassists.member_memberships
211 >>> #bassists.proposed_members
212 >>> print(bassists.visibility)
213 Public
214 >>> print(bassists.team_description)
215 None
216 >>> print(bassists.subscription_policy)
217 Moderated Team
218 >>> print(bassists.renewal_policy)
219 invite them to apply for renewal
220 >>> print(bassists.default_membership_period)
221 None
222 >>> print(bassists.default_renewal_period)
223 None