~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

[rs=buildbot-poller] automatic merge from stable. Revisions: 13730,
        13731 included.

Show diffs side-by-side

added added

removed removed

Lines of Context:
101
101
from lp.registry.interfaces.person import IPersonSet
102
102
from lp.registry.interfaces.pocket import PackagePublishingPocket
103
103
from lp.registry.interfaces.series import SeriesStatus
 
104
from lp.services.browser_helpers import get_plural_text
104
105
from lp.services.features import getFeatureFlag
105
106
from lp.services.propertycache import cachedproperty
106
107
from lp.services.worlddata.interfaces.country import ICountry
127
128
    ]
128
129
 
129
130
 
 
131
def get_dsd_source():
 
132
    """For convenience: the `IDistroSeriesDifferenceSource` utility."""
 
133
    return getUtility(IDistroSeriesDifferenceSource)
 
134
 
 
135
 
130
136
class DistroSeriesNavigation(GetitemNavigation, BugTargetTraversalMixin,
131
137
    StructuralSubscriptionTargetTraversalMixin):
132
138
 
400
406
                return 'a parent series'
401
407
 
402
408
 
 
409
def word_differences_count(count):
 
410
    """Express "`count` differences" in words.
 
411
 
 
412
    For example, "1 package", or "2 packages" and so on.
 
413
    """
 
414
    return get_plural_text(count, "%d package", "%d packages") % count
 
415
 
 
416
 
403
417
class DistroSeriesView(LaunchpadView, MilestoneOverlayMixin,
404
418
                       DerivedDistroSeriesMixin):
405
419
 
463
477
    def milestone_batch_navigator(self):
464
478
        return BatchNavigator(self.context.all_milestones, self.request)
465
479
 
466
 
    def _num_differences(self, difference_type):
467
 
        differences = getUtility(
468
 
            IDistroSeriesDifferenceSource).getForDistroSeries(
469
 
                self.context,
470
 
                difference_type=difference_type,
471
 
                status=(DistroSeriesDifferenceStatus.NEEDS_ATTENTION,))
 
480
    def countDifferences(self, difference_type, needing_attention_only=True):
 
481
        """Count the number of differences of a given kind.
 
482
 
 
483
        :param difference_type: Type of `DistroSeriesDifference` to look for.
 
484
        :param needing_attention_only: Restrict count to differences that need
 
485
            attention?  If not, count all that can be viewed.
 
486
        """
 
487
        if needing_attention_only:
 
488
            status = (DistroSeriesDifferenceStatus.NEEDS_ATTENTION, )
 
489
        else:
 
490
            status = None
 
491
 
 
492
        differences = get_dsd_source().getForDistroSeries(
 
493
            self.context, difference_type=difference_type, status=status)
472
494
        return differences.count()
473
495
 
474
496
    @cachedproperty
475
 
    def num_differences(self):
476
 
        return self._num_differences(
 
497
    def num_version_differences_needing_attention(self):
 
498
        return self.countDifferences(
477
499
            DistroSeriesDifferenceType.DIFFERENT_VERSIONS)
478
500
 
479
501
    @cachedproperty
 
502
    def num_version_differences(self):
 
503
        return self.countDifferences(
 
504
            DistroSeriesDifferenceType.DIFFERENT_VERSIONS,
 
505
            needing_attention_only=False)
 
506
 
 
507
    def wordVersionDifferences(self):
 
508
        return word_differences_count(self.num_version_differences)
 
509
 
 
510
    @cachedproperty
480
511
    def num_differences_in_parent(self):
481
 
        return self._num_differences(
 
512
        return self.countDifferences(
482
513
            DistroSeriesDifferenceType.MISSING_FROM_DERIVED_SERIES)
483
514
 
 
515
    def wordDifferencesInParent(self):
 
516
        return word_differences_count(self.num_differences_in_parent)
 
517
 
484
518
    @cachedproperty
485
519
    def num_differences_in_child(self):
486
 
        return self._num_differences(
 
520
        return self.countDifferences(
487
521
            DistroSeriesDifferenceType.UNIQUE_TO_DERIVED_SERIES)
488
522
 
 
523
    def wordDifferencesInChild(self):
 
524
        return word_differences_count(self.num_differences_in_child)
 
525
 
 
526
    def alludeToParent(self):
 
527
        """Wording to refer to the series' parent(s).
 
528
 
 
529
        If there is a single parent, returns its display name.  Otherwise
 
530
        says "a parent series" (more vague, but we could also name parents
 
531
        if there are very few).
 
532
        """
 
533
        if self.has_unique_parent:
 
534
            return self.unique_parent.displayname
 
535
        else:
 
536
            return "a parent series"
 
537
 
 
538
    @cachedproperty
 
539
    def link_to_version_diffs_needing_attention(self):
 
540
        """Return URL for +localpackagediffs page."""
 
541
        return canonical_url(self.context, view_name='+localpackagediffs')
 
542
 
 
543
    @property
 
544
    def link_to_all_version_diffs(self):
 
545
        """Return URL for +localdiffs page for all statuses."""
 
546
        return (
 
547
            "%s?field.package_type=all"
 
548
            % self.link_to_version_diffs_needing_attention)
 
549
 
 
550
    @property
 
551
    def link_to_differences_in_parent(self):
 
552
        """Return URL for +missingpackages page."""
 
553
        return canonical_url(self.context, view_name='+missingpackages')
 
554
 
 
555
    @property
 
556
    def link_to_differences_in_child(self):
 
557
        """Return URL for +uniquepackages page."""
 
558
        return canonical_url(self.context, view_name='+uniquepackages')
 
559
 
489
560
 
490
561
class DistroSeriesEditView(LaunchpadEditFormView, SeriesStatusMixin):
491
562
    """View class that lets you edit a DistroSeries object.
1090
1161
    def cached_differences(self):
1091
1162
        """Return a batch navigator of filtered results."""
1092
1163
        package_type_dsd_status = {
1093
 
            NON_IGNORED: (
1094
 
                DistroSeriesDifferenceStatus.NEEDS_ATTENTION,),
 
1164
            NON_IGNORED: DistroSeriesDifferenceStatus.NEEDS_ATTENTION,
1095
1165
            HIGHER_VERSION_THAN_PARENT: (
1096
1166
                DistroSeriesDifferenceStatus.BLACKLISTED_CURRENT),
1097
1167
            RESOLVED: DistroSeriesDifferenceStatus.RESOLVED,
1098
 
            ALL: DistroSeriesDifferenceStatus.items,
 
1168
            ALL: None,
1099
1169
        }
1100
1170
 
1101
1171
        # If the package_type option is not supported, add an error to
1107
1177
            status = package_type_dsd_status[self.specified_package_type]
1108
1178
            child_version_higher = (
1109
1179
                self.specified_package_type == HIGHER_VERSION_THAN_PARENT)
1110
 
            differences = getUtility(
1111
 
                IDistroSeriesDifferenceSource).getForDistroSeries(
1112
 
                    self.context, difference_type=self.differences_type,
1113
 
                    name_filter=self.specified_name_filter,
1114
 
                    status=status, child_version_higher=child_version_higher,
1115
 
                    packagesets=self.specified_packagesets_filter,
1116
 
                    changed_by=self.specified_changed_by_filter)
 
1180
            differences = get_dsd_source().getForDistroSeries(
 
1181
                self.context, difference_type=self.differences_type,
 
1182
                name_filter=self.specified_name_filter, status=status,
 
1183
                child_version_higher=child_version_higher,
 
1184
                packagesets=self.specified_packagesets_filter,
 
1185
                changed_by=self.specified_changed_by_filter)
1117
1186
 
1118
1187
        return BatchNavigator(differences, self.request)
1119
1188
 
1185
1254
 
1186
1255
        :return: A result set of `DistroSeriesDifference`s.
1187
1256
        """
1188
 
        return getUtility(IDistroSeriesDifferenceSource).getSimpleUpgrades(
1189
 
            self.context)
 
1257
        return get_dsd_source().getSimpleUpgrades(self.context)
1190
1258
 
1191
1259
    @action(_("Upgrade Packages"), name="upgrade", condition='canUpgrade')
1192
1260
    def upgrade(self, action, data):