~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-08-24 01:40:35 UTC
  • mfrom: (13651.1.17 dsp-vocab-is-a-pain)
  • Revision ID: launchpad@pqm.canonical.com-20110824014035-7s3vwja6oa0mvpuz
[r=sinzui][bug=820005][incr] Updates dsp vocab to use the dsp in db
        in the search query.

Show diffs side-by-side

added added

removed removed

Lines of Context:
131
131
    SQLObjectVocabularyBase,
132
132
    VocabularyFilter,
133
133
    )
 
134
from canonical.lazr.utils import safe_hasattr
134
135
from lp.app.browser.tales import DateTimeFormatterAPI
135
136
from lp.app.interfaces.launchpad import ILaunchpadCelebrities
136
137
from lp.blueprints.interfaces.specification import ISpecification
173
174
from lp.registry.interfaces.productseries import IProductSeries
174
175
from lp.registry.interfaces.projectgroup import IProjectGroup
175
176
from lp.registry.interfaces.sourcepackage import ISourcePackage
 
177
from lp.registry.interfaces.sourcepackagename import ISourcePackageName
176
178
from lp.registry.model.distribution import Distribution
 
179
from lp.registry.model.distributionsourcepackage import (
 
180
    DistributionSourcePackageInDatabase,
 
181
    )
177
182
from lp.registry.model.distroseries import DistroSeries
178
183
from lp.registry.model.distroseriesdifference import DistroSeriesDifference
179
184
from lp.registry.model.distroseriesparent import DistroSeriesParent
2231
2236
        if IDistributionSourcePackage.providedBy(spn_or_dsp):
2232
2237
            dsp = spn_or_dsp
2233
2238
            distribution = spn_or_dsp.distribution
 
2239
        elif (not ISourcePackageName.providedBy(spn_or_dsp) and
 
2240
            safe_hasattr(spn_or_dsp, 'distribution')
 
2241
            and safe_hasattr(spn_or_dsp, 'sourcepackagename')):
 
2242
            # We use the hasattr checks rather than adaption because the
 
2243
            # DistributionSourcePackageInDatabase object is a little bit
 
2244
            # broken, and does not provide any interface.
 
2245
            distribution = spn_or_dsp.distribution
 
2246
            dsp = distribution.getSourcePackage(spn_or_dsp.sourcepackagename)
2234
2247
        else:
2235
2248
            distribution = distribution or self.distribution
2236
2249
            if distribution is not None and spn_or_dsp is not None:
2237
2250
                dsp = distribution.getSourcePackage(spn_or_dsp)
2238
2251
        try:
2239
2252
            token = '%s/%s' % (dsp.distribution.name, dsp.name)
2240
 
            binaries = dsp.publishing_history[0].getBuiltBinaries()
2241
 
            binary_names = [binary.binary_package_name for binary in binaries]
2242
 
            if binary_names != []:
2243
 
                summary = ', '.join(binary_names)
2244
 
            else:
2245
 
                summary = 'Not yet built.'
2246
 
            summary = token + ' ' + summary
2247
 
            return SimpleTerm(dsp.sourcepackagename, token, summary)
 
2253
            summary = '%s (%s)' % (token, dsp.name)
 
2254
 
 
2255
            # We try to get the binaries for the dsp; if this fails, we return
 
2256
            # lookup error instead.
 
2257
            dsp.publishing_history[0].getBuiltBinaries()
 
2258
            return SimpleTerm(dsp, token, summary)
 
2259
            #return SimpleTerm(dsp, token, summary)
2248
2260
        except (IndexError, AttributeError):
2249
2261
            # Either the DSP was None or there is no publishing history.
2250
2262
            raise LookupError(distribution, spn_or_dsp)
2270
2282
            return EmptyResultSet()
2271
2283
        search_term = unicode(query)
2272
2284
        store = IStore(SourcePackagePublishingHistory)
2273
 
        spns = store.using(
 
2285
        dsps = store.using(
2274
2286
            SourcePackagePublishingHistory,
2275
2287
            LeftJoin(
2276
2288
                SourcePackageRelease,
2281
2293
                SourcePackageRelease.sourcepackagenameID ==
2282
2294
                    SourcePackageName.id),
2283
2295
            LeftJoin(
2284
 
                DistroSeries,
2285
 
                SourcePackagePublishingHistory.distroseriesID ==
2286
 
                    DistroSeries.id),
 
2296
                DistributionSourcePackageInDatabase,
 
2297
                SourcePackageName.id ==
 
2298
                    DistributionSourcePackageInDatabase.sourcepackagename_id),
2287
2299
            LeftJoin(
2288
2300
                BinaryPackageBuild,
2289
2301
                BinaryPackageBuild.source_package_release_id ==
2296
2308
                BinaryPackageRelease.binarypackagenameID ==
2297
2309
                    BinaryPackageName.id
2298
2310
            )).find(
2299
 
                SourcePackageName,
2300
 
                DistroSeries.distributionID == distribution.id,
 
2311
                DistributionSourcePackageInDatabase,
 
2312
                DistributionSourcePackageInDatabase.distribution_id ==
 
2313
                    distribution.id,
2301
2314
                SourcePackagePublishingHistory.status.is_in((
2302
2315
                    PackagePublishingStatus.PENDING,
2303
2316
                    PackagePublishingStatus.PUBLISHED)),
2308
2321
                    BinaryPackageName.name.contains_string(
2309
2322
                        search_term))).config(distinct=True)
2310
2323
        # XXX sinzui 2011-07-26: This query ignored SPN branches.
2311
 
        return CountableIterator(spns.count(), spns, self.toTerm)
 
2324
        return CountableIterator(dsps.count(), dsps, self.toTerm)