~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/registry/browser/person.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-09-21 03:09:33 UTC
  • mfrom: (7675.1045.811 db-devel)
  • Revision ID: launchpad@pqm.canonical.com-20110921030933-mfkdkkkb99sskvrt
Merging db-stable at revno 10994

Show diffs side-by-side

added added

removed removed

Lines of Context:
326
326
from lp.soyuz.interfaces.archive import IArchiveSet
327
327
from lp.soyuz.interfaces.archivesubscriber import IArchiveSubscriberSet
328
328
from lp.soyuz.interfaces.binarypackagebuild import IBinaryPackageBuildSet
329
 
from lp.soyuz.interfaces.publishing import ISourcePackagePublishingHistory
 
329
from lp.soyuz.interfaces.sourcepackagerelease import ISourcePackageRelease
330
330
 
331
331
 
332
332
COMMASPACE = ', '
5160
5160
        return Link('+subscribedquestions', text, summary, icon='question')
5161
5161
 
5162
5162
 
5163
 
class SourcePackagePublishingHistoryWithStats:
5164
 
    """An ISourcePackagePublishinghistory, with extra stats added."""
 
5163
class SourcePackageReleaseWithStats:
 
5164
    """An ISourcePackageRelease, with extra stats added."""
5165
5165
 
5166
 
    implements(ISourcePackagePublishingHistory)
5167
 
    delegates(ISourcePackagePublishingHistory)
 
5166
    implements(ISourcePackageRelease)
 
5167
    delegates(ISourcePackageRelease)
5168
5168
    failed_builds = None
5169
5169
    needs_building = None
5170
5170
 
5171
 
    def __init__(self, spph, open_bugs, open_questions,
 
5171
    def __init__(self, sourcepackage_release, open_bugs, open_questions,
5172
5172
                 failed_builds, needs_building):
5173
 
        self.context = spph
5174
 
        self.spr = spph.sourcepackagerelease
 
5173
        self.context = sourcepackage_release
5175
5174
        self.open_bugs = open_bugs
5176
5175
        self.open_questions = open_questions
5177
5176
        self.failed_builds = failed_builds
5260
5259
 
5261
5260
        return header_message
5262
5261
 
5263
 
    def filterPPAPackageList(self, spphs):
5264
 
        """Remove publishings that the user is not allowed to see.
 
5262
    def filterPPAPackageList(self, packages):
 
5263
        """Remove packages that the user is not allowed to see.
5265
5264
 
5266
5265
        Given a list of PPA packages, some might be in a PPA that the
5267
5266
        user is not allowed to see, so they are filtered out of the list.
5274
5273
        # IPerson.getLatestUploadedPPAPackages() but formulating the SQL
5275
5274
        # query is virtually impossible!
5276
5275
        results = []
5277
 
        for spph in spphs:
5278
 
            package = spph.sourcepackagerelease
 
5276
        for package in packages:
5279
5277
            # Make a shallow copy to remove the Zope security.
5280
5278
            archives = set(package.published_archives)
5281
5279
            # Ensure the SPR.upload_archive is also considered.
5282
5280
            archives.add(package.upload_archive)
5283
5281
            for archive in archives:
5284
5282
                if check_permission('launchpad.View', archive):
5285
 
                    results.append(spph)
 
5283
                    results.append(package)
5286
5284
                    break
 
5285
 
5287
5286
        return results
5288
5287
 
5289
5288
    def _getDecoratedPackagesSummary(self, packages):
5334
5333
        self.uploaded_packages_header_message = header_message
5335
5334
        return results
5336
5335
 
5337
 
    def _calculateBuildStats(self, spphs):
 
5336
    def _calculateBuildStats(self, package_releases):
5338
5337
        """Calculate failed builds and needs_build state.
5339
5338
 
5340
 
        For each of the spphs, calculate the failed builds
 
5339
        For each of the package_releases, calculate the failed builds
5341
5340
        and the needs_build state, and return a tuple of two dictionaries,
5342
5341
        one containing the failed builds and the other containing
5343
5342
        True or False according to the needs_build state, both keyed by
5346
5345
        # Calculate all the failed builds with one query.
5347
5346
        build_set = getUtility(IBinaryPackageBuildSet)
5348
5347
        package_release_ids = [
5349
 
            spph.sourcepackagerelease.id for spph in spphs]
 
5348
            package_release.id for package_release in package_releases]
5350
5349
        all_builds = build_set.getBuildsBySourcePackageRelease(
5351
5350
            package_release_ids)
5352
5351
        # Make a dictionary of lists of builds keyed by SourcePackageRelease
5353
5352
        # and a dictionary of "needs build" state keyed by the same.
5354
5353
        builds_by_package = {}
5355
5354
        needs_build_by_package = {}
5356
 
        for spph in spphs:
5357
 
            package = spph.sourcepackagerelease
 
5355
        for package in package_releases:
5358
5356
            builds_by_package[package] = []
5359
5357
            needs_build_by_package[package] = False
5360
5358
        for build in all_builds:
5369
5367
 
5370
5368
        return (builds_by_package, needs_build_by_package)
5371
5369
 
5372
 
    def _addStatsToPackages(self, spphs):
 
5370
    def _addStatsToPackages(self, package_releases):
5373
5371
        """Add stats to the given package releases, and return them."""
5374
 
        filtered_spphs = [
5375
 
            spph for spph in spphs if
5376
 
            check_permission('launchpad.View', spph)]
5377
5372
        distro_packages = [
5378
 
            spph.meta_sourcepackage.distribution_sourcepackage
5379
 
            for spph in filtered_spphs]
 
5373
            package_release.distrosourcepackage
 
5374
            for package_release in package_releases]
5380
5375
        package_bug_counts = getUtility(IBugTaskSet).getBugCountsForPackages(
5381
5376
            self.user, distro_packages)
5382
5377
        open_bugs = {}
5389
5384
            distro_packages)
5390
5385
 
5391
5386
        builds_by_package, needs_build_by_package = self._calculateBuildStats(
5392
 
            filtered_spphs)
 
5387
            package_releases)
5393
5388
 
5394
5389
        return [
5395
 
            SourcePackagePublishingHistoryWithStats(
5396
 
                spph,
5397
 
                open_bugs[spph.meta_sourcepackage.distribution_sourcepackage],
5398
 
                package_question_counts[
5399
 
                    spph.meta_sourcepackage.distribution_sourcepackage],
5400
 
                builds_by_package[spph.sourcepackagerelease],
5401
 
                needs_build_by_package[spph.sourcepackagerelease])
5402
 
            for spph in filtered_spphs]
 
5390
            SourcePackageReleaseWithStats(
 
5391
                package, open_bugs[package.distrosourcepackage],
 
5392
                package_question_counts[package.distrosourcepackage],
 
5393
                builds_by_package[package],
 
5394
                needs_build_by_package[package])
 
5395
            for package in package_releases]
5403
5396
 
5404
5397
    def setUpBatch(self, packages):
5405
5398
        """Set up the batch navigation for the page being viewed.