~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/code/browser/branchlisting.py

Merge db-devel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
613
613
 
614
614
    def hasAnyBranchesVisibleByUser(self):
615
615
        """Does the context have any branches that are visible to the user?"""
616
 
        return self.branch_count > 0
 
616
        return not self.is_branch_count_zero
617
617
 
618
618
    def _getCollection(self):
619
619
        """Override this to say what branches will be in the listing."""
624
624
        """The number of total branches the user can see."""
625
625
        return self._getCollection().visibleByUser(self.user).count()
626
626
 
 
627
    @cachedproperty
 
628
    def is_branch_count_zero(self):
 
629
        """Is the number of total branches the user can see zero?."""
 
630
        # If the batch itself is not empty, we don't need to check
 
631
        # the whole collection count (it might be expensive to compute if the
 
632
        # total number of branches is huge).
 
633
        return (
 
634
            len(self.branches().visible_branches_for_view) == 0 and
 
635
            not self.branch_count)
 
636
 
627
637
    def _branches(self, lifecycle_status):
628
638
        """Return a sequence of branches.
629
639
 
885
895
        """
886
896
        return self.context
887
897
 
888
 
    @cachedproperty
889
 
    def has_branches(self):
890
 
        """Should the template show the summary view with the links."""
891
 
 
892
898
    @property
893
899
    def show_summary(self):
894
900
        """Should the template show the summary view with the links."""
895
901
 
896
902
        if self.simplified_branches_menu:
897
 
            return (
898
 
                self.registered_branches_not_empty or
899
 
                self.owned_branches_not_empty or
900
 
                self.subscribed_branches_not_empty or
901
 
                self.active_reviews_not_empty
902
 
                )
 
903
            return True
903
904
        else:
904
905
            return (
905
906
                self.owned_branch_count or
921
922
            not self._getCountCollection().registeredBy(
922
923
                self.person).is_empty())
923
924
 
924
 
    @cachedproperty
925
 
    def owned_branches_not_empty(self):
926
 
        """False if the number of branches owned by self.person is zero."""
927
 
        return not self._getCountCollection().ownedBy(self.person).is_empty()
928
 
 
929
 
    @cachedproperty
930
 
    def subscribed_branches_not_empty(self):
931
 
        """False if the number of branches subscribed to by self.person
932
 
        is zero.
933
 
        """
934
 
        return (
935
 
            not self._getCountCollection().subscribedBy(
936
 
                self.person).is_empty())
937
 
 
938
 
    @cachedproperty
939
 
    def active_reviews_not_empty(self):
940
 
        """Return the number of active reviews for self.person's branches."""
941
 
        active_reviews = PersonActiveReviewsView(self.context, self.request)
942
 
        return not active_reviews.getProposals().is_empty()
943
 
 
944
925
    def simplified_owned(self):
945
926
        return Link(
946
927
            canonical_url(self.context, rootsite='code'),
947
 
            'Owned branches',
948
 
            enabled=self.owned_branches_not_empty)
 
928
            'Owned branches')
949
929
 
950
930
    def simplified_registered(self):
951
931
        person_is_individual = (not self.person.is_team)
959
939
    def simplified_subscribed(self):
960
940
        return Link(
961
941
            '+subscribedbranches',
962
 
            'Subscribed branches',
963
 
            enabled=self.subscribed_branches_not_empty)
 
942
            'Subscribed branches')
964
943
 
965
944
    def simplified_active_reviews(self):
966
945
        return Link(
967
946
            '+activereviews',
968
 
            'Active reviews',
969
 
            enabled=self.active_reviews_not_empty)
 
947
            'Active reviews')
970
948
 
971
949
    @cachedproperty
972
950
    def registered_branch_count(self):
1033
1011
class PersonProductBranchesMenu(PersonBranchesMenu):
1034
1012
 
1035
1013
    usedfor = IPersonProduct
1036
 
    links = ['registered', 'owned', 'subscribed', 'active_reviews']
 
1014
    links = ['registered', 'owned', 'subscribed', 'active_reviews',
 
1015
             'simplified_subscribed', 'simplified_registered',
 
1016
             'simplified_owned', 'simplified_active_reviews']
1037
1017
 
1038
1018
    def _getCountCollection(self):
1039
1019
        """See `PersonBranchesMenu`."""