launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #04803
[Merge] lp:~jcsackett/launchpad/target-adapters-aplenty into lp:launchpad
j.c.sackett has proposed merging lp:~jcsackett/launchpad/target-adapters-aplenty into lp:launchpad.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~jcsackett/launchpad/target-adapters-aplenty/+merge/73248
--
https://code.launchpad.net/~jcsackett/launchpad/target-adapters-aplenty/+merge/73248
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jcsackett/launchpad/target-adapters-aplenty into lp:launchpad.
=== modified file 'lib/lp/app/browser/configure.zcml'
--- lib/lp/app/browser/configure.zcml 2011-08-22 14:33:01 +0000
+++ lib/lp/app/browser/configure.zcml 2011-08-29 15:38:35 +0000
@@ -424,6 +424,14 @@
/>
<adapter
+ factory="lp.app.browser.vocabulary.ProductPickerEntrySourceAdapter"
+ />
+
+ <adapter
+ factory="lp.app.browser.vocabulary.DistributionPickerEntrySourceAdapter"
+ />
+
+ <adapter
factory="lp.app.browser.vocabulary.ArchivePickerEntrySourceAdapter"
/>
=== modified file 'lib/lp/app/browser/tests/test_vocabulary.py'
--- lib/lp/app/browser/tests/test_vocabulary.py 2011-08-21 21:19:39 +0000
+++ lib/lp/app/browser/tests/test_vocabulary.py 2011-08-29 15:38:35 +0000
@@ -150,6 +150,68 @@
self.assertEqual(None, None)
+class TestDistributionSourcePackagePickerEntrySourceAdapter(TestCaseWithFactory):
+
+ layer = DatabaseFunctionalLayer
+
+ def test_dsp_to_picker_entry(self):
+ dsp = self.factory.makeDistributionSourcePackage()
+ adapter = IPickerEntrySource(dsp)
+ self.assertTrue(IPickerEntrySource.providedBy(adapter))
+
+ def test_dsp_provides_summary(self):
+ dsp = self.factory.makeDistributionSourcePackage()
+ series = self.factory.makeDistroSeries(distribution=dsp.distribution)
+ release = self.factory.makeSourcePackageRelease(
+ distroseries=series,
+ sourcepackagename=dsp.sourcepackagename)
+ self.factory.makeSourcePackagePublishingHistory(
+ distroseries=series,
+ sourcepackagerelease=release)
+ [entry] = IPickerEntrySource(dsp).getPickerEntries([dsp], object())
+ self.assertEqual(entry.description, 'Not yet built.')
+
+ archseries = self.factory.makeDistroArchSeries(distroseries=series)
+ bpn = self.factory.makeBinaryPackageName(name='fnord')
+ self.factory.makeBinaryPackagePublishingHistory(
+ binarypackagename=bpn,
+ source_package_release=release,
+ sourcepackagename=dsp.sourcepackagename,
+ distroarchseries=archseries)
+ [entry] = IPickerEntrySource(dsp).getPickerEntries([dsp], object())
+ self.assertEqual(entry.description, 'fnord')
+
+
+class TestProductPickerEntrySourceAdapter(TestCaseWithFactory):
+
+ layer = DatabaseFunctionalLayer
+
+ def test_product_to_picker_entry(self):
+ product = self.factory.makeProduct()
+ adapter = IPickerEntrySource(product)
+ self.assertTrue(IPickerEntrySource.providedBy(adapter))
+
+ def test_product_provides_summary(self):
+ product = self.factory.makeProduct()
+ [entry] = IPickerEntrySource(product).getPickerEntries([product], object())
+ self.assertEqual(entry.description, product.summary)
+
+
+class TestDistributionPickerEntrySourceAdapter(TestCaseWithFactory):
+
+ layer = DatabaseFunctionalLayer
+
+ def test_distribution_to_picker_entry(self):
+ distribution = self.factory.makeDistribution()
+ adapter = IPickerEntrySource(distribution)
+ self.assertTrue(IPickerEntrySource.providedBy(adapter))
+
+ def test_distribution_provides_summary(self):
+ distribution = self.factory.makeDistribution()
+ [entry] = IPickerEntrySource(distribution).getPickerEntries([distribution], object())
+ self.assertEqual(entry.description, distribution.summary)
+
+
class TestPersonVocabulary:
implements(IHugeVocabulary)
test_persons = []
=== modified file 'lib/lp/app/browser/vocabulary.py'
--- lib/lp/app/browser/vocabulary.py 2011-08-22 14:33:01 +0000
+++ lib/lp/app/browser/vocabulary.py 2011-08-29 15:38:35 +0000
@@ -40,10 +40,12 @@
from canonical.launchpad.webapp.vocabulary import IHugeVocabulary
from lp.app.errors import UnexpectedFormData
from lp.code.interfaces.branch import IBranch
+from lp.registry.interfaces.distribution import IDistribution
from lp.registry.interfaces.distributionsourcepackage import (
IDistributionSourcePackage,
)
from lp.registry.interfaces.person import IPerson
+from lp.registry.interfaces.product import IProduct
from lp.registry.interfaces.sourcepackagename import ISourcePackageName
from lp.registry.model.pillaraffiliation import IHasAffiliation
from lp.registry.model.sourcepackagename import getSourcePackageDescriptions
@@ -226,12 +228,29 @@
return entries
+class TargetPickerEntrySourceAdapter(DefaultPickerEntrySourceAdapter):
+ """Adapt targets (Product, Package, Distribution) to PickerEntrySource."""
+
+ def getDescription(self, target):
+ """Gets the description data for target picker entries."""
+ raise NotImplemented
+
+ def getPickerEntries(self, term_values, context_object, **kwarg):
+ """See `IPickerEntrySource`"""
+ entries = (
+ super(TargetPickerEntrySourceAdapter, self)
+ .getPickerEntries(term_values, context_object, **kwarg))
+ for target, picker_entry in izip(term_values, entries):
+ picker_entry.description = self.getDescription(target)
+ return entries
+
+
@adapter(ISourcePackageName)
class SourcePackageNamePickerEntrySourceAdapter(
DefaultPickerEntrySourceAdapter):
"""Adapts ISourcePackageName to IPickerEntrySource."""
- def getPickerEntry(self, term_values, context_object, **kwarg):
+ def getPickerEntries(self, term_values, context_object, **kwarg):
"""See `IPickerEntrySource`"""
entries = (
super(SourcePackageNamePickerEntrySourceAdapter, self)
@@ -245,23 +264,35 @@
@adapter(IDistributionSourcePackage)
class DistributionSourcePackagePickerEntrySourceAdapter(
- DefaultPickerEntrySourceAdapter):
- """Adapts ISourcePackageName to IPickerEntrySource."""
-
- def getPickerEntries(self, term_values, context_object, **kwarg):
- """See `IPickerEntrySource`"""
- entries = (
- super(DistributionSourcePackagePickerEntrySourceAdapter, self)
- .getPickerEntries(term_values, context_object, **kwarg))
- for dsp, picker_entry in izip(term_values, entries):
- binaries = dsp.publishing_history[0].getBuiltBinaries()
- binary_names = [binary.binary_package_name for binary in binaries]
- if binary_names != []:
- description = ', '.join(binary_names)
- else:
- description = 'Not yet built.'
- picker_entry.description = description
- return entries
+ TargetPickerEntrySourceAdapter):
+ """Adapts IDistributionSourcePackage to IPickerEntrySource."""
+
+ def getDescription(self, target):
+ """See `TargetPickerEntrySource`"""
+ binaries = target.publishing_history[0].getBuiltBinaries()
+ binary_names = [binary.binary_package_name for binary in binaries]
+ if binary_names != []:
+ description = ', '.join(binary_names)
+ else:
+ description = 'Not yet built.'
+ return description
+
+
+@adapter(IProduct)
+class ProductPickerEntrySourceAdapter(TargetPickerEntrySourceAdapter):
+ """Adapts IProduct to IPickerEntrySource."""
+
+ def getDescription(self, target):
+ """See `TargetPickerEntrySource`"""
+ return target.summary
+
+
+@adapter(IDistribution)
+class DistributionPickerEntrySourceAdapter(TargetPickerEntrySourceAdapter):
+
+ def getDescription(self, target):
+ """See `TargetPickerEntrySource`"""
+ return target.summary
@adapter(IArchive)
Follow ups