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
|
= Displaying Information on Bugs and Bug Tasks =
This document discusses TALES techniques and IBugTask object
attributes that may be useful to you, if you're writing some code to
display bug and bug task information.
== Displaying an Icon with image:icon ==
image:sprite_css is a TALES adapter that returns the CSS class for
an icon for a bugtask.
The icon is dependent on the importance of the IBugTask object.
Let's use a few examples to demonstrate:
>>> from zope.component import getUtility
>>> from lp.services.webapp.interfaces import ILaunchBag
>>> from lp.bugs.interfaces.bugtask import BugTaskImportance, IBugTaskSet
>>> from lp.testing import (
... login,
... test_tales,
... )
>>> login("foo.bar@canonical.com")
>>> bugtaskset = getUtility(IBugTaskSet)
>>> test_task = bugtaskset.get(4)
>>> ORIGINAL_IMPORTANCE = test_task.importance
>>> test_task.transitionToImportance(
... BugTaskImportance.CRITICAL, getUtility(ILaunchBag).user)
>>> test_tales("bugtask/image:sprite_css", bugtask=test_task)
'sprite bug-critical'
>>> test_task.transitionToImportance(
... BugTaskImportance.HIGH, getUtility(ILaunchBag).user)
>>> test_tales("bugtask/image:sprite_css", bugtask=test_task)
'sprite bug-high'
>>> test_task.transitionToImportance(
... BugTaskImportance.MEDIUM, getUtility(ILaunchBag).user)
>>> test_tales("bugtask/image:sprite_css", bugtask=test_task)
'sprite bug-medium'
>>> test_task.transitionToImportance(
... BugTaskImportance.LOW, getUtility(ILaunchBag).user)
>>> test_tales("bugtask/image:sprite_css", bugtask=test_task)
'sprite bug-low'
>>> test_task.transitionToImportance(
... BugTaskImportance.WISHLIST, getUtility(ILaunchBag).user)
>>> test_tales("bugtask/image:sprite_css", bugtask=test_task)
'sprite bug-wishlist'
>>> test_task.transitionToImportance(
... BugTaskImportance.UNDECIDED, getUtility(ILaunchBag).user)
>>> test_tales("bugtask/image:sprite_css", bugtask=test_task)
'sprite bug-undecided'
>>> test_task.transitionToImportance(
... ORIGINAL_IMPORTANCE, getUtility(ILaunchBag).user)
== Displaying Logos for Bug Tasks ==
The logo for a bug task display the corresponding logo for its
target.
>>> from lp.bugs.interfaces.bug import IBugSet
>>> bug1 = getUtility(IBugSet).get(1)
>>> upstream_task = bug1.bugtasks[0]
>>> print upstream_task.product.name
firefox
>>> ubuntu_task = bug1.bugtasks[1]
>>> print ubuntu_task.distribution.name
ubuntu
So the logo for an upstream bug task shows the project icon:
>>> test_tales("bugtask/image:logo", bugtask=upstream_task)
'<img alt="" width="64" height="64" src="/@@/product-logo" />'
And the logo for a distro bug task shows the source package icon:
>>> test_tales("bugtask/image:logo", bugtask=ubuntu_task)
'<img alt="" width="64" height="64" src="/@@/distribution-logo" />'
== Displaying Status ==
Sometimes it's useful to display the status of an IBugTask as a
human-readable string. So, instead of displaying something like:
Status: Confirmed, Assignee: foo.bar@canonical.com
you might prefer that to read, simply:
assigned to Foo Bar
We define a helper that uses the BugTaskListingView class (obtained via
+listing-view) to render the status:
>>> from zope.component import getMultiAdapter
>>> from lp.services.webapp.interfaces import ILaunchBag
>>> from lp.services.webapp.servers import LaunchpadTestRequest
>>> from lp.bugs.interfaces.bugtask import BugTaskStatus
>>> def render_bugtask_status(task):
... view = getMultiAdapter(
... (task, LaunchpadTestRequest()), name="+listing-view")
... return view.status
Let's see some examples of how this works:
>>> login("foo.bar@canonical.com", LaunchpadTestRequest())
>>> foobar = getUtility(ILaunchBag).user
>>> ORIGINAL_STATUS = test_task.status
>>> ORIGINAL_ASSIGNEE = test_task.assignee
>>> test_task.transitionToAssignee(None)
>>> render_bugtask_status(test_task)
'Confirmed (unassigned)'
>>> test_task.transitionToAssignee(foobar)
>>> test_task.transitionToStatus(
... BugTaskStatus.NEW, getUtility(ILaunchBag).user)
>>> render_bugtask_status(test_task)
u'New, assigned to ...Foo Bar...'
>>> test_task.transitionToStatus(
... BugTaskStatus.CONFIRMED, getUtility(ILaunchBag).user)
>>> render_bugtask_status(test_task)
u'Confirmed, assigned to ...Foo Bar...'
>>> test_task.transitionToStatus(
... BugTaskStatus.INVALID, getUtility(ILaunchBag).user)
>>> render_bugtask_status(test_task)
u'Invalid by ...Foo Bar...'
>>> test_task.transitionToAssignee(None)
>>> render_bugtask_status(test_task)
'Invalid (unassigned)'
>>> test_task.transitionToStatus(
... BugTaskStatus.FIXRELEASED, getUtility(ILaunchBag).user)
>>> render_bugtask_status(test_task)
'Fix released (unassigned)'
>>> test_task.transitionToAssignee(foobar)
>>> render_bugtask_status(test_task)
u'Fix released, assigned to ...Foo Bar...'
Lastly, some cleanup:
>>> test_task.transitionToStatus(
... ORIGINAL_STATUS, test_task.distribution.owner)
>>> test_task.transitionToAssignee(ORIGINAL_ASSIGNEE)
== Status Elsewhere ==
It's often useful to present information about the status of a bug in
other contexts. Again, the listing-view holds a method which provides us
with this information; let's define a helper for it:
>>> def render_bugtask_status_elsewhere(task):
... view = getMultiAdapter(
... (task, LaunchpadTestRequest()), name="+listing-view")
... return view.status_elsewhere
The main questions of interest, in order, are:
1. Has this bug been fixed elsewhere?
2. Has this bug been reported elsewhere?
Let's see some examples:
>>> render_bugtask_status_elsewhere(bugtaskset.get(13))
'not filed elsewhere'
>>> render_bugtask_status_elsewhere(bugtaskset.get(2))
'filed in 2 other places'
Let's take a random task related to task 2, mark it Fixed, and see how the
statuselsewhere value is affected:
>>> related_task = bugtaskset.get(2).related_tasks[0]
>>> ORIGINAL_STATUS = related_task.status
>>> related_task.transitionToStatus(
... BugTaskStatus.FIXRELEASED, getUtility(ILaunchBag).user)
>>> render_bugtask_status_elsewhere(bugtaskset.get(2))
'fixed in 1 of 3 places'
>>> related_task.transitionToStatus(
... ORIGINAL_STATUS, getUtility(ILaunchBag).user)
|