Merge lp:~deryck/launchpad/hot-bugtasks-to-hot-bugs-442170 into lp:launchpad/db-devel

Proposed by Deryck Hodge
Status: Merged
Approved by: Eleanor Berger
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~deryck/launchpad/hot-bugtasks-to-hot-bugs-442170
Merge into: lp:launchpad/db-devel
Diff against target: 186 lines (+72/-30)
4 files modified
lib/lp/bugs/browser/bugtarget.py (+21/-0)
lib/lp/bugs/browser/bugtask.py (+0/-9)
lib/lp/bugs/stories/bugs/xx-product-bugs-page.txt (+48/-18)
lib/lp/bugs/templates/bugtarget-bugs.pt (+3/-3)
To merge this branch: bzr merge lp:~deryck/launchpad/hot-bugtasks-to-hot-bugs-442170
Reviewer Review Type Date Requested Status
Eleanor Berger (community) Approve
Review via email: mp+17826@code.launchpad.net

Commit message

Make the method getting a hot bugs list get bugs by heat rather than recently touched bugtasks.

To post a comment you must log in.
Revision history for this message
Deryck Hodge (deryck) wrote :

This branch moves the hot_bugtasks method from the bug listing view to a hot_bugs method on a bug target view, which changes the behavior to return 10 bugs according to heat rather than recently touched bug tasks.

This change also allows us to fix Bug #442170, since the code ensures the same bug isn't shown twice. The code uses default_bugtask for display.

The "hot bugs" test in stories/bugs/xx-product-bugs-page.txt has been updated to use factory data, rather than sample data, and to test that bugs are listed by heat.

The branch builds on a branch from Tom/Brian M. that allows sorting by heat, so the diff for my changes is pasted:

http://pastebin.ubuntu.com/360139/

Revision history for this message
Eleanor Berger (intellectronica) wrote :

At last, real hot bugs!!!

We've discussed a few minor changes:

1. Exiting from the loop instead of returning twice in hot_bugs.
2. Accessing bug/prop instead of bug/default_bugtask/bug/prop in the template.

Everything else looks great.

review: Approve
Revision history for this message
Eleanor Berger (intellectronica) wrote :

On further discussion, we realised that there's a subtle problem with using the default_bugtask, since it isn't necessarily a task on the same bugtarget we're viewing. Instead of returning bugs, we should return the task we got back from searchTasks. That does complicate the loop in hot_bugs a bit.

review: Needs Fixing
Revision history for this message
Deryck Hodge (deryck) wrote :
Download full text (3.9 KiB)

I believe I've fixed everything now. Latest incremental diff:

=== modified file 'lib/lp/bugs/browser/bugtarget.py'
--- lib/lp/bugs/browser/bugtarget.py 2010-01-20 18:27:12 +0000
+++ lib/lp/bugs/browser/bugtarget.py 2010-01-21 17:51:36 +0000
@@ -1264,12 +1264,13 @@
         hot_bugs = []
         count = 0
         for task in bugtasks:
- if task.bug not in hot_bugs:
+ # Ensure we only represent a bug once in the list.
+ if task.bug not in [hot_task.bug for hot_task in hot_bugs]:
                 if count < 10:
- hot_bugs.append(task.bug)
+ hot_bugs.append(task)
                     count += 1
- elif count == 10:
- return hot_bugs
+ else:
+ break
         return hot_bugs

=== modified file 'lib/lp/bugs/model/bugtask.py'
--- lib/lp/bugs/model/bugtask.py 2010-01-19 22:34:00 +0000
+++ lib/lp/bugs/model/bugtask.py 2010-01-21 20:45:05 +0000
@@ -1257,7 +1257,7 @@
         "number_of_duplicates": "Bug.number_of_duplicates",
         "message_count": "Bug.message_count",
         "users_affected_count": "Bug.users_affected_count",
- "heat": "Bug.hotness",
+ "heat": "Bug.heat",
         }

     _open_resolved_upstream = """

=== modified file 'lib/lp/bugs/stories/bugs/xx-product-bugs-page.txt'
--- lib/lp/bugs/stories/bugs/xx-product-bugs-page.txt 2010-01-20 20:52:20 +0000
+++ lib/lp/bugs/stories/bugs/xx-product-bugs-page.txt 2010-01-21 17:56:06 +0000
@@ -203,8 +203,8 @@
     #21 Summary for new bug 6 New Undecided ...

-Fix released bugs are not shown. We demonstrate this by setting the bugtask
-for bug 18 to be "Fix released".
+Fix Released bugs are not shown. We demonstrate this by setting the bugtask
+for bug 18 to be "Fix Released".

     >>> from lp.bugs.interfaces.bug import BugTaskStatus, IBugSet
     >>> from lp.registry.interfaces.person import IPersonSet
@@ -215,7 +215,7 @@
     ... BugTaskStatus.FIXRELEASED, project_owner)
     >>> logout()

-And then reloading the page. The Fix released bug, bug 18, is no longer shown.
+And then reloading the page. The Fix Released bug, bug 18, is no longer shown.

     >>> anon_browser.reload()
     >>> print extract_text(

=== modified file 'lib/lp/bugs/templates/bugtarget-bugs.pt'
--- lib/lp/bugs/templates/bugtarget-bugs.pt 2010-01-20 18:16:50 +0000
+++ lib/lp/bugs/templates/bugtarget-bugs.pt 2010-01-21 17:33:54 +0000
@@ -113,23 +113,23 @@
           </tr>
         </thead>
         <tbody>
- <tr tal:repeat="bug view/hot_bugs">
+ <tr tal:repeat="bugtask view/hot_bugs">
             <td class="icon left">
               <img alt="" src="/@@/bug" />
             </td>
             <td style="text-align: right">
- #<span tal:replace="bug/default_bugtask/bug/id" />
+ #<span tal:replace="bugtask/bug/id" />
             </td>
             <td>
- <a tal:attributes="href bug/default_bugtask/fmt:url"
- tal:content="bug/default_bugtask/bug/title" />
+ <a tal:attributes="href bugtask/fmt:url"
+ tal:content="bugtask/bug/title" />
      ...

Read more...

Revision history for this message
Eleanor Berger (intellectronica) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/bugs/browser/bugtarget.py'
2--- lib/lp/bugs/browser/bugtarget.py 2010-01-07 05:41:58 +0000
3+++ lib/lp/bugs/browser/bugtarget.py 2010-01-22 16:41:25 +0000
4@@ -40,6 +40,7 @@
5 from canonical.config import config
6 from lp.bugs.browser.bugtask import BugTaskSearchListingView
7 from lp.bugs.interfaces.bug import IBug
8+from lp.bugs.interfaces.bugtask import BugTaskSearchParams
9 from canonical.launchpad.browser.feeds import (
10 BugFeedLink, BugTargetLatestBugsFeedLink, FeedsMixin,
11 PersonLatestBugsFeedLink)
12@@ -55,6 +56,7 @@
13 from canonical.launchpad.interfaces.launchpad import ILaunchpadCelebrities
14 from canonical.launchpad.interfaces.temporaryblobstorage import (
15 ITemporaryStorageManager)
16+from canonical.launchpad.searchbuilder import any
17 from canonical.launchpad.webapp import urlappend
18 from canonical.launchpad.webapp.breadcrumb import Breadcrumb
19 from canonical.launchpad.webapp.interfaces import ILaunchBag, NotFoundError
20@@ -1252,6 +1254,25 @@
21 else:
22 return 'None specified'
23
24+ @property
25+ def hot_bugs(self):
26+ """Return the 10 hotest bugs according to IBug.heat."""
27+ params = BugTaskSearchParams(
28+ orderby=['-heat', '-date_last_updated'], omit_dupes=True,
29+ user=self.user, status=any(*UNRESOLVED_BUGTASK_STATUSES))
30+ bugtasks = self.context.searchTasks(params)
31+ hot_bugs = []
32+ count = 0
33+ for task in bugtasks:
34+ # Ensure we only represent a bug once in the list.
35+ if task.bug not in [hot_task.bug for hot_task in hot_bugs]:
36+ if count < 10:
37+ hot_bugs.append(task)
38+ count += 1
39+ else:
40+ break
41+ return hot_bugs
42+
43
44 class BugTargetBugTagsView(LaunchpadView):
45 """Helper methods for rendering the bug tags portlet."""
46
47=== modified file 'lib/lp/bugs/browser/bugtask.py'
48--- lib/lp/bugs/browser/bugtask.py 2010-01-19 16:43:20 +0000
49+++ lib/lp/bugs/browser/bugtask.py 2010-01-22 16:41:25 +0000
50@@ -2726,15 +2726,6 @@
51 return IDistributionSourcePackage(self.context, None)
52
53 @property
54- def hot_bugtasks(self):
55- """Return the 10 most recently updated bugtasks for this target."""
56- params = BugTaskSearchParams(
57- orderby="-date_last_updated", omit_dupes=True, user=self.user,
58- status=any(*UNRESOLVED_BUGTASK_STATUSES))
59- search = self.context.searchTasks(params)
60- return list(search[:10])
61-
62- @property
63 def addquestion_url(self):
64 """Return the URL for the +addquestion view for the context."""
65 if IQuestionTarget.providedBy(self.context):
66
67=== modified file 'lib/lp/bugs/stories/bugs/xx-product-bugs-page.txt'
68--- lib/lp/bugs/stories/bugs/xx-product-bugs-page.txt 2010-01-18 18:27:32 +0000
69+++ lib/lp/bugs/stories/bugs/xx-product-bugs-page.txt 2010-01-22 16:41:25 +0000
70@@ -131,38 +131,68 @@
71
72 == Hot Bugs ==
73
74-A listing of the 10 'hottest' bugs (currently simply the bugs most
75-recently touched) is displayed to allow a quick overview of the project.
76+A listing of the 10 'hottest' bugs is displayed to allow a quick
77+overview of the project.
78+
79+To demonstrate this, we create 10 bugs and adjust their heat values manually.
80+
81+ >>> from zope.component import getUtility
82+ >>> from canonical.launchpad.ftests import login, logout
83+ >>> from lp.registry.interfaces.product import IProductSet
84+ >>> import transaction
85+ >>> login('foo.bar@canonical.com')
86+ >>> firefox = getUtility(IProductSet).getByName("firefox")
87+ >>> heat_values = [0, 400, 200, 600, 100, 50, 50, 50, 50, 50, 50, 50]
88+ >>> for count in range(1, 11):
89+ ... summary = 'Summary for new bug %d' % count
90+ ... bug = factory.makeBug(title=summary, product=firefox)
91+ ... bug.setHeat(heat_values[count])
92+ >>> transaction.commit()
93+ >>> logout()
94+
95 For each bug we have the number, title, status, importance and the time
96 since the last update.
97
98 >>> anon_browser.open('http://bugs.launchpad.dev/firefox')
99 >>> print extract_text(
100 ... find_tag_by_id(anon_browser.contents, 'hot-bugs'))
101- Summary Status Importance Last changed
102- #5 Firefox install... New Critical on 2006-07-14
103- #4 Reflow problems... New Medium on 2006-07-14
104- #1 Firefox does no... New Low on 2006-05-19
105-
106-
107-Fix released bugs are not shown. We demonstrate this by setting the bugtask
108-for bug 4 to be "Fix released".
109-
110- >>> from zope.component import getUtility
111+ Summary Status Importance Last changed
112+ #18 Summary for new bug 3 New Undecided ...
113+ #16 Summary for new bug 1 New Undecided ...
114+ #17 Summary for new bug 2 New Undecided ...
115+ #19 Summary for new bug 4 New Undecided ...
116+ #25 Summary for new bug 10 New Undecided ...
117+ #22 Summary for new bug 7 New Undecided ...
118+ #23 Summary for new bug 8 New Undecided ...
119+ #24 Summary for new bug 9 New Undecided ...
120+ #20 Summary for new bug 5 New Undecided ...
121+ #21 Summary for new bug 6 New Undecided ...
122+
123+
124+Fix Released bugs are not shown. We demonstrate this by setting the bugtask
125+for bug 18 to be "Fix Released".
126+
127 >>> from lp.bugs.interfaces.bug import BugTaskStatus, IBugSet
128 >>> from lp.registry.interfaces.person import IPersonSet
129 >>> login('foo.bar@canonical.com')
130- >>> bug_4 = getUtility(IBugSet).get(4)
131+ >>> bug_18 = getUtility(IBugSet).get(18)
132 >>> project_owner = getUtility(IPersonSet).getByName('name12')
133- >>> bug_4.bugtasks[0].transitionToStatus(
134+ >>> bug_18.bugtasks[0].transitionToStatus(
135 ... BugTaskStatus.FIXRELEASED, project_owner)
136 >>> logout()
137
138-And then reloading the page. The Fix released bug, bug 4, is no longer shown.
139+And then reloading the page. The Fix Released bug, bug 18, is no longer shown.
140
141 >>> anon_browser.reload()
142 >>> print extract_text(
143 ... find_tag_by_id(anon_browser.contents, 'hot-bugs'))
144- Summary Status Importance Last changed
145- #5 Firefox install... New Critical on 2006-07-14
146- #1 Firefox does no... New Low on 2006-05-19
147+ Summary Status Importance Last changed
148+ #16 Summary for new bug 1 New Undecided ...
149+ #17 Summary for new bug 2 New Undecided ...
150+ #19 Summary for new bug 4 New Undecided ...
151+ #25 Summary for new bug 10 New Undecided ...
152+ #22 Summary for new bug 7 New Undecided ...
153+ #23 Summary for new bug 8 New Undecided ...
154+ #24 Summary for new bug 9 New Undecided ...
155+ #20 Summary for new bug 5 New Undecided ...
156+ #21 Summary for new bug 6 New Undecided ...
157
158=== modified file 'lib/lp/bugs/templates/bugtarget-bugs.pt'
159--- lib/lp/bugs/templates/bugtarget-bugs.pt 2010-01-20 17:26:54 +0000
160+++ lib/lp/bugs/templates/bugtarget-bugs.pt 2010-01-22 16:41:25 +0000
161@@ -95,7 +95,7 @@
162 </ul>
163 </div>
164
165- <tal:has_hot_bugs condition="view/hot_bugtasks">
166+ <tal:has_hot_bugs condition="view/hot_bugs">
167 <div class="search-box">
168 <metal:search
169 use-macro="context/@@+bugtarget-macros-search/simple-search-form"
170@@ -123,7 +123,7 @@
171 </tr>
172 </thead>
173 <tbody>
174- <tr tal:repeat="bugtask view/hot_bugtasks">
175+ <tr tal:repeat="bugtask view/hot_bugs">
176 <td class="icon left">
177 <span tal:replace="structure bugtask/image:icon" />
178 </td>
179@@ -148,7 +148,7 @@
180 </table>
181 </tal:has_hot_bugs>
182
183- <tal:no_hot_bugs condition="not: view/hot_bugtasks">
184+ <tal:no_hot_bugs condition="not: view/hot_bugs">
185 <p id="no-bugs-filed"><strong>There are currently no bugs filed against
186 <tal:project_title replace="context/title" />.</strong></p>
187

Subscribers

People subscribed via source and target branches

to status/vote changes: