Merge lp:~intellectronica/launchpad/use-max-heat into lp:launchpad/db-devel

Proposed by Eleanor Berger on 2010-02-24
Status: Merged
Merged at revision: not available
Proposed branch: lp:~intellectronica/launchpad/use-max-heat
Merge into: lp:launchpad/db-devel
Prerequisite: lp:~deryck/launchpad/max-heat-by-target-511382
Diff against target: 173 lines (+28/-40)
4 files modified
lib/lp/bugs/browser/bug.py (+0/-22)
lib/lp/bugs/browser/bugtask.py (+20/-4)
lib/lp/bugs/browser/configure.zcml (+0/-5)
lib/lp/bugs/browser/tests/bug-heat-view.txt (+8/-9)
To merge this branch: bzr merge lp:~intellectronica/launchpad/use-max-heat
Reviewer Review Type Date Requested Status
Leonard Richardson (community) Approve on 2010-02-24
Canonical Launchpad Engineering code 2010-02-24 Pending
Review via email: mp+20054@code.launchpad.net
To post a comment you must log in.
Eleanor Berger (intellectronica) wrote :

This branch changes the way bug heat is rendered. Instead of using a constant maximum heat, we use the max_heat value for the relevant bug target. As a result of this change, using a bug view doesn't make sense any more, since we now have to know about the target (which is only available from the bugtask).

Leonard Richardson (leonardr) wrote :

<leonardr> intellectronica: it seems like having a MAX_HEAT in bugtask.py would still be useful. you still use it in two different files
<intellectronica> leonardr: i use it in a test. i use the value as a default, but it will be gone with a following branch which will make sure we have max_heat populated
<leonardr> intellectronica: oh, one other question. why can't the bugheatview be a view on the bugtask?
<leonardr> (assuming views are desirable in general)
<intellectronica> leonardr: it's just a case of yagni. it wasn't such a brilliant idea to use a view to begin with.
<intellectronica> all we ever did with the view is initialize manually and call it

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/bug.py'
2--- lib/lp/bugs/browser/bug.py 2010-02-02 17:26:53 +0000
3+++ lib/lp/bugs/browser/bug.py 2010-02-24 13:14:23 +0000
4@@ -10,7 +10,6 @@
5 'BugContextMenu',
6 'BugEditView',
7 'BugFacets',
8- 'BugHeatView',
9 'BugMarkAsAffectingUserView',
10 'BugMarkAsDuplicateView',
11 'BugNavigation',
12@@ -23,13 +22,11 @@
13 'BugWithoutContextView',
14 'DeprecatedAssignedBugsView',
15 'MaloneView',
16- 'MAX_HEAT',
17 ]
18
19 from datetime import datetime, timedelta
20 from email.MIMEMultipart import MIMEMultipart
21 from email.MIMEText import MIMEText
22-from math import floor
23 import re
24
25 import pytz
26@@ -77,10 +74,6 @@
27 from canonical.widgets.bug import BugTagsWidget
28 from canonical.widgets.project import ProjectScopeWidget
29
30-# Constant for the maximum bug heat we'll use for converting
31-# IBug.heat to ratio. In the future this should come from the DB.
32-# The value must be a float
33-MAX_HEAT = 5000.0
34
35 class BugNavigation(Navigation):
36 """Navigation for the `IBug`."""
37@@ -969,18 +962,3 @@
38 return html.encode('utf-8')
39 return renderer
40
41-
42-class BugHeatView(LaunchpadView):
43- """View for rendering the graphical (HTML) representation of bug heat."""
44-
45- def __call__(self):
46- """Render the bug heat representation."""
47- heat_ratio = floor((self.context.heat / MAX_HEAT) * 4)
48- html = '<span>'
49- for flame in range(1, 5):
50- if flame <= heat_ratio:
51- html += '<img src="/@@/flame-icon" />'
52- else:
53- html += '<img src="/@@/flame-bw-icon" />'
54- html += '</span>'
55- return html
56
57=== modified file 'lib/lp/bugs/browser/bugtask.py'
58--- lib/lp/bugs/browser/bugtask.py 2010-02-20 13:16:38 +0000
59+++ lib/lp/bugs/browser/bugtask.py 2010-02-24 13:14:23 +0000
60@@ -33,6 +33,7 @@
61 'BugTaskTextView',
62 'BugTaskView',
63 'BugTasksAndNominationsView',
64+ 'bugtask_heat_html',
65 'BugsBugTaskSearchListingView',
66 'NominationsReviewTableBatchNavigatorView',
67 'TextualBugTaskSearchListingView',
68@@ -49,6 +50,7 @@
69 from simplejson import dumps
70 import urllib
71 from operator import attrgetter, itemgetter
72+from math import floor
73
74 from zope import component
75 from zope.app.form import CustomWidgetFactory
76@@ -1079,10 +1081,24 @@
77 @property
78 def bug_heat_html(self):
79 """HTML representation of the bug heat."""
80- view = getMultiAdapter(
81- (self.context.bug, self.request),
82- name='+bug-heat')
83- return view()
84+ return bugtask_heat_html(self.context)
85+
86+
87+def bugtask_heat_html(bugtask):
88+ """Render the HTML representing bug heat for a given bugask."""
89+ max_heat = bugtask.target.max_heat
90+ if max_heat == 0:
91+ max_heat = 5000
92+ heat_ratio = floor(
93+ (bugtask.bug.heat / float(max_heat)) * 4)
94+ html = '<span>'
95+ for flame in range(1, 5):
96+ if flame <= heat_ratio:
97+ html += '<img src="/@@/flame-icon" />'
98+ else:
99+ html += '<img src="/@@/flame-bw-icon" />'
100+ html += '</span>'
101+ return html
102
103
104 class BugTaskPortletView:
105
106=== modified file 'lib/lp/bugs/browser/configure.zcml'
107--- lib/lp/bugs/browser/configure.zcml 2010-02-20 13:16:38 +0000
108+++ lib/lp/bugs/browser/configure.zcml 2010-02-24 13:14:23 +0000
109@@ -1044,11 +1044,6 @@
110 name="+bug-portlet-subscribers-ids"
111 class="lp.bugs.browser.bugsubscription.BugPortletSubcribersIds"
112 permission="zope.Public"/>
113- <browser:page
114- for="lp.bugs.interfaces.bug.IBug"
115- class="lp.bugs.browser.bug.BugHeatView"
116- permission="zope.Public"
117- name="+bug-heat"/>
118 <browser:navigation
119 module="lp.bugs.browser.bug"
120 classes="
121
122=== modified file 'lib/lp/bugs/browser/tests/bug-heat-view.txt'
123--- lib/lp/bugs/browser/tests/bug-heat-view.txt 2010-01-18 22:11:00 +0000
124+++ lib/lp/bugs/browser/tests/bug-heat-view.txt 2010-02-24 13:14:23 +0000
125@@ -4,12 +4,13 @@
126 coloured is dependent on the value of the heat field. The view BugHeatView
127 is used to render the flames.
128
129- >>> from lp.bugs.browser.bug import MAX_HEAT
130+ >>> MAX_HEAT = 5000.0
131 >>> from canonical.launchpad.ftests import login, logout
132- >>> from canonical.launchpad.webapp import canonical_url
133 >>> from zope.security.proxy import removeSecurityProxy
134 >>> from BeautifulSoup import BeautifulSoup
135- >>> def print_flames(html):
136+ >>> from lp.bugs.browser.bugtask import bugtask_heat_html
137+ >>> def print_flames(bugtask):
138+ ... html = bugtask_heat_html(bugtask)
139 ... soup = BeautifulSoup(html)
140 ... for img in soup.span.contents:
141 ... print img['src']
142@@ -20,9 +21,9 @@
143 a heat of half the maximum will result in a display of two coloured flames
144 and two black-and-white flames.
145
146+ >>> removeSecurityProxy(bug.default_bugtask.target).max_heat = MAX_HEAT
147 >>> removeSecurityProxy(bug).heat = MAX_HEAT / 2
148- >>> bug_heat_view = create_initialized_view(bug, name='+bug-heat')
149- >>> print_flames(bug_heat_view())
150+ >>> print_flames(bug.default_bugtask)
151 /@@/flame-icon
152 /@@/flame-icon
153 /@@/flame-bw-icon
154@@ -31,8 +32,7 @@
155 A bug with a maximum heat will display all four flames coloured.
156
157 >>> removeSecurityProxy(bug).heat = MAX_HEAT
158- >>> bug_heat_view = create_initialized_view(bug, name='+bug-heat')
159- >>> print_flames(bug_heat_view())
160+ >>> print_flames(bug.default_bugtask)
161 /@@/flame-icon
162 /@@/flame-icon
163 /@@/flame-icon
164@@ -41,8 +41,7 @@
165 A heat of less than a quarter of the maximum will display no coloured flames.
166
167 >>> removeSecurityProxy(bug).heat = 0.1 * MAX_HEAT
168- >>> bug_heat_view = create_initialized_view(bug, name='+bug-heat')
169- >>> print_flames(bug_heat_view())
170+ >>> print_flames(bug.default_bugtask)
171 /@@/flame-bw-icon
172 /@@/flame-bw-icon
173 /@@/flame-bw-icon

Subscribers

People subscribed via source and target branches

to status/vote changes: