~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/registry/vocabularies.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-06-24 13:40:28 UTC
  • mfrom: (13261.5.3 dsp-vocab)
  • Revision ID: launchpad@pqm.canonical.com-20110624134028-p6bhs72xycu5uuoi
[r=jtv][bug=42298][incr] Add DistributionSourcePackageVocabulary.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
    'CommercialProjectsVocabulary',
31
31
    'DistributionOrProductOrProjectGroupVocabulary',
32
32
    'DistributionOrProductVocabulary',
 
33
    'DistributionSourcePackageVocabulary',
33
34
    'DistributionVocabulary',
34
35
    'DistroSeriesDerivationVocabulary',
35
36
    'DistroSeriesVocabulary',
167
168
from lp.registry.interfaces.projectgroup import IProjectGroup
168
169
from lp.registry.interfaces.sourcepackage import ISourcePackage
169
170
from lp.registry.model.distribution import Distribution
 
171
from lp.registry.model.distributionsourcepackage import (
 
172
    DistributionSourcePackage,
 
173
    )
170
174
from lp.registry.model.distroseries import DistroSeries
171
175
from lp.registry.model.distroseriesparent import DistroSeriesParent
172
176
from lp.registry.model.featuredproject import FeaturedProject
190
194
    cachedproperty,
191
195
    get_property_cache,
192
196
    )
 
197
from lp.soyuz.enums import PackagePublishingStatus
 
198
from lp.soyuz.model.binarypackagebuild import BinaryPackageBuild
 
199
from lp.soyuz.model.binarypackagename import BinaryPackageName
 
200
from lp.soyuz.model.binarypackagerelease import BinaryPackageRelease
193
201
from lp.soyuz.model.distroarchseries import DistroArchSeries
 
202
from lp.soyuz.model.publishing import (
 
203
    BinaryPackagePublishingHistory,
 
204
    SourcePackagePublishingHistory,
 
205
    )
 
206
from lp.soyuz.model.sourcepackagerelease import SourcePackageRelease
194
207
 
195
208
 
196
209
class BasePersonVocabulary:
1949
1962
        # package names are always lowercase.
1950
1963
        return super(SourcePackageNameVocabulary, self).getTermByToken(
1951
1964
            token.lower())
 
1965
        
 
1966
 
 
1967
class DistributionSourcePackageVocabulary:
 
1968
 
 
1969
    implements(IHugeVocabulary)
 
1970
    displayname = 'Select a package'
 
1971
    step_title = 'Search'
 
1972
 
 
1973
    def __init__(self, context=None):
 
1974
        self.context = context
 
1975
 
 
1976
    def __contains__(self, obj):
 
1977
        pass
 
1978
 
 
1979
    def __iter__(self):
 
1980
        pass
 
1981
 
 
1982
    def __len__(self):
 
1983
        pass
 
1984
 
 
1985
    def toTerm(self, dsp):
 
1986
        """See `IVocabulary`."""
 
1987
        # SimpleTerm(value, token=None, title=None)
 
1988
        if dsp.publishing_history:
 
1989
            binaries = dsp.publishing_history[0].getBuiltBinaries()
 
1990
            summary = ', '.join(
 
1991
                [binary.binary_package_name for binary in binaries])
 
1992
        else:
 
1993
            summary = "Not yet built."
 
1994
        token = '%s-%s' % (dsp.distribution.name, dsp.name)
 
1995
        return SimpleTerm(summary, token, dsp.name)
 
1996
 
 
1997
    def getTerm(self, dsp):
 
1998
        """See `IBaseVocabulary`."""
 
1999
        return self.toTerm(dsp)
 
2000
 
 
2001
    def getTermByToken(self, token):
 
2002
        """See `IVocabularyTokenized`."""
 
2003
        pass
 
2004
 
 
2005
    def searchForTerms(self, query=None):
 
2006
        """See `IHugeVocabulary`."""
 
2007
        distribution = self.context
 
2008
        if query is None:
 
2009
            return
 
2010
        search_term = unicode(query)
 
2011
        store = IStore(SourcePackagePublishingHistory)
 
2012
        spns = store.using(
 
2013
            SourcePackagePublishingHistory,
 
2014
            LeftJoin(
 
2015
                SourcePackageRelease,
 
2016
                SourcePackagePublishingHistory.sourcepackagereleaseID ==
 
2017
                    SourcePackageRelease.id),
 
2018
            LeftJoin(
 
2019
                SourcePackageName,
 
2020
                SourcePackageRelease.sourcepackagenameID ==
 
2021
                    SourcePackageName.id),
 
2022
            LeftJoin(
 
2023
                DistroSeries,
 
2024
                SourcePackagePublishingHistory.distroseriesID ==
 
2025
                    DistroSeries.id),
 
2026
            LeftJoin(
 
2027
                BinaryPackageBuild,
 
2028
                BinaryPackageBuild.source_package_release_id ==
 
2029
                    SourcePackageRelease.id),
 
2030
            LeftJoin(
 
2031
                BinaryPackageRelease,
 
2032
                BinaryPackageRelease.buildID == BinaryPackageBuild.id),
 
2033
            LeftJoin(
 
2034
                BinaryPackageName,
 
2035
                BinaryPackageRelease.binarypackagenameID ==
 
2036
                    BinaryPackageName.id
 
2037
            )).find(
 
2038
                SourcePackageName,
 
2039
                DistroSeries.distributionID == distribution.id,
 
2040
                SourcePackagePublishingHistory.status.is_in((
 
2041
                    PackagePublishingStatus.PENDING,
 
2042
                    PackagePublishingStatus.PUBLISHED)),
 
2043
                SourcePackagePublishingHistory.archive ==
 
2044
                    distribution.main_archive,
 
2045
                Or(
 
2046
                    SourcePackageName.name.contains_string(search_term),
 
2047
                    BinaryPackageName.name.contains_string(
 
2048
                        search_term))).config(distinct=True)
 
2049
        return [
 
2050
            self.toTerm(distribution.getSourcePackage(spn)) for spn in spns]