~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-12-22 04:55:30 UTC
  • mfrom: (14577.1.1 testfix)
  • Revision ID: launchpad@pqm.canonical.com-20111222045530-wki9iu6c0ysqqwkx
[r=wgrant][no-qa] Fix test_publisherconfig lpstorm import. Probably a
        silent conflict between megalint and apocalypse.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2011 Canonical Ltd.  This software is licensed under the
 
2
# GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
"""BugSummary Storm database classes."""
 
5
 
 
6
__metaclass__ = type
 
7
__all__ = [
 
8
    'BugSummary',
 
9
    'CombineBugSummaryConstraint',
 
10
    ]
 
11
 
 
12
from storm.locals import (
 
13
    And,
 
14
    Bool,
 
15
    Int,
 
16
    Reference,
 
17
    Storm,
 
18
    Unicode,
 
19
    )
 
20
from zope.interface import implements
 
21
from zope.security.proxy import removeSecurityProxy
 
22
 
 
23
from canonical.database.enumcol import EnumCol
 
24
from lp.bugs.interfaces.bugsummary import (
 
25
    IBugSummary,
 
26
    IBugSummaryDimension,
 
27
    )
 
28
from lp.bugs.interfaces.bugtask import (
 
29
    BugTaskImportance,
 
30
    BugTaskStatus,
 
31
    BugTaskStatusSearch,
 
32
    )
 
33
from lp.registry.model.distribution import Distribution
 
34
from lp.registry.model.distroseries import DistroSeries
 
35
from lp.registry.model.milestone import Milestone
 
36
from lp.registry.model.person import Person
 
37
from lp.registry.model.product import Product
 
38
from lp.registry.model.productseries import ProductSeries
 
39
from lp.registry.model.sourcepackagename import SourcePackageName
 
40
 
 
41
 
 
42
class BugSummary(Storm):
 
43
    """BugSummary Storm database class."""
 
44
 
 
45
    implements(IBugSummary)
 
46
 
 
47
    __storm_table__ = 'combinedbugsummary'
 
48
 
 
49
    id = Int(primary=True)
 
50
    count = Int()
 
51
 
 
52
    product_id = Int(name='product')
 
53
    product = Reference(product_id, Product.id)
 
54
 
 
55
    productseries_id = Int(name='productseries')
 
56
    productseries = Reference(productseries_id, ProductSeries.id)
 
57
 
 
58
    distribution_id = Int(name='distribution')
 
59
    distribution = Reference(distribution_id, Distribution.id)
 
60
 
 
61
    distroseries_id = Int(name='distroseries')
 
62
    distroseries = Reference(distroseries_id, DistroSeries.id)
 
63
 
 
64
    sourcepackagename_id = Int(name='sourcepackagename')
 
65
    sourcepackagename = Reference(sourcepackagename_id, SourcePackageName.id)
 
66
 
 
67
    milestone_id = Int(name='milestone')
 
68
    milestone = Reference(milestone_id, Milestone.id)
 
69
 
 
70
    status = EnumCol(
 
71
        dbName='status', schema=(BugTaskStatus, BugTaskStatusSearch))
 
72
 
 
73
    importance = EnumCol(dbName='importance', schema=BugTaskImportance)
 
74
 
 
75
    tag = Unicode()
 
76
 
 
77
    viewed_by_id = Int(name='viewed_by')
 
78
    viewed_by = Reference(viewed_by_id, Person.id)
 
79
 
 
80
    has_patch = Bool()
 
81
    fixed_upstream = Bool()
 
82
 
 
83
 
 
84
class CombineBugSummaryConstraint:
 
85
    """A class to combine two separate bug summary constraints.
 
86
 
 
87
    This is useful for querying on multiple related dimensions (e.g. milestone
 
88
    + sourcepackage) - and essential when a dimension is not unique to a
 
89
    context.
 
90
    """
 
91
 
 
92
    implements(IBugSummaryDimension)
 
93
 
 
94
    def __init__(self, *dimensions):
 
95
        self.dimensions = map(
 
96
            lambda x:
 
97
            removeSecurityProxy(x.getBugSummaryContextWhereClause()),
 
98
            dimensions)
 
99
 
 
100
    def getBugSummaryContextWhereClause(self):
 
101
        """See `IBugSummaryDimension`."""
 
102
        return And(*self.dimensions)