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

Proposed by Eleanor Berger
Status: Merged
Merged at revision: not available
Proposed branch: lp://staging/~intellectronica/launchpad/use-max-heat
Merge into: lp://staging/launchpad/db-devel
Prerequisite: lp://staging/~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://staging/~intellectronica/launchpad/use-max-heat
Reviewer Review Type Date Requested Status
Leonard Richardson (community) Approve
Canonical Launchpad Engineering code Pending
Review via email: mp+20054@code.staging.launchpad.net
To post a comment you must log in.
Revision history for this message
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).

Revision history for this message
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
=== modified file 'lib/lp/bugs/browser/bug.py'
--- lib/lp/bugs/browser/bug.py 2010-02-02 17:26:53 +0000
+++ lib/lp/bugs/browser/bug.py 2010-02-24 13:14:23 +0000
@@ -10,7 +10,6 @@
10 'BugContextMenu',10 'BugContextMenu',
11 'BugEditView',11 'BugEditView',
12 'BugFacets',12 'BugFacets',
13 'BugHeatView',
14 'BugMarkAsAffectingUserView',13 'BugMarkAsAffectingUserView',
15 'BugMarkAsDuplicateView',14 'BugMarkAsDuplicateView',
16 'BugNavigation',15 'BugNavigation',
@@ -23,13 +22,11 @@
23 'BugWithoutContextView',22 'BugWithoutContextView',
24 'DeprecatedAssignedBugsView',23 'DeprecatedAssignedBugsView',
25 'MaloneView',24 'MaloneView',
26 'MAX_HEAT',
27 ]25 ]
2826
29from datetime import datetime, timedelta27from datetime import datetime, timedelta
30from email.MIMEMultipart import MIMEMultipart28from email.MIMEMultipart import MIMEMultipart
31from email.MIMEText import MIMEText29from email.MIMEText import MIMEText
32from math import floor
33import re30import re
3431
35import pytz32import pytz
@@ -77,10 +74,6 @@
77from canonical.widgets.bug import BugTagsWidget74from canonical.widgets.bug import BugTagsWidget
78from canonical.widgets.project import ProjectScopeWidget75from canonical.widgets.project import ProjectScopeWidget
7976
80# Constant for the maximum bug heat we'll use for converting
81# IBug.heat to ratio. In the future this should come from the DB.
82# The value must be a float
83MAX_HEAT = 5000.0
8477
85class BugNavigation(Navigation):78class BugNavigation(Navigation):
86 """Navigation for the `IBug`."""79 """Navigation for the `IBug`."""
@@ -969,18 +962,3 @@
969 return html.encode('utf-8')962 return html.encode('utf-8')
970 return renderer963 return renderer
971964
972
973class BugHeatView(LaunchpadView):
974 """View for rendering the graphical (HTML) representation of bug heat."""
975
976 def __call__(self):
977 """Render the bug heat representation."""
978 heat_ratio = floor((self.context.heat / MAX_HEAT) * 4)
979 html = '<span>'
980 for flame in range(1, 5):
981 if flame <= heat_ratio:
982 html += '<img src="/@@/flame-icon" />'
983 else:
984 html += '<img src="/@@/flame-bw-icon" />'
985 html += '</span>'
986 return html
987965
=== modified file 'lib/lp/bugs/browser/bugtask.py'
--- lib/lp/bugs/browser/bugtask.py 2010-02-20 13:16:38 +0000
+++ lib/lp/bugs/browser/bugtask.py 2010-02-24 13:14:23 +0000
@@ -33,6 +33,7 @@
33 'BugTaskTextView',33 'BugTaskTextView',
34 'BugTaskView',34 'BugTaskView',
35 'BugTasksAndNominationsView',35 'BugTasksAndNominationsView',
36 'bugtask_heat_html',
36 'BugsBugTaskSearchListingView',37 'BugsBugTaskSearchListingView',
37 'NominationsReviewTableBatchNavigatorView',38 'NominationsReviewTableBatchNavigatorView',
38 'TextualBugTaskSearchListingView',39 'TextualBugTaskSearchListingView',
@@ -49,6 +50,7 @@
49from simplejson import dumps50from simplejson import dumps
50import urllib51import urllib
51from operator import attrgetter, itemgetter52from operator import attrgetter, itemgetter
53from math import floor
5254
53from zope import component55from zope import component
54from zope.app.form import CustomWidgetFactory56from zope.app.form import CustomWidgetFactory
@@ -1079,10 +1081,24 @@
1079 @property1081 @property
1080 def bug_heat_html(self):1082 def bug_heat_html(self):
1081 """HTML representation of the bug heat."""1083 """HTML representation of the bug heat."""
1082 view = getMultiAdapter(1084 return bugtask_heat_html(self.context)
1083 (self.context.bug, self.request),1085
1084 name='+bug-heat')1086
1085 return view()1087def bugtask_heat_html(bugtask):
1088 """Render the HTML representing bug heat for a given bugask."""
1089 max_heat = bugtask.target.max_heat
1090 if max_heat == 0:
1091 max_heat = 5000
1092 heat_ratio = floor(
1093 (bugtask.bug.heat / float(max_heat)) * 4)
1094 html = '<span>'
1095 for flame in range(1, 5):
1096 if flame <= heat_ratio:
1097 html += '<img src="/@@/flame-icon" />'
1098 else:
1099 html += '<img src="/@@/flame-bw-icon" />'
1100 html += '</span>'
1101 return html
10861102
10871103
1088class BugTaskPortletView:1104class BugTaskPortletView:
10891105
=== modified file 'lib/lp/bugs/browser/configure.zcml'
--- lib/lp/bugs/browser/configure.zcml 2010-02-20 13:16:38 +0000
+++ lib/lp/bugs/browser/configure.zcml 2010-02-24 13:14:23 +0000
@@ -1044,11 +1044,6 @@
1044 name="+bug-portlet-subscribers-ids"1044 name="+bug-portlet-subscribers-ids"
1045 class="lp.bugs.browser.bugsubscription.BugPortletSubcribersIds"1045 class="lp.bugs.browser.bugsubscription.BugPortletSubcribersIds"
1046 permission="zope.Public"/>1046 permission="zope.Public"/>
1047 <browser:page
1048 for="lp.bugs.interfaces.bug.IBug"
1049 class="lp.bugs.browser.bug.BugHeatView"
1050 permission="zope.Public"
1051 name="+bug-heat"/>
1052 <browser:navigation1047 <browser:navigation
1053 module="lp.bugs.browser.bug"1048 module="lp.bugs.browser.bug"
1054 classes="1049 classes="
10551050
=== modified file 'lib/lp/bugs/browser/tests/bug-heat-view.txt'
--- lib/lp/bugs/browser/tests/bug-heat-view.txt 2010-01-18 22:11:00 +0000
+++ lib/lp/bugs/browser/tests/bug-heat-view.txt 2010-02-24 13:14:23 +0000
@@ -4,12 +4,13 @@
4coloured is dependent on the value of the heat field. The view BugHeatView4coloured is dependent on the value of the heat field. The view BugHeatView
5is used to render the flames.5is used to render the flames.
66
7 >>> from lp.bugs.browser.bug import MAX_HEAT7 >>> MAX_HEAT = 5000.0
8 >>> from canonical.launchpad.ftests import login, logout8 >>> from canonical.launchpad.ftests import login, logout
9 >>> from canonical.launchpad.webapp import canonical_url
10 >>> from zope.security.proxy import removeSecurityProxy9 >>> from zope.security.proxy import removeSecurityProxy
11 >>> from BeautifulSoup import BeautifulSoup10 >>> from BeautifulSoup import BeautifulSoup
12 >>> def print_flames(html):11 >>> from lp.bugs.browser.bugtask import bugtask_heat_html
12 >>> def print_flames(bugtask):
13 ... html = bugtask_heat_html(bugtask)
13 ... soup = BeautifulSoup(html)14 ... soup = BeautifulSoup(html)
14 ... for img in soup.span.contents:15 ... for img in soup.span.contents:
15 ... print img['src']16 ... print img['src']
@@ -20,9 +21,9 @@
20a heat of half the maximum will result in a display of two coloured flames21a heat of half the maximum will result in a display of two coloured flames
21and two black-and-white flames.22and two black-and-white flames.
2223
24 >>> removeSecurityProxy(bug.default_bugtask.target).max_heat = MAX_HEAT
23 >>> removeSecurityProxy(bug).heat = MAX_HEAT / 225 >>> removeSecurityProxy(bug).heat = MAX_HEAT / 2
24 >>> bug_heat_view = create_initialized_view(bug, name='+bug-heat')26 >>> print_flames(bug.default_bugtask)
25 >>> print_flames(bug_heat_view())
26 /@@/flame-icon27 /@@/flame-icon
27 /@@/flame-icon28 /@@/flame-icon
28 /@@/flame-bw-icon29 /@@/flame-bw-icon
@@ -31,8 +32,7 @@
31A bug with a maximum heat will display all four flames coloured.32A bug with a maximum heat will display all four flames coloured.
3233
33 >>> removeSecurityProxy(bug).heat = MAX_HEAT34 >>> removeSecurityProxy(bug).heat = MAX_HEAT
34 >>> bug_heat_view = create_initialized_view(bug, name='+bug-heat')35 >>> print_flames(bug.default_bugtask)
35 >>> print_flames(bug_heat_view())
36 /@@/flame-icon36 /@@/flame-icon
37 /@@/flame-icon37 /@@/flame-icon
38 /@@/flame-icon38 /@@/flame-icon
@@ -41,8 +41,7 @@
41A heat of less than a quarter of the maximum will display no coloured flames.41A heat of less than a quarter of the maximum will display no coloured flames.
4242
43 >>> removeSecurityProxy(bug).heat = 0.1 * MAX_HEAT43 >>> removeSecurityProxy(bug).heat = 0.1 * MAX_HEAT
44 >>> bug_heat_view = create_initialized_view(bug, name='+bug-heat')44 >>> print_flames(bug.default_bugtask)
45 >>> print_flames(bug_heat_view())
46 /@@/flame-bw-icon45 /@@/flame-bw-icon
47 /@@/flame-bw-icon46 /@@/flame-bw-icon
48 /@@/flame-bw-icon47 /@@/flame-bw-icon

Subscribers

People subscribed via source and target branches

to status/vote changes: