← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~wgrant/launchpad/kill-iprimarycontext into lp:launchpad

 

William Grant has proposed merging lp:~wgrant/launchpad/kill-iprimarycontext into lp:launchpad.

Commit message:
Kill off IPrimaryContext. It's replaced by the breadcrumb iterator and IHeadingBreadcrumb.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~wgrant/launchpad/kill-iprimarycontext/+merge/243200

Kill off IPrimaryContext. It's replaced by the breadcrumb iterator and IHeadingBreadcrumb.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~wgrant/launchpad/kill-iprimarycontext into lp:launchpad.
=== modified file 'lib/lp/bugs/browser/bugbranch.py'
--- lib/lp/bugs/browser/bugbranch.py	2014-11-27 20:52:37 +0000
+++ lib/lp/bugs/browser/bugbranch.py	2014-11-29 03:34:51 +0000
@@ -8,7 +8,6 @@
     'BranchLinkToBugView',
     'BugBranchAddView',
     'BugBranchDeleteView',
-    'BugBranchPrimaryContext',
     'BugBranchView',
     ]
 
@@ -38,16 +37,6 @@
     canonical_url,
     LaunchpadView,
     )
-from lp.services.webapp.interfaces import IPrimaryContext
-
-
-class BugBranchPrimaryContext:
-    """The primary context is the bug branch link is that of the branch."""
-
-    implements(IPrimaryContext)
-
-    def __init__(self, bug_branch):
-        self.context = IPrimaryContext(bug_branch.branch).context
 
 
 class BugBranchAddView(LaunchpadFormView):

=== modified file 'lib/lp/bugs/browser/bugnomination.py'
--- lib/lp/bugs/browser/bugnomination.py	2012-10-11 14:24:15 +0000
+++ lib/lp/bugs/browser/bugnomination.py	2014-11-29 03:34:51 +0000
@@ -16,7 +16,6 @@
 import pytz
 from zope.component import getUtility
 from zope.interface import Interface
-from zope.publisher.interfaces import implements
 
 from lp import _
 from lp.app.browser.launchpadform import (
@@ -36,19 +35,7 @@
     LaunchpadView,
     )
 from lp.services.webapp.authorization import check_permission
-from lp.services.webapp.interfaces import (
-    ILaunchBag,
-    IPrimaryContext,
-    )
-
-
-class BugNominationPrimaryContext:
-    """The primary context is the nearest `IBugTarget`."""
-    implements(IPrimaryContext)
-
-    def __init__(self, nomination):
-        launchbag = getUtility(ILaunchBag)
-        self.context = launchbag.bugtask.target
+from lp.services.webapp.interfaces import ILaunchBag
 
 
 class BugNominationView(LaunchpadFormView):

=== modified file 'lib/lp/bugs/browser/tests/bug-nomination-views.txt'
--- lib/lp/bugs/browser/tests/bug-nomination-views.txt	2012-12-20 14:55:13 +0000
+++ lib/lp/bugs/browser/tests/bug-nomination-views.txt	2014-11-29 03:34:51 +0000
@@ -250,56 +250,3 @@
 
     >>> print request.response.notifications[0].message
     Targeted bug to: Ubuntu Grumpy
-
-
-IPrimaryContext for BugNominations
-----------------------------------
-
-A BugNomination can be adapted to its IPrimaryContext for use with
-menus. The IPrimaryContext for a BugNomination is the IBugTarget
-traversed in the URL.
-
-    >>> from lp.services.webapp.interfaces import IPrimaryContext
-    >>> from lp.bugs.interfaces.bugnomination import (
-    ...     IBugNominationSet)
-
-    >>> bugnominationset = getUtility(IBugNominationSet)
-
-The product 'firefox' is the IBugTarget in
-/firefox/+bug/1/nominations/1/+editstatus.
-
-    >>> firefox_nomination = bugnominationset.get(1)
-    >>> firefox_nomination.bug.id
-    1
-    >>> firefox_nomination.bug == bug_one_in_firefox.bug
-    True
-
-    >>> launchbag.clear()
-    >>> launchbag.add(bug_one_in_firefox.target)
-    >>> launchbag.add(bug_one_in_firefox)
-    >>> launchbag.bugtask.target.name
-    u'firefox'
-
-    >>> bugtarget = launchbag.bugtask.target
-    >>> IPrimaryContext(firefox_nomination).context == bugtarget
-    True
-
-The source package 'mozilla-firefox in Ubuntu' is the IBugTarget in
-/ubuntu/+source/mozilla-firefox/+bug/1/nominations/2/+editstatus.
-
-    >>> ubuntu_firefox_nomination = bugnominationset.get(2)
-    >>> ubuntu_firefox_nomination.bug.id
-    1
-    >>> ubuntu_firefox_nomination.bug == bug_one_in_ubuntu_firefox.bug
-    True
-
-    >>> launchbag.clear()
-    >>> launchbag.add(bug_one_in_ubuntu_firefox.target)
-    >>> launchbag.add(bug_one_in_ubuntu_firefox)
-    >>> launchbag.bugtask.target.displayname
-    u'mozilla-firefox in Ubuntu'
-
-    >>> bugtarget = launchbag.bugtask.target
-    >>> IPrimaryContext(ubuntu_firefox_nomination).context == bugtarget
-    True
-

=== removed file 'lib/lp/bugs/browser/tests/test_bugbranch.py'
--- lib/lp/bugs/browser/tests/test_bugbranch.py	2012-08-08 07:22:51 +0000
+++ lib/lp/bugs/browser/tests/test_bugbranch.py	1970-01-01 00:00:00 +0000
@@ -1,30 +0,0 @@
-# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
-# GNU Affero General Public License version 3 (see the file LICENSE).
-
-"""Unit tests for BugBranches."""
-
-__metaclass__ = type
-
-from lp.services.webapp.interfaces import IPrimaryContext
-from lp.testing import (
-    login_person,
-    TestCaseWithFactory,
-    )
-from lp.testing.layers import DatabaseFunctionalLayer
-
-
-class TestBugBranchPrimaryContext(TestCaseWithFactory):
-    # Tests the adaptation of a bug branch link into a primary context.
-
-    layer = DatabaseFunctionalLayer
-
-    def testPrimaryContext(self):
-        # The primary context of a bug branch link is the same as the
-        # primary context of the branch that is linked to the bug.
-        branch = self.factory.makeProductBranch()
-        bug = self.factory.makeBug(target=branch.product)
-        login_person(branch.owner)
-        bugbranch = bug.linkBranch(branch, branch.owner)
-        self.assertEqual(
-            IPrimaryContext(bugbranch).context,
-            IPrimaryContext(bugbranch.branch).context)

=== modified file 'lib/lp/bugs/configure.zcml'
--- lib/lp/bugs/configure.zcml	2014-11-24 06:20:03 +0000
+++ lib/lp/bugs/configure.zcml	2014-11-29 03:34:51 +0000
@@ -532,10 +532,6 @@
             attributes="
                 destroySelf"/>
     </class>
-    <adapter
-        for="lp.bugs.interfaces.bugbranch.IBugBranch"
-        provides="lp.services.webapp.interfaces.IPrimaryContext"
-        factory="lp.bugs.browser.bugbranch.BugBranchPrimaryContext"/>
 
     <!-- hierarchy -->
 
@@ -795,10 +791,6 @@
         <allow
             interface="lp.bugs.interfaces.bugmessage.IBugMessageSet"/>
     </securedutility>
-    <adapter
-        for="lp.bugs.interfaces.bugnomination.IBugNomination"
-        provides="lp.services.webapp.interfaces.IPrimaryContext"
-        factory="lp.bugs.browser.bugnomination.BugNominationPrimaryContext"/>
         <class
             class="lp.bugs.model.bugnomination.BugNomination">
             <require

=== modified file 'lib/lp/code/browser/branchmergeproposal.py'
--- lib/lp/code/browser/branchmergeproposal.py	2014-08-19 04:56:39 +0000
+++ lib/lp/code/browser/branchmergeproposal.py	2014-11-29 03:34:51 +0000
@@ -21,7 +21,6 @@
     'BranchMergeProposalJumpQueueView',
     'BranchMergeProposalNavigation',
     'BranchMergeProposalMergedView',
-    'BranchMergeProposalPrimaryContext',
     'BranchMergeProposalRequestReviewView',
     'BranchMergeProposalResubmitView',
     'BranchMergeProposalSubscribersView',
@@ -127,7 +126,6 @@
 from lp.services.webapp.authorization import check_permission
 from lp.services.webapp.breadcrumb import Breadcrumb
 from lp.services.webapp.escaping import structured
-from lp.services.webapp.interfaces import IPrimaryContext
 from lp.services.webapp.menu import NavigationMenu
 
 
@@ -153,16 +151,6 @@
         key=operator.attrgetter('date_created'), reverse=True)
 
 
-class BranchMergeProposalPrimaryContext:
-    """The primary context is the proposal is that of the source branch."""
-
-    implements(IPrimaryContext)
-
-    def __init__(self, branch_merge_proposal):
-        self.context = IPrimaryContext(
-            branch_merge_proposal.source_branch).context
-
-
 class BranchMergeProposalBreadcrumb(Breadcrumb):
     """An `IBreadcrumb` for a merge proposal."""
 

=== modified file 'lib/lp/code/browser/branchsubscription.py'
--- lib/lp/code/browser/branchsubscription.py	2014-11-27 20:52:37 +0000
+++ lib/lp/code/browser/branchsubscription.py	2014-11-29 03:34:51 +0000
@@ -9,11 +9,9 @@
     'BranchSubscriptionAddView',
     'BranchSubscriptionEditOwnView',
     'BranchSubscriptionEditView',
-    'BranchSubscriptionPrimaryContext',
     ]
 
 from zope.component import getUtility
-from zope.interface import implements
 
 from lp.app.browser.launchpadform import (
     action,
@@ -33,16 +31,6 @@
     precache_permission_for_objects,
     )
 from lp.services.webapp.escaping import structured
-from lp.services.webapp.interfaces import IPrimaryContext
-
-
-class BranchSubscriptionPrimaryContext:
-    """The primary context is the subscription is that of the branch."""
-
-    implements(IPrimaryContext)
-
-    def __init__(self, branch_subscription):
-        self.context = IPrimaryContext(branch_subscription.branch).context
 
 
 class BranchPortletSubscribersContent(LaunchpadView):

=== modified file 'lib/lp/code/browser/codereviewcomment.py'
--- lib/lp/code/browser/codereviewcomment.py	2014-08-19 04:56:39 +0000
+++ lib/lp/code/browser/codereviewcomment.py	2014-11-29 03:34:51 +0000
@@ -6,7 +6,6 @@
 __all__ = [
     'CodeReviewCommentAddView',
     'CodeReviewCommentContextMenu',
-    'CodeReviewCommentPrimaryContext',
     'CodeReviewCommentView',
     'CodeReviewDisplayComment',
     ]
@@ -51,7 +50,6 @@
     LaunchpadView,
     Link,
     )
-from lp.services.webapp.interfaces import IPrimaryContext
 
 
 class ICodeReviewDisplayComment(IComment, ICodeReviewComment):
@@ -131,16 +129,6 @@
     return display_comment.comment.message
 
 
-class CodeReviewCommentPrimaryContext:
-    """The primary context is the comment is that of the source branch."""
-
-    implements(IPrimaryContext)
-
-    def __init__(self, comment):
-        self.context = IPrimaryContext(
-            comment.branch_merge_proposal).context
-
-
 class CodeReviewCommentContextMenu(ContextMenu):
     """Context menu for branches."""
 

=== modified file 'lib/lp/code/browser/tests/test_branchmergeproposal.py'
--- lib/lp/code/browser/tests/test_branchmergeproposal.py	2013-05-08 00:56:03 +0000
+++ lib/lp/code/browser/tests/test_branchmergeproposal.py	2014-11-29 03:34:51 +0000
@@ -60,7 +60,6 @@
 from lp.services.webapp import canonical_url
 from lp.services.webapp.interfaces import (
     BrowserNotificationLevel,
-    IPrimaryContext,
     )
 from lp.services.webapp.servers import LaunchpadTestRequest
 from lp.testing import (
@@ -81,20 +80,6 @@
 from lp.testing.views import create_initialized_view
 
 
-class TestBranchMergeProposalPrimaryContext(TestCaseWithFactory):
-    """Tests the adaptation of a merge proposal into a primary context."""
-
-    layer = DatabaseFunctionalLayer
-
-    def testPrimaryContext(self):
-        # The primary context of a merge proposal is the same as the primary
-        # context of the source_branch.
-        bmp = self.factory.makeBranchMergeProposal()
-        self.assertEqual(
-            IPrimaryContext(bmp).context,
-            IPrimaryContext(bmp.source_branch).context)
-
-
 class TestBranchMergeProposalContextMenu(TestCaseWithFactory):
 
     layer = DatabaseFunctionalLayer

=== modified file 'lib/lp/code/browser/tests/test_branchsubscription.py'
--- lib/lp/code/browser/tests/test_branchsubscription.py	2013-01-16 06:41:43 +0000
+++ lib/lp/code/browser/tests/test_branchsubscription.py	2014-11-29 03:34:51 +0000
@@ -6,7 +6,6 @@
 __metaclass__ = type
 
 from lp.app.enums import InformationType
-from lp.services.webapp.interfaces import IPrimaryContext
 from lp.testing import (
     person_logged_in,
     TestCaseWithFactory,
@@ -15,20 +14,6 @@
 from lp.testing.views import create_initialized_view
 
 
-class TestBranchSubscriptionPrimaryContext(TestCaseWithFactory):
-    # Tests the adaptation of a branch subscription into a primary context.
-
-    layer = DatabaseFunctionalLayer
-
-    def testPrimaryContext(self):
-        # The primary context of a branch subscription is the same as the
-        # primary context of the branch that the subscription is for.
-        subscription = self.factory.makeBranchSubscription()
-        self.assertEqual(
-            IPrimaryContext(subscription).context,
-            IPrimaryContext(subscription.branch).context)
-
-
 class TestBranchSubscriptionAddOtherView(TestCaseWithFactory):
 
     layer = DatabaseFunctionalLayer

=== modified file 'lib/lp/code/browser/tests/test_codereviewcomment.py'
--- lib/lp/code/browser/tests/test_codereviewcomment.py	2014-04-04 04:30:48 +0000
+++ lib/lp/code/browser/tests/test_codereviewcomment.py	2014-11-29 03:34:51 +0000
@@ -23,7 +23,6 @@
     ICodeReviewInlineCommentSet,
     )
 from lp.services.webapp import canonical_url
-from lp.services.webapp.interfaces import IPrimaryContext
 from lp.testing import (
     BrowserTestCase,
     person_logged_in,
@@ -42,20 +41,6 @@
 
     layer = DatabaseFunctionalLayer
 
-    def testPrimaryContext(self):
-        # Tests the adaptation of a code review comment into a primary
-        # context.
-        # We need a person to make a comment.
-        with person_logged_in(self.factory.makePerson()):
-            # The primary context of a code review comment is the same
-            # as the primary context for the branch merge proposal that
-            # the comment is for.
-            comment = self.factory.makeCodeReviewComment()
-
-        self.assertEqual(
-            IPrimaryContext(comment).context,
-            IPrimaryContext(comment.branch_merge_proposal).context)
-
     def test_display_comment_provides_icodereviewdisplaycomment(self):
         # The CodeReviewDisplayComment class provides IComment.
         with person_logged_in(self.factory.makePerson()):

=== modified file 'lib/lp/code/configure.zcml'
--- lib/lp/code/configure.zcml	2014-11-23 21:37:40 +0000
+++ lib/lp/code/configure.zcml	2014-11-29 03:34:51 +0000
@@ -323,10 +323,6 @@
       for="lp.code.interfaces.branchmergeproposal.IBranchMergeProposal
            lp.code.interfaces.event.IBranchMergeProposalStatusChangeEvent"
       handler="lp.code.subscribers.karma.branch_merge_status_changed"/>
-  <adapter
-      for="lp.code.interfaces.branchmergeproposal.IBranchMergeProposal"
-      provides="lp.services.webapp.interfaces.IPrimaryContext"
-      factory="lp.code.browser.branchmergeproposal.BranchMergeProposalPrimaryContext"/>
 
   <!-- hierarchy -->
 
@@ -385,10 +381,6 @@
         permission="zope.Public"
         set_schema="lp.code.interfaces.branchsubscription.IBranchSubscription"/>
   </class>
-  <adapter
-      for="lp.code.interfaces.branchsubscription.IBranchSubscription"
-      provides="lp.services.webapp.interfaces.IPrimaryContext"
-      factory="lp.code.browser.branchsubscription.BranchSubscriptionPrimaryContext"/>
 
   <!-- Branch -->
 
@@ -432,10 +424,6 @@
       for="lp.code.interfaces.branch.IBranch"
       provides="lp.app.browser.badge.IHasBadges"
       factory="lp.code.browser.branchlisting.BranchBadges"/>
-  <adapter
-      for="lp.code.interfaces.branch.IBranch"
-      provides="lp.services.webapp.interfaces.IPrimaryContext"
-      factory="lp.code.model.branchtarget.branch_to_target"/>
 
   <subscriber
       for="lp.code.interfaces.branch.IBranch
@@ -585,10 +573,6 @@
       for="lp.code.interfaces.codereviewcomment.ICodeReviewComment
            lp.code.interfaces.event.INewCodeReviewCommentEvent"
       handler="lp.code.subscribers.karma.code_review_comment_added"/>
-  <adapter
-      for="lp.code.interfaces.codereviewcomment.ICodeReviewComment"
-      provides="lp.services.webapp.interfaces.IPrimaryContext"
-      factory="lp.code.browser.codereviewcomment.CodeReviewCommentPrimaryContext"/>
 
   <!-- CodeReviewInlineComment -->
 

=== modified file 'lib/lp/code/interfaces/branchtarget.py'
--- lib/lp/code/interfaces/branchtarget.py	2013-01-07 02:40:55 +0000
+++ lib/lp/code/interfaces/branchtarget.py	2014-11-29 03:34:51 +0000
@@ -102,16 +102,10 @@
         """Are branches from other_target mergeable into this target."""
 
     def __eq__(other):
-        """Is this target the same as another target?
-
-        Generally implemented in terms of `IPrimaryContext.context`.
-        """
+        """Is this target the same as another target?"""
 
     def __ne__(other):
-        """Is this target not the same as another target?
-
-        Generally implemented in terms of `IPrimaryContext.context`.
-        """
+        """Is this target not the same as another target?"""
 
     def getNamespace(owner):
         """Return a `IBranchNamespace` for 'owner' and this target."""

=== modified file 'lib/lp/code/model/branchtarget.py'
--- lib/lp/code/model/branchtarget.py	2012-01-01 02:58:52 +0000
+++ lib/lp/code/model/branchtarget.py	2014-11-29 03:34:51 +0000
@@ -5,7 +5,6 @@
 
 __metaclass__ = type
 __all__ = [
-    'branch_to_target',
     'PackageBranchTarget',
     'PersonBranchTarget',
     'ProductBranchTarget',
@@ -32,11 +31,6 @@
 from lp.services.webapp.sorting import sorted_version_numbers
 
 
-def branch_to_target(branch):
-    """Adapt an IBranch to an IBranchTarget."""
-    return branch.target
-
-
 class _BaseBranchTarget:
 
     def __eq__(self, other):

=== modified file 'lib/lp/code/model/tests/test_branchtarget.py'
--- lib/lp/code/model/tests/test_branchtarget.py	2012-09-18 18:36:09 +0000
+++ lib/lp/code/model/tests/test_branchtarget.py	2014-11-29 03:34:51 +0000
@@ -22,7 +22,6 @@
     )
 from lp.registry.interfaces.pocket import PackagePublishingPocket
 from lp.services.webapp import canonical_url
-from lp.services.webapp.interfaces import IPrimaryContext
 from lp.testing import (
     person_logged_in,
     run_with_login,
@@ -565,20 +564,3 @@
         removeSecurityProxy(branch).branchChanged(
             '', self.factory.getUniqueString(), None, None, None)
         self.assertEqual(branch, check_default_stacked_on(branch))
-
-
-class TestPrimaryContext(TestCaseWithFactory):
-
-    layer = DatabaseFunctionalLayer
-
-    def test_package_branch(self):
-        branch = self.factory.makePackageBranch()
-        self.assertEqual(branch.target, IPrimaryContext(branch))
-
-    def test_personal_branch(self):
-        branch = self.factory.makePersonalBranch()
-        self.assertEqual(branch.target, IPrimaryContext(branch))
-
-    def test_product_branch(self):
-        branch = self.factory.makeProductBranch()
-        self.assertEqual(branch.target, IPrimaryContext(branch))

=== modified file 'lib/lp/services/webapp/configure.zcml'
--- lib/lp/services/webapp/configure.zcml	2013-06-20 05:50:00 +0000
+++ lib/lp/services/webapp/configure.zcml	2014-11-29 03:34:51 +0000
@@ -91,12 +91,6 @@
         factory="lp.services.webapp.menu.MenuLink"
         />
 
-    <adapter
-        for="*"
-        provides="lp.services.webapp.interfaces.IPrimaryContext"
-        factory="lp.services.webapp.publication.DefaultPrimaryContext"
-        />
-
     <class class="lp.services.webapp.menu.MenuLink">
         <require
             permission="zope.Public"

=== modified file 'lib/lp/services/webapp/interfaces.py'
--- lib/lp/services/webapp/interfaces.py	2014-11-24 01:20:26 +0000
+++ lib/lp/services/webapp/interfaces.py	2014-11-29 03:34:51 +0000
@@ -750,11 +750,6 @@
     """A widget that is displayed like a check box with label to the right."""
 
 
-class IPrimaryContext(Interface):
-    """The primary context that used to determine the tabs for the web UI."""
-    context = Attribute('The primary context.')
-
-
 class IFinishReadOnlyRequestEvent(Interface):
     """An event which gets sent when the publication is ended"""
 

=== modified file 'lib/lp/services/webapp/publication.py'
--- lib/lp/services/webapp/publication.py	2014-01-30 15:04:06 +0000
+++ lib/lp/services/webapp/publication.py	2014-11-29 03:34:51 +0000
@@ -80,7 +80,6 @@
     ILaunchpadRoot,
     IOpenLaunchBag,
     IPlacelessAuthUtility,
-    IPrimaryContext,
     NoReferrerError,
     OffsiteFormPostError,
     )
@@ -746,15 +745,6 @@
     """Exception thrown when the number of threads isn't set correctly."""
 
 
-class DefaultPrimaryContext:
-    """The default primary context is the context."""
-
-    implements(IPrimaryContext)
-
-    def __init__(self, context):
-        self.context = context
-
-
 _browser_re = re.compile(r"""(?x)^(
     Mozilla |
     Opera |


Follow ups