On Fri, Aug 29, 2014 at 2:39 PM, Raphael Hertzog <[email protected]> wrote: > Hi, > > On Fri, 29 Aug 2014, Andrew Starr-Bochicchio wrote: >> This is done in distro_tracker/core/views.py Let me know if there is a >> better place. I know that views.py can become a bit of a dumping >> ground, but I didn't see anywhere that made more sense. > > It should probably be a method of PackageName so that we get the short > description for free in any other context... for example in the mail > bot when we confirm the subscription or something like that.
Makes sense. I think I've addressed all the other issues as well. Thanks for the review! -- Andrew Starr-Bochicchio Ubuntu Developer <https://launchpad.net/~andrewsomething> Debian Developer <http://qa.debian.org/developer.php?login=asb> PGP/GPG Key ID: D53FDCB1
From e8a3c78471190aca2a04a12100e075fe86ff869b Mon Sep 17 00:00:00 2001 From: Andrew Starr-Bochicchio <[email protected]> Date: Fri, 29 Aug 2014 13:05:03 -0700 Subject: [PATCH] Add the short description under the source package name. The current PTS only uses the short description if there is a binary package that has the same name as the source package. If not, it just displays "Source package" I have decided to fall back to the short description for the first binary package instead. --- distro_tracker/core/models.py | 23 +++++++++++++ distro_tracker/core/templates/core/package.html | 1 + distro_tracker/core/tests/tests_models.py | 33 +++++++++++++++++++ distro_tracker/core/tests/tests_views.py | 44 +++++++++++++++++++++++-- 4 files changed, 99 insertions(+), 2 deletions(-) diff --git a/distro_tracker/core/models.py b/distro_tracker/core/models.py index 2a16944..818fb36 100644 --- a/distro_tracker/core/models.py +++ b/distro_tracker/core/models.py @@ -306,6 +306,29 @@ class PackageName(models.Model): else: super(self, PackageName).delete(*args, **kwargs) + def short_description(self): + """ + Returns the most recent short description for a package. If there is + a binary package whose name matches the source package, its description + will be used. If not, the short description for the first binary package + will be used. + + If there are no binary packages to get the description from it returns + blank. + """ + try: + bin_pkg = BinaryPackage.objects.filter(binary_package_name=self) + return bin_pkg.first().short_description + except AttributeError: + try: + source = SourcePackage.objects.filter( + source_package_name=self).prefetch_related( + 'binary_packages') + bin_pkg = source.last().binarypackage_set.first() + return bin_pkg.short_description + except AttributeError: + return '' + class PseudoPackageName(PackageName): """ diff --git a/distro_tracker/core/templates/core/package.html b/distro_tracker/core/templates/core/package.html index c17f90f..3402eb8 100644 --- a/distro_tracker/core/templates/core/package.html +++ b/distro_tracker/core/templates/core/package.html @@ -16,6 +16,7 @@ </div> <div class="span6 col col-lg-6 text-center"> <h1>{{ package }}</h1> + <h4>{{ package.short_description }}</h4> </div> <div class="span3 col col-lg-3"> {% include 'core/package-search-form.html' %} diff --git a/distro_tracker/core/tests/tests_models.py b/distro_tracker/core/tests/tests_models.py index da7df4e..d16359a 100644 --- a/distro_tracker/core/tests/tests_models.py +++ b/distro_tracker/core/tests/tests_models.py @@ -1615,3 +1615,36 @@ class TeamTests(TestCase): self.assertTrue(membership.is_muted(self.package_name)) # The other package isn't self.assertFalse(membership.is_muted(package)) + + +class PackageNameTests(TestCase): + """ + Tests for the :class:`distro_tracker.core.models.PackageName` model. + """ + def setUp(self): + self.package = SourcePackageName.objects.create(name='dummy-package') + self.binary_package = BinaryPackageName.objects.create( + name='binary-package') + self.pseudo_package = \ + PseudoPackageName.objects.create(name='pseudo-pkg') + src_pkg = SourcePackage.objects.create( + source_package_name=self.package, version='1.0.0') + bin_pkg = BinaryPackage.objects.create( + binary_package_name=self.binary_package, + source_package=src_pkg, + short_description='a useful package') + src_pkg.binary_packages = [self.binary_package] + src_pkg.save() + bin_pkg.save() + + def test_get_short_description_for_source_pkg(self): + self.assertEqual(self.package.short_description(), 'a useful package') + + def test_get_short_description_for_binary_pkg(self): + self.assertEqual(self.binary_package.short_description(), + 'a useful package') + + def test_get_short_description_with_no_binary_pkgs(self): + pkg = SourcePackageName.objects.create(name='some-package') + + self.assertEqual(pkg.short_description(), '') diff --git a/distro_tracker/core/tests/tests_views.py b/distro_tracker/core/tests/tests_views.py index ba57849..02ad486 100644 --- a/distro_tracker/core/tests/tests_views.py +++ b/distro_tracker/core/tests/tests_views.py @@ -16,9 +16,9 @@ Tests for the Distro Tracker core views. from __future__ import unicode_literals from distro_tracker.test import TestCase from django.test.utils import override_settings -from distro_tracker.core.models import PackageName, BinaryPackageName +from distro_tracker.core.models import BinaryPackage, BinaryPackageName from distro_tracker.core.models import SourcePackageName, SourcePackage -from distro_tracker.core.models import PseudoPackageName +from distro_tracker.core.models import PackageName, PseudoPackageName from distro_tracker.core.models import ActionItem, ActionItemType import json @@ -40,8 +40,13 @@ class PackageViewTest(TestCase): PseudoPackageName.objects.create(name='pseudo-pkg') src_pkg = SourcePackage.objects.create( source_package_name=self.package, version='1.0.0') + bin_pkg = BinaryPackage.objects.create( + binary_package_name=self.binary_package, + source_package=src_pkg, + short_description='a useful package') src_pkg.binary_packages = [self.binary_package] src_pkg.save() + bin_pkg.save() def get_package_url(self, package_name): """ @@ -164,6 +169,41 @@ class PackageViewTest(TestCase): response = self.client.get(url, follow=True) self.assertEqual(404, response.status_code) + def test_short_desc_on_page_when_different(self): + """ + Tests that the short description is displayed. + """ + url = self.get_package_url(self.package.name) + response = self.client.get(url) + response_content = response.content.decode('utf-8') + + self.assertIn('a useful package', response_content) + + def test_short_desc_on_page_when_same(self): + """ + Tests that the short description is displayed when the source package + and binary package have the same name. + """ + package = SourcePackageName.objects.get_or_create( + name='another-package') + src_pkg = SourcePackage.objects.get_or_create( + source_package_name=package[0], version='2.0.0') + binary_package = BinaryPackageName.objects.get_or_create( + name='another-package') + bin_pkg = BinaryPackage.objects.get_or_create( + binary_package_name=binary_package[0], + source_package=src_pkg[0], + short_description='another useful package') + src_pkg[0].binary_packages = [binary_package[0]] + src_pkg[0].save() + bin_pkg[0].save() + + url = self.get_package_url(package[0].name) + response = self.client.get(url) + response_content = response.content.decode('utf-8') + + self.assertIn('another useful package', response_content) + class PackageSearchViewTest(TestCase): def setUp(self): -- 1.9.1

