← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~jcsackett/launchpad/rip-out-portlet into lp:launchpad

 

j.c.sackett has proposed merging lp:~jcsackett/launchpad/rip-out-portlet into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~jcsackett/launchpad/rip-out-portlet/+merge/126104

Summary
=======
The packaging suggestions portlet is really expensive and not useful. Let's
kill it.

Preimp
======
Spoke with Curtis Hovey.

Implementation
==============
The part of the packaging portlet that does suggestions is removed, along with
accompanying setup in the view and the (now) unnecessary tests.

Tests
=====
bin/test -vvcm lp.registry.browser.product

QA
==
Make sure that the suggestions portlet doesn't show up; make sure the linked
packages portlet does.

LoC
===
This kills LoC.

Lint
====

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/registry/browser/product.py
  lib/lp/registry/templates/product-portlet-packages.pt
  lib/lp/registry/stories/product/xx-product-index.txt
-- 
https://code.launchpad.net/~jcsackett/launchpad/rip-out-portlet/+merge/126104
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jcsackett/launchpad/rip-out-portlet into lp:launchpad.
=== modified file 'lib/lp/registry/browser/product.py'
--- lib/lp/registry/browser/product.py	2012-09-20 13:26:42 +0000
+++ lib/lp/registry/browser/product.py	2012-09-24 21:24:24 +0000
@@ -1184,18 +1184,10 @@
         return results
 
 
-class ProductPackagesPortletView(LaunchpadFormView):
+class ProductPackagesPortletView(LaunchpadView):
     """View class for product packaging portlet."""
 
     schema = Interface
-    package_field_name = 'distributionsourcepackage'
-    custom_widget(
-        package_field_name, LaunchpadRadioWidget, orientation='vertical')
-    suggestions = None
-    max_suggestions = 8
-    other_package = object()
-    not_packaged = object()
-    initial_focus_widget = None
 
     @cachedproperty
     def sourcepackages(self):
@@ -1211,89 +1203,6 @@
         """Are there packages, or can packages be suggested."""
         if len(self.sourcepackages) > 0:
             return True
-        if self.user is None:
-            return False
-        date_next_suggest_packaging = self.context.date_next_suggest_packaging
-        return (
-            date_next_suggest_packaging is None
-            or date_next_suggest_packaging <= datetime.now(tz=pytz.UTC))
-
-    @property
-    def initial_values(self):
-        """See `LaunchpadFormView`."""
-        return {self.package_field_name: self.other_package}
-
-    def initialize(self):
-        # The template only shows the form if the portlet is shown and
-        # there aren't any linked sourcepackages. If either of those
-        # conditions fails, there's no point setting up the widgets
-        # (with the expensive FTI query that entails).
-        if self.can_show_portlet and not self.sourcepackages:
-            super(ProductPackagesPortletView, self).initialize()
-
-    def setUpFields(self):
-        """See `LaunchpadFormView`."""
-        super(ProductPackagesPortletView, self).setUpFields()
-        ubuntu = getUtility(ILaunchpadCelebrities).ubuntu
-        distro_source_packages = ubuntu.searchSourcePackages(
-            self.context.name, has_packaging=False,
-            publishing_distroseries=ubuntu.currentseries)
-        # Based upon the matches, create a new vocabulary with
-        # term descriptions that include a link to the source package.
-        self.suggestions = []
-        vocab_terms = []
-        for package in distro_source_packages[:self.max_suggestions]:
-            if package.development_version.currentrelease is not None:
-                self.suggestions.append(package)
-                item_url = canonical_url(package)
-                description = structured(
-                    '<a href="%s">%s</a>', item_url, package.name)
-                vocab_terms.append(
-                    SimpleTerm(package, package.name, description))
-        # Add an option to represent the user's decision to choose a
-        # different package. Note that source packages cannot have uppercase
-        # names with underscores, so the name is safe to use.
-        description = 'Choose another Ubuntu package'
-        vocab_terms.append(
-            SimpleTerm(self.other_package, 'OTHER_PACKAGE', description))
-        vocabulary = SimpleVocabulary(vocab_terms)
-        # Add an option to represent that the project is not packaged in
-        # Ubuntu.
-        description = 'This project is not packaged in Ubuntu'
-        vocab_terms.append(
-            SimpleTerm(self.not_packaged, 'NOT_PACKAGED', description))
-        vocabulary = SimpleVocabulary(vocab_terms)
-        series_display_name = ubuntu.currentseries.displayname
-        self.form_fields = form.Fields(
-            Choice(__name__=self.package_field_name,
-                   title=_('Ubuntu %s packages') % series_display_name,
-                   default=None,
-                   vocabulary=vocabulary,
-                   required=True))
-
-    @action(_('Set Ubuntu Package Information'), name='link')
-    def link(self, action, data):
-        product = self.context
-        dsp = data.get(self.package_field_name)
-        product_series = product.development_focus
-        if dsp is self.other_package:
-            # The user wants to link an alternate package to this project.
-            self.next_url = canonical_url(
-                product_series, view_name="+ubuntupkg")
-            return
-        if dsp is self.not_packaged:
-            year_from_now = datetime.now(tz=pytz.UTC) + timedelta(days=365)
-            self.context.date_next_suggest_packaging = year_from_now
-            self.next_url = self.request.getURL()
-            return
-        ubuntu = getUtility(ILaunchpadCelebrities).ubuntu
-        product_series.setPackaging(ubuntu.currentseries,
-                                    dsp.sourcepackagename,
-                                    self.user)
-        self.request.response.addInfoNotification(
-            'This project was linked to the source package "%s"' %
-            dsp.displayname)
-        self.next_url = self.request.getURL()
 
 
 class SeriesReleasePair:

=== removed file 'lib/lp/registry/browser/tests/product-portlet-packages-view.txt'
--- lib/lp/registry/browser/tests/product-portlet-packages-view.txt	2012-04-10 14:01:17 +0000
+++ lib/lp/registry/browser/tests/product-portlet-packages-view.txt	1970-01-01 00:00:00 +0000
@@ -1,360 +0,0 @@
-+portlet-packages
------------------
-
-When the product is not linked to a source package in Ubuntu the
-+portlet-packages will show suggestions on potential matches and ask
-the user to make the connection.
-
-Create a helper to update the distribution source package cache, which
-does not happen automatically.
-
-    >>> from lp.testing.pages import (
-    ...     extract_text,
-    ...     find_tag_by_id,
-    ...     )
-    >>> from lp.app.interfaces.launchpad import ILaunchpadCelebrities
-    >>> from lp.registry.interfaces.product import IProductSet
-    >>> from lp.registry.interfaces.sourcepackagename import (
-    ...     ISourcePackageNameSet)
-    >>> from lp.soyuz.model.distributionsourcepackagecache import (
-    ...     DistributionSourcePackageCache)
-
-    >>> import transaction
-    >>> from lp.services.log.logger import BufferLogger
-    >>> logger = BufferLogger()
-    >>> from lp.services.config import config
-    >>> from lp.testing.dbuser import dbuser
-    >>> def updateCache():
-    ...     # Switch to the statistician user who is the only user with
-    ...     # write permission to the source package cache tables.
-    ...     ubuntu = getUtility(ILaunchpadCelebrities).ubuntu
-    ...     with dbuser(config.statistician.dbuser):
-    ...         DistributionSourcePackageCache.updateAll(
-    ...             ubuntu, archive=ubuntu.main_archive, log=logger,
-    ...             ztm=transaction)
-    ...     product = getUtility(IProductSet)['bingo']
-    ...     spn = getUtility(ISourcePackageNameSet)['bingo']
-    ...     login(ANONYMOUS)
-    ...     return (ubuntu, product, spn)
-
-Let's create a test project.
-
-    >>> product = factory.makeProduct(name="bingo")
-    >>> ignored = login_person(product.owner)
-    >>> view = create_initialized_view(
-    ...     product, name="+portlet-packages",
-    ...     principal=product.owner)
-    >>> print view.suggestions
-    []
-
-The view does not set focus to its form otherwise it will cause the page to
-scroll.
-
-    >>> view.focusedElementScript()
-    ''
-
-No distribution source packages match so the user is shown an
-appropriate message asking to suggest a match.
-
-    >>> content = find_tag_by_id(view.render(), 'portlet-packages')
-    >>> print extract_text(content)
-    All packages
-    Packages in Distributions
-    Launchpad doesn't know which Ubuntu packages this project
-    provides. Links from distribution packages to upstream projects
-    let distribution and upstream maintainers share bugs, patches, and
-    translations efficiently.
-    There are no unlinked source packages that are a good match. Can you
-    suggest one?
-    Ubuntu Hoary packages:
-    Choose another Ubuntu package
-    This project is not packaged in Ubuntu
-
-A distribution source package in a distribution other than ubuntu will
-not be suggested.
-
-    >>> spn = factory.makeSourcePackageName(name="bingo")
-    >>> distro_package = factory.makeDistributionSourcePackage(
-    ...     sourcepackagename=spn)
-    >>> spph = factory.makeSourcePackagePublishingHistory(
-    ...     sourcepackagename=spn)
-    >>> (ubuntu, product, spn) = updateCache()
-    >>> ignored = login_person(product.owner)
-    >>> view = create_initialized_view(
-    ...     product, name="+portlet-packages",
-    ...     principal=product.owner)
-    >>> print view.suggestions
-    []
-
-A source package that does NOT have a publishing history
-for the current Ubuntu series will NOT be suggested.
-
-    >>> warty = ubuntu.getSeries('warty')
-    >>> warty == ubuntu.currentseries
-    False
-    >>> spph = factory.makeSourcePackagePublishingHistory(
-    ...     sourcepackagename=spn, distroseries=warty)
-    >>> (ubuntu, product, spn) = updateCache()
-    >>> ignored = login_person(product.owner)
-    >>> view = create_initialized_view(
-    ...     product, name="+portlet-packages",
-    ...     principal=product.owner)
-    >>> view.suggestions
-    []
-
-A source package that does NOT have a publishing history in the PENDING
-or PUBLISHED statuses will NOT be suggested.
-
-    >>> from lp.soyuz.enums import PackagePublishingStatus
-    >>> spph = factory.makeSourcePackagePublishingHistory(
-    ...     sourcepackagename=spn, distroseries=ubuntu.currentseries,
-    ...     status=PackagePublishingStatus.DELETED)
-    >>> (ubuntu, product, spn) = updateCache()
-    >>> ignored = login_person(product.owner)
-    >>> view = create_initialized_view(
-    ...     product, name="+portlet-packages",
-    ...     principal=product.owner)
-    >>> for dsp in view.suggestions:
-    ...     print dsp.name
-
-A source package that does have a publishing history for the current
-Ubuntu series will be suggested. The view has a distributionsourcepackage
-field.
-
-    >>> spph = factory.makeSourcePackagePublishingHistory(
-    ...     sourcepackagename=spn, distroseries=ubuntu.currentseries,
-    ...     status=PackagePublishingStatus.PUBLISHED)
-    >>> ignored = login_person(product.owner)
-    >>> view = create_initialized_view(
-    ...     product, name="+portlet-packages",
-    ...     principal=product.owner)
-    >>> for dsp in view.suggestions:
-    ...     print dsp.name
-    bingo
-
-    >>> for field in view.form_fields:
-    ...     print field.__name__
-    distributionsourcepackage
-
-And the user is presented with a form to select the distribution
-source package.
-
-    >>> content = find_tag_by_id(view.render(), 'portlet-packages')
-
-    >>> print extract_text(content)
-    All packages
-    Packages in Distributions
-    Launchpad doesn't know which Ubuntu packages this project
-    provides. Links from distribution packages to upstream projects
-    let distribution and upstream maintainers share bugs, patches, and
-    translations efficiently.
-    Ubuntu Hoary packages:
-    bingo...
-
-A distribution series with a matching name in the Ubuntu current
-series will be suggested.
-
-    >>> distro_package = factory.makeDistributionSourcePackage(
-    ...     sourcepackagename=spn, distribution=ubuntu)
-    >>> spph = factory.makeSourcePackagePublishingHistory(
-    ...     sourcepackagename=spn, distroseries=ubuntu.currentseries)
-    >>> (ubuntu, product, spn) = updateCache()
-    >>> ignored = login_person(product.owner)
-    >>> view = create_initialized_view(
-    ...     product, name="+portlet-packages",
-    ...     principal=product.owner)
-    >>> for dsp in view.suggestions:
-    ...     print dsp.name
-    bingo
-
-If multiple source packages match they will all be displayed.
-
-    >>> spn = factory.makeSourcePackageName(name="ba-bingo")
-    >>> distro_package = factory.makeDistributionSourcePackage(
-    ...     sourcepackagename=spn, distribution=ubuntu)
-    >>> spph = factory.makeSourcePackagePublishingHistory(
-    ...     sourcepackagename=spn, distroseries=ubuntu.currentseries)
-    >>> (ubuntu, product, spn) = updateCache()
-    >>> ignored = login_person(product.owner)
-    >>> view = create_initialized_view(
-    ...     product, name="+portlet-packages",
-    ...     principal=product.owner)
-    >>> for dsp in view.suggestions:
-    ...     print dsp.name
-    ba-bingo
-    bingo
-
-    >>> content = find_tag_by_id(view.render(), 'portlet-packages')
-    >>> print extract_text(content)
-    All packages
-    Packages in Distributions
-    Launchpad doesn't know which Ubuntu packages this project
-    provides. Links from distribution packages to upstream projects
-    let distribution and upstream maintainers share bugs, patches, and
-    translations efficiently.
-    Ubuntu Hoary packages:
-    ba-bingo
-    bingo...
-
-But the limit is 8 packages.
-
-    >>> view.max_suggestions
-    8
-
-If a package matches by name but is already linked to an Ubuntu
-package then it will not be shown as one of the suggestions.
-
-    >>> new_product = factory.makeProduct(name="not-bingo")
-    >>> product_series = new_product.development_focus
-    >>> babingo_spn = getUtility(ISourcePackageNameSet)['ba-bingo']
-    >>> pkg = product_series.setPackaging(
-    ...     ubuntu.currentseries,
-    ...     babingo_spn, product.owner)
-    >>> (ubuntu, product, spn) = updateCache()
-    >>> ignored = login_person(product.owner)
-    >>> view = create_initialized_view(
-    ...     product, name="+portlet-packages",
-    ...     principal=product.owner)
-    >>> for dsp in view.suggestions:
-    ...     print dsp.name
-    bingo
-
-The view is not rendered when there are no source packages and the user is
-anonymous.
-
-    >>> login(ANONYMOUS)
-    >>> view = create_initialized_view(
-    ...     product, name="+portlet-packages", principal=product.owner)
-    >>> view.sourcepackages
-    []
-    >>> view.can_show_portlet
-    False
-
-The can_show_portlet property is False when
-product.date_next_suggest_packaging is None or the date is more than one
-year ago.
-
-    >>> from datetime import datetime, timedelta
-    >>> import pytz
-
-    >>> print product.date_next_suggest_packaging
-    None
-
-    >>> ignored = login_person(product.owner)
-    >>> view = create_initialized_view(
-    ...     product, name="+portlet-packages", principal=product.owner)
-    >>> view.can_show_portlet
-    True
-
-    >>> year_from_now = datetime.now(tz=pytz.UTC) + timedelta(days=365)
-    >>> product.date_next_suggest_packaging = year_from_now
-    >>> view = create_initialized_view(
-    ...     product, name="+portlet-packages", principal=product.owner)
-    >>> view.can_show_portlet
-    False
-
-    >>> yesterday = datetime.now(tz=pytz.UTC) - timedelta(days=1)
-    >>> product.date_next_suggest_packaging = yesterday
-    >>> view = create_initialized_view(
-    ...     product, name="+portlet-packages", principal=product.owner)
-    >>> view.can_show_portlet
-    True
-
-The +portlet-packages view can set the product date_next_suggest_packaging
-attribute so that suggestions are disabled.
-
-    >>> product.date_next_suggest_packaging = None
-    >>> almost_a_year = datetime.now(tz=pytz.UTC) + timedelta(days=364)
-    >>> form = {
-    ...     'field.distributionsourcepackage': 'NOT_PACKAGED',
-    ...     'field.actions.link': 'Set Ubuntu Package Information',
-    ...     }
-    >>> view = create_initialized_view(
-    ...     product, name="+portlet-packages", form=form)
-    >>> view.errors
-    []
-
-    >>> print product.date_next_suggest_packaging > almost_a_year
-    True
-    >>> product.date_next_suggest_packaging = None
-
-The +portlet-packages view can create a Packaging link.
-
-    >>> product.sourcepackages
-    []
-
-    >>> form = {
-    ...     'field.distributionsourcepackage': 'bingo',
-    ...     'field.actions.link': 'Set Ubuntu Package Information',
-    ...     }
-    >>> ignored = login_person(product.owner)
-    >>> view = create_initialized_view(
-    ...     product, name="+portlet-packages", form=form)
-    >>> view.errors
-    []
-
-    >>> for sp in product.sourcepackages:
-    ...     print sp.name
-    bingo
-
-    >>> from lp.registry.interfaces.packaging import (
-    ...     IPackagingUtil, PackagingType)
-
-    >>> packaging_util = getUtility(IPackagingUtil)
-    >>> packaging_util.deletePackaging(
-    ...     product.development_focus,
-    ...     getUtility(ISourcePackageNameSet)['bingo'],
-    ...     ubuntu.currentseries)
-
-Choosing the other_package option issues a redirect to the +ubuntupkg. The
-option is the default value.
-
-    >>> view.initial_values['distributionsourcepackage'] is view.other_package
-    True
-
-    >>> form = {
-    ...     'field.distributionsourcepackage': 'OTHER_PACKAGE',
-    ...     'field.actions.link': 'Set Ubuntu Package Information',
-    ...     }
-    >>> view = create_initialized_view(
-    ...     product, name="+portlet-packages", form=form)
-    >>> view.errors
-    []
-
-    >>> product.sourcepackages
-    []
-
-    >>> print view.next_url
-    http://launchpad.dev/bingo/trunk/+ubuntupkg
-
-The view's sourcepackages property filters out obsolete packages and
-reverses the order so that the latest packages for the current ubuntu
-series are shown first.
-
-    >>> spn = factory.makeSourcePackageName(name="a-obsolete-package")
-    >>> packaging = packaging_util.createPackaging(
-    ...     product.development_focus, spn, ubuntu.currentseries,
-    ...     PackagingType.PRIME, owner=product.owner)
-    >>> spn = factory.makeSourcePackageName(name="b-recent-package")
-    >>> spph = factory.makeSourcePackagePublishingHistory(
-    ...     sourcepackagename=spn, distroseries=ubuntu.currentseries)
-    >>> packaging = packaging_util.createPackaging(
-    ...     product.development_focus, spn, ubuntu.currentseries,
-    ...     PackagingType.PRIME, owner=product.owner)
-    >>> spn = factory.makeSourcePackageName(name="c-current-package")
-    >>> spph = factory.makeSourcePackagePublishingHistory(
-    ...     sourcepackagename=spn, distroseries=ubuntu.currentseries)
-    >>> packaging = packaging_util.createPackaging(
-    ...     product.development_focus, spn, ubuntu.currentseries,
-    ...     PackagingType.PRIME, owner=product.owner)
-    >>> for package in product.sourcepackages:
-    ...     print package.name
-    a-obsolete-package
-    b-recent-package
-    c-current-package
-
-    >>> view = create_initialized_view(product, name="+portlet-packages")
-    >>> for package in view.sourcepackages:
-    ...     print package.name
-    c-current-package
-    b-recent-package

=== modified file 'lib/lp/registry/stories/product/xx-product-index.txt'
--- lib/lp/registry/stories/product/xx-product-index.txt	2012-07-06 19:00:25 +0000
+++ lib/lp/registry/stories/product/xx-product-index.txt	2012-09-24 21:24:24 +0000
@@ -307,23 +307,3 @@
     All packages
     Packages in Distributions
     “mozilla-firefox” source package in Warty Version 0.9 uploaded on...
-
-A product that has linked packages now displays suggestions and asks
-the user to select the package.
-
-    >>> login(ANONYMOUS)
-    >>> product = factory.makeProduct(name='pmount')
-    >>> logout()
-    >>> user_browser.open('http://launchpad.dev/pmount')
-    >>> print extract_text(
-    ...     find_tag_by_id(user_browser.contents, 'portlet-packages'))
-    All packages...
-    Packages in Distributions...
-    Ubuntu Hoary packages:
-    pmount...
-
-    >>> user_browser.getControl(
-    ...     name='field.distributionsourcepackage').value = ['pmount']
-    >>> user_browser.getControl('Set Ubuntu Package Information').click()
-    >>> print_feedback_messages(user_browser.contents)
-    This project was linked to the source package "pmount in Ubuntu"

=== modified file 'lib/lp/registry/templates/product-portlet-packages.pt'
--- lib/lp/registry/templates/product-portlet-packages.pt	2012-06-11 00:03:25 +0000
+++ lib/lp/registry/templates/product-portlet-packages.pt	2012-09-24 21:24:24 +0000
@@ -7,6 +7,7 @@
   condition="view/can_show_portlet">
 
 <div class="portlet" id="portlet-packages">
+  <tal:has_packages condition="packages">
   <h2>
     <span class="see-all"><a
       tal:attributes="href context/menu:overview/packages/fmt:url">
@@ -14,8 +15,6 @@
     Packages in Distributions
   </h2>
 
-  <tal:has_packages condition="packages">
-
     <ul>
       <tal:pair tal:repeat="package packages">
         <li>
@@ -34,28 +33,5 @@
       </tal:pair>
     </ul>
   </tal:has_packages>
-
-  <tal:has_no_packages condition="not:packages">
-
-    <p>
-      Launchpad doesn't know which Ubuntu packages this project
-      provides.  Links from distribution packages to upstream projects
-      let distribution and upstream maintainers share bugs, patches, and
-      translations efficiently.
-    </p>
-    <div id="suggestions">
-      <p tal:condition="not:view/suggestions">
-        There are no unlinked source packages that are a good match.
-        Can you suggest one?
-      </p>
-
-      <div metal:use-macro="context/@@launchpad_form/form">
-        <div class="actions" metal:fill-slot="buttons">
-          <input tal:replace="structure view/link/render"/>
-        </div>
-      </div>
-    </div>
-
-  </tal:has_no_packages>
 </div>
 </tal:root>


Follow ups