Merge lp:~cjwatson/launchpad/bugtask-distroseries-sort-by-version into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18351
Proposed branch: lp:~cjwatson/launchpad/bugtask-distroseries-sort-by-version
Merge into: lp:launchpad
Diff against target: 103 lines (+26/-14)
2 files modified
lib/lp/bugs/browser/bugtask.py (+17/-10)
lib/lp/bugs/browser/tests/test_bugtask.py (+9/-4)
To merge this branch: bzr merge lp:~cjwatson/launchpad/bugtask-distroseries-sort-by-version
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+322467@code.launchpad.net

Commit message

Sort bug tasks related to distribution series by series version rather than series name.

Description of the change

I steered clear of doing this for ProductSeries-related tasks mostly out of conservatism: I wasn't sure if we can reliably expect versions to be sensibly comparable there.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/bugs/browser/bugtask.py'
2--- lib/lp/bugs/browser/bugtask.py 2016-07-29 16:13:36 +0000
3+++ lib/lp/bugs/browser/bugtask.py 2017-04-12 15:45:41 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
6+# Copyright 2009-2017 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 """IBugTask-related browser views."""
10@@ -95,6 +95,7 @@
11 from lp.app.enums import PROPRIETARY_INFORMATION_TYPES
12 from lp.app.errors import NotFoundError
13 from lp.app.interfaces.launchpad import ILaunchpadCelebrities
14+from lp.archivepublisher.debversion import Version
15 from lp.bugs.browser.bug import (
16 BugContextMenu,
17 BugTextView,
18@@ -1655,28 +1656,34 @@
19 Designed to make sense when bugtargetdisplayname is shown.
20 """
21 if IDistribution.providedBy(bugtask.target):
22- return (
23- None, bugtask.target.displayname, None, None, None)
24+ key = (None, bugtask.target.displayname, None, None, None)
25 elif IDistroSeries.providedBy(bugtask.target):
26- return (
27+ key = (
28 None, bugtask.target.distribution.displayname,
29 bugtask.target.name, None, None)
30 elif IDistributionSourcePackage.providedBy(bugtask.target):
31- return (
32+ key = (
33 bugtask.target.sourcepackagename.name,
34 bugtask.target.distribution.displayname, None, None, None)
35 elif ISourcePackage.providedBy(bugtask.target):
36- return (
37+ key = (
38 bugtask.target.sourcepackagename.name,
39 bugtask.target.distribution.displayname,
40- bugtask.target.distroseries.name, None, None)
41+ Version(bugtask.target.distroseries.version), None, None)
42 elif IProduct.providedBy(bugtask.target):
43- return (None, None, None, bugtask.target.displayname, None)
44+ key = (None, None, None, bugtask.target.displayname, None)
45 elif IProductSeries.providedBy(bugtask.target):
46- return (
47+ key = (
48 None, None, None, bugtask.target.product.displayname,
49 bugtask.target.name)
50- raise AssertionError("No sort key for %r" % bugtask.target)
51+ else:
52+ raise AssertionError("No sort key for %r" % bugtask.target)
53+
54+ # Map elements of the sort key into a form where None is guaranteed to
55+ # compare before non-None. Values of arbitrary types are not guaranteed
56+ # to compare greater than None in Python 2, and in Python 3 even asking
57+ # the question results in a TypeError.
58+ return [(0, None) if value is None else (1, value) for value in key]
59
60
61 class BugTasksNominationsView(LaunchpadView):
62
63=== modified file 'lib/lp/bugs/browser/tests/test_bugtask.py'
64--- lib/lp/bugs/browser/tests/test_bugtask.py 2016-07-29 16:41:58 +0000
65+++ lib/lp/bugs/browser/tests/test_bugtask.py 2017-04-12 15:45:41 +0000
66@@ -1,4 +1,4 @@
67-# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
68+# Copyright 2009-2017 Canonical Ltd. This software is licensed under the
69 # GNU Affero General Public License version 3 (see the file LICENSE).
70
71 __metaclass__ = type
72@@ -797,7 +797,7 @@
73 def test_bugtask_sorting(self):
74 # Product tasks come first, sorted by product then series.
75 # Distro tasks follow, sorted by package, distribution, then
76- # series.
77+ # series (by version in the case of distribution series).
78 foo = self.factory.makeProduct(displayname='Foo')
79 self.factory.makeProductSeries(product=foo, name='2.0')
80 self.factory.makeProductSeries(product=foo, name='1.0')
81@@ -805,8 +805,12 @@
82 self.factory.makeProductSeries(product=bar, name='0.0')
83
84 barix = self.factory.makeDistribution(displayname='Barix')
85- self.factory.makeDistroSeries(distribution=barix, name='beta')
86- self.factory.makeDistroSeries(distribution=barix, name='alpha')
87+ self.factory.makeDistroSeries(
88+ distribution=barix, name='aaa-release', version='1.0')
89+ self.factory.makeDistroSeries(
90+ distribution=barix, name='beta', version='0.10')
91+ self.factory.makeDistroSeries(
92+ distribution=barix, name='alpha', version='0.9')
93 fooix = self.factory.makeDistribution(displayname='Fooix')
94 self.factory.makeDistroSeries(distribution=fooix, name='beta')
95
96@@ -818,6 +822,7 @@
97 foo, foo.getSeries('1.0'), foo.getSeries('2.0'),
98 barix.getSourcePackage(bar_spn),
99 barix.getSeries('beta').getSourcePackage(bar_spn),
100+ barix.getSeries('aaa-release').getSourcePackage(bar_spn),
101 fooix.getSourcePackage(bar_spn),
102 fooix.getSeries('beta').getSourcePackage(bar_spn),
103 barix.getSourcePackage(foo_spn),