← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~stevenk/launchpad/dsp-picker-fields into lp:launchpad

 

Steve Kowalik has proposed merging lp:~stevenk/launchpad/dsp-picker-fields into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~stevenk/launchpad/dsp-picker-fields/+merge/70382

Add a new feature flag, 'disclosure.dsp_picker.enabled', which will change source and binary package name pickers to use the new DistributionSourcePackage vocabulary, which will look for publication information for the distribution specified.

Drive-by some lint.
-- 
https://code.launchpad.net/~stevenk/launchpad/dsp-picker-fields/+merge/70382
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~stevenk/launchpad/dsp-picker-fields into lp:launchpad.
=== modified file 'lib/lp/app/widgets/launchpadtarget.py'
--- lib/lp/app/widgets/launchpadtarget.py	2011-07-26 00:47:07 +0000
+++ lib/lp/app/widgets/launchpadtarget.py	2011-08-03 23:36:43 +0000
@@ -39,6 +39,7 @@
     IDistributionSourcePackage,
     )
 from lp.registry.interfaces.product import IProduct
+from lp.services.features import getFeatureFlag
 
 
 class LaunchpadTargetWidget(BrowserWidget, InputWidget):
@@ -53,6 +54,12 @@
     def setUpSubWidgets(self):
         if self._widgets_set_up:
             return
+        if bool(getFeatureFlag('disclosure.dsp_picker.enabled')):
+            # Replace the default field with a field that uses the better
+            # vocabulary.
+            package_vocab = 'DistributionSourcePackage'
+        else:
+            package_vocab = 'BinaryAndSourcePackageName'
         fields = [
             Choice(
                 __name__='product', title=u'Project',
@@ -63,7 +70,7 @@
                 default=getUtility(ILaunchpadCelebrities).ubuntu),
             Choice(
                 __name__='package', title=u"Package",
-                required=False, vocabulary='BinaryAndSourcePackageName'),
+                required=False, vocabulary=package_vocab),
             ]
         self.distribution_widget = CustomWidgetFactory(
             LaunchpadDropdownWidget)
@@ -136,9 +143,14 @@
                 if package_name is None:
                     return distribution
                 try:
-                    source_name = (
-                        distribution.guessPublishedSourcePackageName(
-                            package_name.name))
+                    if bool(getFeatureFlag('disclosure.dsp_picker.enabled')):
+                        vocab = self.package_widget.context.vocabulary
+                        name = package_name.name
+                        source_name = vocab.getTermByToken(name).value
+                    else:
+                        source_name = (
+                            distribution.guessPublishedSourcePackageName(
+                                package_name.name))
                 except NotFoundError:
                     raise LaunchpadValidationError(
                         "There is no package name '%s' published in %s"

=== modified file 'lib/lp/bugs/browser/bugalsoaffects.py'
--- lib/lp/bugs/browser/bugalsoaffects.py	2011-07-26 17:18:19 +0000
+++ lib/lp/bugs/browser/bugalsoaffects.py	2011-08-03 23:36:43 +0000
@@ -3,8 +3,11 @@
 
 __metaclass__ = type
 
-__all__ = ['BugAlsoAffectsProductMetaView', 'BugAlsoAffectsDistroMetaView',
-           'BugAlsoAffectsProductWithProductCreationView']
+__all__ = [
+    'BugAlsoAffectsProductMetaView',
+    'BugAlsoAffectsDistroMetaView',
+    'BugAlsoAffectsProductWithProductCreationView'
+    ]
 
 import cgi
 from textwrap import dedent
@@ -14,6 +17,7 @@
     Item,
     )
 from lazr.lifecycle.event import ObjectCreatedEvent
+from lazr.restful.interface import copy_field
 from z3c.ptcompat import ViewPageTemplateFile
 from zope.app.form.browser import DropdownWidget
 from zope.app.form.interfaces import MissingInputError
@@ -41,7 +45,6 @@
     )
 from lp.app.enums import ServiceUsage
 from lp.app.interfaces.launchpad import ILaunchpadCelebrities
-from lp.app.validators import LaunchpadValidationError
 from lp.app.validators.email import email_validator
 from lp.app.widgets.itemswidgets import LaunchpadRadioWidget
 from lp.app.widgets.popup import SearchForUpstreamPopupWidget
@@ -82,6 +85,7 @@
     IProductSet,
     License,
     )
+from lp.services.features import getFeatureFlag
 from lp.services.fields import StrippedTextLine
 from lp.services.propertycache import cachedproperty
 
@@ -352,6 +356,17 @@
     label = "Also affects distribution/package"
     target_field_names = ('distribution', 'sourcepackagename')
 
+    def setUpFields(self):
+        super(DistroBugTaskCreationStep, self).setUpFields()
+        if bool(getFeatureFlag('disclosure.dsp_picker.enabled')):
+            # Replace the default field with a field that uses the better
+            # vocabulary.
+            self.form_fields = self.form_fields.omit('sourcepackagename')
+            new_sourcepackagename = copy_field(
+                IAddBugTaskForm['sourcepackagename'],
+                vocabulary='DistributionSourcePackage')
+            self.form_fields += form.Fields(new_sourcepackagename)
+
     @property
     def initial_values(self):
         """Return the initial values for the view's fields."""

=== modified file 'lib/lp/bugs/browser/bugtask.py'
--- lib/lp/bugs/browser/bugtask.py	2011-08-03 05:00:46 +0000
+++ lib/lp/bugs/browser/bugtask.py	2011-08-03 23:36:43 +0000
@@ -86,7 +86,6 @@
     IDisplayWidget,
     IInputWidget,
     InputErrors,
-    WidgetsError,
     )
 from zope.app.form.utility import (
     setUpWidget,
@@ -182,7 +181,6 @@
     ILaunchpadCelebrities,
     IServiceUsage,
     )
-from lp.app.validators import LaunchpadValidationError
 from lp.app.widgets.itemswidgets import LabeledMultiCheckBoxWidget
 from lp.app.widgets.project import ProjectScopeWidget
 from lp.bugs.browser.bug import (
@@ -269,6 +267,7 @@
 from lp.registry.interfaces.sourcepackage import ISourcePackage
 from lp.registry.model.personroles import PersonRoles
 from lp.registry.vocabularies import MilestoneVocabulary
+from lp.services.features import getFeatureFlag
 from lp.services.fields import PersonChoice
 from lp.services.propertycache import cachedproperty
 
@@ -1332,6 +1331,14 @@
             self.form_fields['assignee'].custom_widget = CustomWidgetFactory(
                 BugTaskAssigneeWidget)
 
+        if bool(getFeatureFlag('disclosure.dsp_picker.enabled')):
+            # Replace the default field with a field that uses the better
+            # vocabulary.
+            self.form_fields = self.form_fields.omit('sourcepackagename')
+            self.form_fields += formlib.form.Fields(Choice(
+                __name__='sourcepackagename', title=_('SourcePackageName'),
+                required=False, vocabulary='DistributionSourcePackage'))
+
     def _getReadOnlyFieldNames(self):
         """Return the names of fields that will be rendered read only."""
         if self.context.target_uses_malone:
@@ -1453,7 +1460,6 @@
             # what it was!
             data_to_apply.pop('milestone', None)
 
-
         # We special case setting assignee and status, because there's
         # a workflow associated with changes to these fields.
         if "assignee" in data_to_apply:

=== modified file 'lib/lp/bugs/browser/widgets/bugtask.py'
--- lib/lp/bugs/browser/widgets/bugtask.py	2011-07-28 17:34:34 +0000
+++ lib/lp/bugs/browser/widgets/bugtask.py	2011-08-03 23:36:43 +0000
@@ -72,6 +72,7 @@
     UnrecognizedBugTrackerURL,
     )
 from lp.registry.interfaces.distribution import IDistributionSet
+from lp.services.features import getFeatureFlag
 from lp.services.fields import URIField
 
 
@@ -498,6 +499,17 @@
 
         distribution = self.getDistribution()
 
+        if bool(getFeatureFlag('disclosure.dsp_picker.enabled')):
+            try:
+                source = self.context.vocabulary.getTermByToken(input).value
+            except NotFoundError:
+                raise ConversionError(
+                    "Launchpad doesn't know of any source package named"
+                    " '%s' in %s." % (input, distribution.displayname))
+            else:
+                return source
+        # Else the untrusted SPN vocab was used so it needs seconday
+        # verification.
         try:
             source = distribution.guessPublishedSourcePackageName(input)
         except NotFoundError:

=== modified file 'lib/lp/registry/tests/test_dsp_vocabularies.py'
--- lib/lp/registry/tests/test_dsp_vocabularies.py	2011-07-26 19:06:06 +0000
+++ lib/lp/registry/tests/test_dsp_vocabularies.py	2011-08-03 23:36:43 +0000
@@ -151,7 +151,9 @@
         dsp = spph.sourcepackagerelease.distrosourcepackage
         vocabulary = DistributionSourcePackageVocabulary(dsp)
         term = vocabulary.toTerm(dsp)
-        self.assertEqual('Not yet built.', term.title)
+        expected_title = '%s/%s Not yet built.' % (
+            dsp.distribution.name, spph.source_package_name)
+        self.assertEqual(expected_title, term.title)
 
     def test_toTerm_built_single_binary_title(self):
         # The binary package name appears in the term's value.
@@ -162,7 +164,10 @@
             distribution=bpph.distroseries.distribution)
         vocabulary = DistributionSourcePackageVocabulary(dsp.distribution)
         term = vocabulary.toTerm(spr.sourcepackagename)
-        self.assertEqual(bpph.binary_package_name, term.title)
+        expected_title = '%s/%s %s' % (
+            dsp.distribution.name, spr.sourcepackagename.name,
+            bpph.binary_package_name)
+        self.assertEqual(expected_title, term.title)
 
     def test_toTerm_built_multiple_binary_title(self):
         # All of the binary package names appear in the term's value.
@@ -181,7 +186,10 @@
         dsp = spr.distrosourcepackage
         vocabulary = DistributionSourcePackageVocabulary(dsp.distribution)
         term = vocabulary.toTerm(spr.sourcepackagename)
-        self.assertEqual(', '.join(expected_names), term.title)
+        expected_title = '%s/%s %s' % (
+            dsp.distribution.name, spph.source_package_name,
+            ', '.join(expected_names))
+        self.assertEqual(expected_title, term.title)
 
     def test_getTermByToken_error(self):
         # An error is raised if the token does not match a published DSP.

=== modified file 'lib/lp/registry/vocabularies.py'
--- lib/lp/registry/vocabularies.py	2011-08-02 07:46:59 +0000
+++ lib/lp/registry/vocabularies.py	2011-08-03 23:36:43 +0000
@@ -95,6 +95,8 @@
     removeSecurityProxy,
     )
 
+from lazr.restful.interfaces import IReference
+
 from canonical.database.sqlbase import (
     quote,
     quote_like,
@@ -2079,7 +2081,9 @@
         self.context = context
         # Avoid circular import issues.
         from lp.answers.interfaces.question import IQuestion
-        if IBugTask.providedBy(context) or IQuestion.providedBy(context):
+        if IReference.providedBy(context):
+            target = context.context.target
+        elif IBugTask.providedBy(context) or IQuestion.providedBy(context):
             target = context.target
         else:
             target = context
@@ -2123,13 +2127,14 @@
             if distribution is not None and spn_or_dsp is not None:
                 dsp = distribution.getSourcePackage(spn_or_dsp)
         try:
+            token = '%s/%s' % (dsp.distribution.name, dsp.name)
             binaries = dsp.publishing_history[0].getBuiltBinaries()
             binary_names = [binary.binary_package_name for binary in binaries]
             if binary_names != []:
                 summary = ', '.join(binary_names)
             else:
                 summary = 'Not yet built.'
-            token = '%s/%s' % (dsp.distribution.name, dsp.name)
+            summary = token + ' ' + summary
             return SimpleTerm(dsp.sourcepackagename, token, summary)
         except (IndexError, AttributeError):
             # Either the DSP was None or there is no publishing history.

=== modified file 'lib/lp/services/features/flags.py'
--- lib/lp/services/features/flags.py	2011-08-02 23:42:08 +0000
+++ lib/lp/services/features/flags.py	2011-08-03 23:36:43 +0000
@@ -108,6 +108,10 @@
      'boolean',
      'Changes the appearance of notifications on private bugs.',
      ''),
+    ('disclosure.dsp_picker.enabled',
+     'boolean',
+     'Enables the use of the new DistributionSourcePackage vocabulary for '
+     'the source and binary package name pickers.'),
     ('disclosure.picker_enhancements.enabled',
      'boolean',
      ('Enables the display of extra details in the person picker.'),