The attached patch adds 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.
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. Also this should really test both if the names match and if they don't, but for the life of me I can't figure out how to get that working in the test suite. I was trying something like: 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.create(name='another-package') src_pkg = SourcePackage.objects.create( source_package_name=package, version='2.0.0') binary_package = BinaryPackageName.objects.create( name='another-package') bin_pkg = BinaryPackage.objects.create( binary_package_name=binary_package, source_package=src_pkg, short_description='another useful package') src_pkg.binary_packages = [binary_package] src_pkg.save() url = self.get_package_url(self.package.name) response = self.client.get(url) response_content = response.content.decode('utf-8') self.assertIn('another useful package', response_content) Which fails with: IntegrityError: UNIQUE constraint failed: core_packagename.name There must be a way to do it but I'm starting to get a bit frustrated, so I figured I'd just ask. =) Thanks, -- 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 b2b7261a0f04e2ebc3ea6313def4f912515d5002 Mon Sep 17 00:00:00 2001 From: Andrew Starr-Bochicchio <a.star...@gmail.com> Date: Fri, 29 Aug 2014 13:05:03 -0700 Subject: [PATCH 2/2] 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/tests/tests_views.py | 18 ++++++++++++++++-- distro_tracker/core/views.py | 12 +++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/distro_tracker/core/tests/tests_views.py b/distro_tracker/core/tests/tests_views.py index efa2580..957b19a 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 @@ -39,6 +39,10 @@ class PackageViewTest(TestCase): 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() @@ -163,6 +167,16 @@ class PackageViewTest(TestCase): response = self.client.get(url, follow=True) self.assertEqual(404, response.status_code) + def test_short_desc_on_page(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) + class PackageSearchViewTest(TestCase): def setUp(self): diff --git a/distro_tracker/core/views.py b/distro_tracker/core/views.py index 4876575..597062c 100644 --- a/distro_tracker/core/views.py +++ b/distro_tracker/core/views.py @@ -29,7 +29,7 @@ from distro_tracker.core.models import get_web_package from distro_tracker.core.forms import CreateTeamForm from distro_tracker.core.forms import AddTeamMemberForm from distro_tracker.core.utils import render_to_json_response -from distro_tracker.core.models import SourcePackageName, PackageName, PseudoPackageName, BinaryPackageName +from distro_tracker.core.models import SourcePackageName, PackageName, PseudoPackageName, BinaryPackageName, SourcePackage, BinaryPackage from distro_tracker.core.models import ActionItem from distro_tracker.core.models import EmailSettings from distro_tracker.core.models import News, NewsRenderer @@ -55,6 +55,15 @@ def package_page(request, package_name): if package.get_absolute_url() != urlquote(request.path): return redirect(package) + try: + bin_pkg = BinaryPackage.objects.filter(binary_package_name=package) + desc = bin_pkg.first().short_description + except AttributeError: + source = SourcePackage.objects.filter(source_package_name=package) + bin_pkg_name = source.last().binary_packages.first() + bin_pkg = BinaryPackage.objects.filter(binary_package_name=bin_pkg_name) + desc = bin_pkg.first().short_description + is_subscribed = False if request.user.is_authenticated(): # Check if the user is subscribed to the package @@ -62,6 +71,7 @@ def package_page(request, package_name): return render(request, 'core/package.html', { 'package': package, + 'short_description': desc, 'panels': get_panels_for_package(package, request), 'is_subscribed': is_subscribed, }) -- 1.9.1