Merge lp:~michael.nelson/ubuntu-webcatalog/987851-display-multiple-apps-from-banner into lp:ubuntu-webcatalog

Proposed by Michael Nelson
Status: Merged
Approved by: Łukasz Czyżykowski
Approved revision: 128
Merged at revision: 120
Proposed branch: lp:~michael.nelson/ubuntu-webcatalog/987851-display-multiple-apps-from-banner
Merge into: lp:ubuntu-webcatalog
Diff against target: 201 lines (+100/-8)
8 files modified
src/webcatalog/models/applications.py (+10/-4)
src/webcatalog/templates/webcatalog/application_list.html (+30/-0)
src/webcatalog/templates/webcatalog/department_overview.html (+1/-1)
src/webcatalog/templates/webcatalog/search_results.html (+1/-1)
src/webcatalog/tests/test_models.py (+2/-1)
src/webcatalog/tests/test_views.py (+35/-1)
src/webcatalog/urls.py (+1/-0)
src/webcatalog/views.py (+20/-0)
To merge this branch: bzr merge lp:~michael.nelson/ubuntu-webcatalog/987851-display-multiple-apps-from-banner
Reviewer Review Type Date Requested Status
Canonical Consumer Applications Hackers Pending
Review via email: mp+104922@code.launchpad.net

Commit message

Support exhibit links for multiple packages.

Description of the change

Overview
========

Adds an /applications/?pkg_name=foo&pkg_name=bar view which will display multiple packages from the url data.

Updates Exhibit.destination_url to use this new view.

`fab test`

You can demo locally by importing exhibits from production and clicking on the book exhibit. The result will look like this (note: icons not imported on my local machine).

http://people.canonical.com/~michaeln/tmp/987851-application-list-view.png

To post a comment you must log in.
Revision history for this message
ISD Branch Mangler (isd-branches-mangler) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/webcatalog/models/applications.py'
--- src/webcatalog/models/applications.py 2012-05-04 12:11:56 +0000
+++ src/webcatalog/models/applications.py 2012-05-08 06:45:21 +0000
@@ -273,7 +273,13 @@
273 app_label = 'webcatalog'273 app_label = 'webcatalog'
274274
275 def destination_url(self):275 def destination_url(self):
276 package = self.package_names.split(',')[0]276 pkg_names = self.package_names.split(',')
277 if not package:277 if len(pkg_names) == 1:
278 return ''278 pkg_name = pkg_names[0]
279 return reverse('wc-package-detail', kwargs={'package_name': package})279 if not pkg_name:
280 return ''
281 return reverse('wc-package-detail',
282 kwargs={'package_name': pkg_name})
283
284 return reverse('wc-package-list') + '?' + '&'.join(
285 ['pkg_name=%s' % pkg_name for pkg_name in pkg_names])
280286
=== added file 'src/webcatalog/templates/webcatalog/application_list.html'
--- src/webcatalog/templates/webcatalog/application_list.html 1970-01-01 00:00:00 +0000
+++ src/webcatalog/templates/webcatalog/application_list.html 2012-05-08 06:45:21 +0000
@@ -0,0 +1,30 @@
1{% extends "webcatalog/base.html" %}
2{% load i18n %}
3
4{% block title %}{% trans "Ubuntu Apps Directory" %}{% endblock %}
5{% block header %}Applications{% endblock %}
6
7{% block content %}
8
9<div id="leftbar">
10 <div class="portlet">
11 <div class="portletheader">App departments</div>
12 <ul class="portletactions">
13{% for dept in depts %}
14 {% include "webcatalog/department_overview_snippet.html" %}
15{% endfor %}
16 </ul>
17 </div>
18</div>
19
20<div class="main-column">
21 {% include "webcatalog/breadcrumbs_snippet.html" %}
22
23{% if applications %}
24 {% include "webcatalog/application_list_snippet.html" %}
25{% else %}
26<h4 class="not-found">{% trans "No applications found." %}</p>
27{% endif %}
28</div>
29
30{% endblock %}
031
=== renamed file 'src/webcatalog/templates/webcatalog/application_overview_snippet.html' => 'src/webcatalog/templates/webcatalog/application_list_snippet.html'
=== modified file 'src/webcatalog/templates/webcatalog/department_overview.html'
--- src/webcatalog/templates/webcatalog/department_overview.html 2012-04-11 14:09:10 +0000
+++ src/webcatalog/templates/webcatalog/department_overview.html 2012-05-08 06:45:21 +0000
@@ -41,7 +41,7 @@
41{% if page.object_list %}41{% if page.object_list %}
42{% include "webcatalog/batch_navigation.html" %}42{% include "webcatalog/batch_navigation.html" %}
43{% with applications=page.object_list %}43{% with applications=page.object_list %}
44 {% include "webcatalog/application_overview_snippet.html" %}44 {% include "webcatalog/application_list_snippet.html" %}
45{% endwith %}45{% endwith %}
46{% include "webcatalog/batch_navigation.html" %}46{% include "webcatalog/batch_navigation.html" %}
47{% else %}47{% else %}
4848
=== modified file 'src/webcatalog/templates/webcatalog/search_results.html'
--- src/webcatalog/templates/webcatalog/search_results.html 2012-04-05 01:14:34 +0000
+++ src/webcatalog/templates/webcatalog/search_results.html 2012-05-08 06:45:21 +0000
@@ -29,7 +29,7 @@
29{% if page.object_list %}29{% if page.object_list %}
30{% include "webcatalog/batch_navigation.html" %}30{% include "webcatalog/batch_navigation.html" %}
31{% with applications=page.object_list %}31{% with applications=page.object_list %}
32 {% include "webcatalog/application_overview_snippet.html" %}32 {% include "webcatalog/application_list_snippet.html" %}
33{% endwith %}33{% endwith %}
34{% include "webcatalog/batch_navigation.html" %}34{% include "webcatalog/batch_navigation.html" %}
35{% else %}35{% else %}
3636
=== modified file 'src/webcatalog/tests/test_models.py'
--- src/webcatalog/tests/test_models.py 2012-05-04 09:31:50 +0000
+++ src/webcatalog/tests/test_models.py 2012-05-08 06:45:21 +0000
@@ -237,7 +237,8 @@
237237
238 def test_destination_url_multiple_packages(self):238 def test_destination_url_multiple_packages(self):
239 exhibit = self.factory.make_exhibit(package_names='foobar,baz')239 exhibit = self.factory.make_exhibit(package_names='foobar,baz')
240 expected = reverse('wc-package-detail', args=['foobar'])240 expected = reverse('wc-package-list') + (
241 '?pkg_name=foobar&pkg_name=baz')
241 self.assertEqual(expected, exhibit.destination_url())242 self.assertEqual(expected, exhibit.destination_url())
242243
243 def test_destination_url_blank_packages(self):244 def test_destination_url_blank_packages(self):
244245
=== modified file 'src/webcatalog/tests/test_views.py'
--- src/webcatalog/tests/test_views.py 2012-05-07 09:06:44 +0000
+++ src/webcatalog/tests/test_views.py 2012-05-08 06:45:21 +0000
@@ -36,7 +36,10 @@
36from mock import patch36from mock import patch
37from rnrclient import ReviewDetails37from rnrclient import ReviewDetails
3838
39from webcatalog.models import DistroSeries39from webcatalog.models import (
40 Department,
41 DistroSeries,
42 )
40from webcatalog.tests.factory import TestCaseWithFactory43from webcatalog.tests.factory import TestCaseWithFactory
41from webcatalog.tests.helpers import patch_settings44from webcatalog.tests.helpers import patch_settings
4245
@@ -44,6 +47,7 @@
44__all__ = [47__all__ = [
45 'ApplicationDetailNoSeriesTestCase',48 'ApplicationDetailNoSeriesTestCase',
46 'ApplicationDetailTestCase',49 'ApplicationDetailTestCase',
50 'ApplicationListTestCase',
47 'ApplicationRecommendsTestCase',51 'ApplicationRecommendsTestCase',
48 'ApplicationReviewsTestCase',52 'ApplicationReviewsTestCase',
49 'ApplicationScreenshotsTestCase',53 'ApplicationScreenshotsTestCase',
@@ -398,6 +402,36 @@
398 self.assertEqual(natty, used.distroseries)402 self.assertEqual(natty, used.distroseries)
399403
400404
405class ApplicationListTestCase(TestCaseWithFactory):
406 def test_no_args_redirects_to_index(self):
407 response = self.client.get(reverse('wc-package-list'))
408
409 self.assertRedirects(response, reverse('wc-index'))
410
411 def test_includes_apps_for_pkg_names(self):
412 apps = [
413 self.factory.make_application(),
414 self.factory.make_application(),
415 self.factory.make_application(),
416 ]
417
418 response = self.client.get(
419 reverse('wc-package-list') + '?' + "&".join(
420 ['pkg_name=%s' % app.package_name for app in apps]))
421
422 self.assertEqual(200, response.status_code)
423 self.assertEqual(apps, response.context['applications'])
424
425 def test_includes_depts_in_context(self):
426 depts = Department.objects.filter(parent=None).order_by('name')
427
428 response = self.client.get(
429 reverse('wc-package-list') + '?pkg_name=firefox')
430
431 self.assertEqual(200, response.status_code)
432 self.assertEqual(list(depts), list(response.context['depts']))
433
434
401class SearchTestCase(TestCaseWithFactory):435class SearchTestCase(TestCaseWithFactory):
402 def setUp(self):436 def setUp(self):
403 super(SearchTestCase, self).setUp()437 super(SearchTestCase, self).setUp()
404438
=== modified file 'src/webcatalog/urls.py'
--- src/webcatalog/urls.py 2012-04-20 16:57:50 +0000
+++ src/webcatalog/urls.py 2012-05-08 06:45:21 +0000
@@ -36,6 +36,7 @@
36 'department_overview', name='wc-department'),36 'department_overview', name='wc-department'),
37 url(r'^department/(?P<dept_slug_or_id>[\w\d-]+)/$', 'department_overview',37 url(r'^department/(?P<dept_slug_or_id>[\w\d-]+)/$', 'department_overview',
38 name='wc-department'),38 name='wc-department'),
39 url(r'^applications/$', 'application_list', name='wc-package-list'),
39 url(r'^applications/screenshots/(?P<package_name>[-.+:\w]+)/$',40 url(r'^applications/screenshots/(?P<package_name>[-.+:\w]+)/$',
40 'application_screenshots', name="wc-package-screenshots"),41 'application_screenshots', name="wc-package-screenshots"),
41 url(r'^applications/(?P<distro>[-.+\w]+)/(?P<package_name>[-.+:\w]+)/$',42 url(r'^applications/(?P<distro>[-.+\w]+)/(?P<package_name>[-.+:\w]+)/$',
4243
=== modified file 'src/webcatalog/views.py'
--- src/webcatalog/views.py 2012-05-07 08:58:26 +0000
+++ src/webcatalog/views.py 2012-05-08 06:45:21 +0000
@@ -159,6 +159,26 @@
159 context_instance=context)159 context_instance=context)
160160
161161
162def application_list(request):
163 pkg_names = request.GET.getlist('pkg_name')
164 if not pkg_names:
165 # We have no need of a general paged view of apps here.
166 return HttpResponseRedirect(reverse('wc-index'))
167
168 applications = []
169 for pkg_name in pkg_names:
170 latest = Application.objects.find_best(
171 package_name=pkg_name)
172 if latest:
173 applications.append(latest)
174
175 depts = Department.objects.filter(parent=None).order_by('name')
176
177 return render_to_response('webcatalog/application_list.html',
178 context_instance=RequestContext(request,
179 dict(applications=applications, depts=depts)))
180
181
162def application_detail(request, package_name, distro=None):182def application_detail(request, package_name, distro=None):
163 if distro is None:183 if distro is None:
164 app = Application.objects.find_best_or_404(package_name=package_name)184 app = Application.objects.find_best_or_404(package_name=package_name)

Subscribers

People subscribed via source and target branches