~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/bugs/model/bugtarget.py

  • Committer: Brad Crittenden
  • Date: 2011-11-16 19:34:31 UTC
  • mto: This revision was merged to the branch mainline in revision 14304.
  • Revision ID: bac@canonical.com-20111116193431-eek3uws5ji3liw71
RevertĀ 14301

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2010-2011 Canonical Ltd.  This software is licensed under the
 
1
# Copyright 2010 Canonical Ltd.  This software is licensed under the
2
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
3
 
4
4
# pylint: disable-msg=E0611,W0212
17
17
from storm.locals import (
18
18
    Int,
19
19
    Reference,
20
 
    SQL,
21
20
    Storm,
22
21
    Unicode,
23
22
    )
24
23
from zope.component import getUtility
25
24
from zope.interface import implements
26
25
 
27
 
from canonical.database.sqlbase import sqlvalues
 
26
from canonical.database.sqlbase import (
 
27
    cursor,
 
28
    sqlvalues,
 
29
    )
28
30
from canonical.launchpad.interfaces.lpstorm import (
29
31
    IMasterObject,
30
32
    IMasterStore,
50
52
    UNRESOLVED_BUGTASK_STATUSES,
51
53
    )
52
54
from lp.bugs.interfaces.bugtaskfilter import simple_weight_calculator
53
 
from lp.bugs.model.bugtask import BugTaskSet
 
55
from lp.bugs.model.bugtask import (
 
56
    BugTaskSet,
 
57
    )
54
58
from lp.registry.interfaces.distribution import IDistribution
55
59
from lp.registry.interfaces.distributionsourcepackage import (
56
60
    IDistributionSourcePackage,
296
300
        else:
297
301
            raise NotImplementedError
298
302
 
299
 
        # Use Storm's lazy expression values
300
 
        # <https://storm.canonical.com/Tutorial#Expression_values>
301
 
        expr = SQL(
302
 
            "(SELECT COALESCE(MAX(heat), 0) FROM (%s) AS geoff)" % (
303
 
                " UNION ALL ".join("(%s)" % query for query in sql)))
304
 
        self.setMaxBugHeat(expr)
 
303
        results = [0]
 
304
        for query in sql:
 
305
            cur = cursor()
 
306
            cur.execute(query)
 
307
            record = cur.fetchone()
 
308
            if record is not None:
 
309
                results.append(record[0])
 
310
            cur.close()
 
311
        self.setMaxBugHeat(max(results))
305
312
 
306
313
        # If the product is part of a project group we calculate the maximum
307
314
        # heat for the project group too.