def get_string_representation(obj): """Returns a string representation of an object. It can be used as oldvalue and newvalue. Returns None if no representation can be made. """ if IPerson.providedBy(obj): return obj.name if IBug.providedBy(obj): return str(obj.id) elif ISourcePackageRelease.providedBy(obj): return "%s %s" % (obj.sourcepackagename.name, obj.version) elif IProductRelease.providedBy(obj): return "%s %s" % (obj.product.name, obj.version) elif IMilestone.providedBy(obj): return obj.name elif isinstance(obj, BaseItem): return obj.title elif isinstance(obj, basestring): return obj elif isinstance(obj, bool): return str(obj) else: return None
def setTarget(self, target): """Constrain the search to only return items in target. This is equivalent to calling setProduct etc but the type of target does not need to be known to the caller. :param target: A `IHasBug`, or some search term like all/any/none on `IHasBug`. If using all/any all the targets must be of the same type due to implementation limitations. Currently only distroseries and productseries `IHasBug` implementations are supported. """ # Yay circular deps. from lp.registry.interfaces.distribution import IDistribution from lp.registry.interfaces.distroseries import IDistroSeries from lp.registry.interfaces.product import IProduct from lp.registry.interfaces.productseries import IProductSeries from lp.registry.interfaces.milestone import IMilestone from lp.registry.interfaces.projectgroup import IProjectGroup from lp.registry.interfaces.sourcepackage import ISourcePackage from lp.registry.interfaces.distributionsourcepackage import \ IDistributionSourcePackage if isinstance(target, (any, all)): assert len(target.query_values), \ 'cannot determine target with no targets' instance = target.query_values[0] else: instance = target if IDistribution.providedBy(instance): self.setDistribution(target) elif IDistroSeries.providedBy(instance): self.setDistroSeries(target) elif IProduct.providedBy(instance): self.setProduct(target) elif IProductSeries.providedBy(instance): self.setProductSeries(target) elif IMilestone.providedBy(instance): self.milestone = target elif ISourcePackage.providedBy(instance): self.setSourcePackage(target) elif IDistributionSourcePackage.providedBy(instance): self.setSourcePackage(target) elif IProjectGroup.providedBy(instance): self.setProjectGroup(target) else: raise AssertionError("unknown target type %r" % target)
def setTarget(self, target): """Constrain the search to only return items in target. This is equivalent to calling setProduct etc but the type of target does not need to be known to the caller. :param target: A `IHasBug`, or some search term like all/any/none on `IHasBug`. If using all/any all the targets must be of the same type due to implementation limitations. Currently only distroseries and productseries `IHasBug` implementations are supported. """ # Yay circular deps. from lp.registry.interfaces.distribution import IDistribution from lp.registry.interfaces.distroseries import IDistroSeries from lp.registry.interfaces.product import IProduct from lp.registry.interfaces.productseries import IProductSeries from lp.registry.interfaces.milestone import IMilestone from lp.registry.interfaces.projectgroup import IProjectGroup from lp.registry.interfaces.sourcepackage import ISourcePackage from lp.registry.interfaces.distributionsourcepackage import \ IDistributionSourcePackage if isinstance(target, (any, all)): assert len(target.query_values), \ 'cannot determine target with no targets' instance = target.query_values[0] else: instance = target if IDistribution.providedBy(instance): self.setDistribution(target) elif IDistroSeries.providedBy(instance): self.setDistroSeries(target) elif IProduct.providedBy(instance): self.setProduct(target) elif IProductSeries.providedBy(instance): self.setProductSeries(target) elif IMilestone.providedBy(instance): self.milestone = target elif ISourcePackage.providedBy(instance): self.setSourcePackage(target) elif IDistributionSourcePackage.providedBy(instance): self.setSourcePackage(target) elif IProjectGroup.providedBy(instance): self.setProject(target) else: raise AssertionError("unknown target type %r" % target)