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
1=== modified file 'src/webcatalog/models/applications.py'
2--- src/webcatalog/models/applications.py 2012-05-04 12:11:56 +0000
3+++ src/webcatalog/models/applications.py 2012-05-08 06:45:21 +0000
4@@ -273,7 +273,13 @@
5 app_label = 'webcatalog'
6
7 def destination_url(self):
8- package = self.package_names.split(',')[0]
9- if not package:
10- return ''
11- return reverse('wc-package-detail', kwargs={'package_name': package})
12+ pkg_names = self.package_names.split(',')
13+ if len(pkg_names) == 1:
14+ pkg_name = pkg_names[0]
15+ if not pkg_name:
16+ return ''
17+ return reverse('wc-package-detail',
18+ kwargs={'package_name': pkg_name})
19+
20+ return reverse('wc-package-list') + '?' + '&'.join(
21+ ['pkg_name=%s' % pkg_name for pkg_name in pkg_names])
22
23=== added file 'src/webcatalog/templates/webcatalog/application_list.html'
24--- src/webcatalog/templates/webcatalog/application_list.html 1970-01-01 00:00:00 +0000
25+++ src/webcatalog/templates/webcatalog/application_list.html 2012-05-08 06:45:21 +0000
26@@ -0,0 +1,30 @@
27+{% extends "webcatalog/base.html" %}
28+{% load i18n %}
29+
30+{% block title %}{% trans "Ubuntu Apps Directory" %}{% endblock %}
31+{% block header %}Applications{% endblock %}
32+
33+{% block content %}
34+
35+<div id="leftbar">
36+ <div class="portlet">
37+ <div class="portletheader">App departments</div>
38+ <ul class="portletactions">
39+{% for dept in depts %}
40+ {% include "webcatalog/department_overview_snippet.html" %}
41+{% endfor %}
42+ </ul>
43+ </div>
44+</div>
45+
46+<div class="main-column">
47+ {% include "webcatalog/breadcrumbs_snippet.html" %}
48+
49+{% if applications %}
50+ {% include "webcatalog/application_list_snippet.html" %}
51+{% else %}
52+<h4 class="not-found">{% trans "No applications found." %}</p>
53+{% endif %}
54+</div>
55+
56+{% endblock %}
57
58=== renamed file 'src/webcatalog/templates/webcatalog/application_overview_snippet.html' => 'src/webcatalog/templates/webcatalog/application_list_snippet.html'
59=== modified file 'src/webcatalog/templates/webcatalog/department_overview.html'
60--- src/webcatalog/templates/webcatalog/department_overview.html 2012-04-11 14:09:10 +0000
61+++ src/webcatalog/templates/webcatalog/department_overview.html 2012-05-08 06:45:21 +0000
62@@ -41,7 +41,7 @@
63 {% if page.object_list %}
64 {% include "webcatalog/batch_navigation.html" %}
65 {% with applications=page.object_list %}
66- {% include "webcatalog/application_overview_snippet.html" %}
67+ {% include "webcatalog/application_list_snippet.html" %}
68 {% endwith %}
69 {% include "webcatalog/batch_navigation.html" %}
70 {% else %}
71
72=== modified file 'src/webcatalog/templates/webcatalog/search_results.html'
73--- src/webcatalog/templates/webcatalog/search_results.html 2012-04-05 01:14:34 +0000
74+++ src/webcatalog/templates/webcatalog/search_results.html 2012-05-08 06:45:21 +0000
75@@ -29,7 +29,7 @@
76 {% if page.object_list %}
77 {% include "webcatalog/batch_navigation.html" %}
78 {% with applications=page.object_list %}
79- {% include "webcatalog/application_overview_snippet.html" %}
80+ {% include "webcatalog/application_list_snippet.html" %}
81 {% endwith %}
82 {% include "webcatalog/batch_navigation.html" %}
83 {% else %}
84
85=== modified file 'src/webcatalog/tests/test_models.py'
86--- src/webcatalog/tests/test_models.py 2012-05-04 09:31:50 +0000
87+++ src/webcatalog/tests/test_models.py 2012-05-08 06:45:21 +0000
88@@ -237,7 +237,8 @@
89
90 def test_destination_url_multiple_packages(self):
91 exhibit = self.factory.make_exhibit(package_names='foobar,baz')
92- expected = reverse('wc-package-detail', args=['foobar'])
93+ expected = reverse('wc-package-list') + (
94+ '?pkg_name=foobar&pkg_name=baz')
95 self.assertEqual(expected, exhibit.destination_url())
96
97 def test_destination_url_blank_packages(self):
98
99=== modified file 'src/webcatalog/tests/test_views.py'
100--- src/webcatalog/tests/test_views.py 2012-05-07 09:06:44 +0000
101+++ src/webcatalog/tests/test_views.py 2012-05-08 06:45:21 +0000
102@@ -36,7 +36,10 @@
103 from mock import patch
104 from rnrclient import ReviewDetails
105
106-from webcatalog.models import DistroSeries
107+from webcatalog.models import (
108+ Department,
109+ DistroSeries,
110+ )
111 from webcatalog.tests.factory import TestCaseWithFactory
112 from webcatalog.tests.helpers import patch_settings
113
114@@ -44,6 +47,7 @@
115 __all__ = [
116 'ApplicationDetailNoSeriesTestCase',
117 'ApplicationDetailTestCase',
118+ 'ApplicationListTestCase',
119 'ApplicationRecommendsTestCase',
120 'ApplicationReviewsTestCase',
121 'ApplicationScreenshotsTestCase',
122@@ -398,6 +402,36 @@
123 self.assertEqual(natty, used.distroseries)
124
125
126+class ApplicationListTestCase(TestCaseWithFactory):
127+ def test_no_args_redirects_to_index(self):
128+ response = self.client.get(reverse('wc-package-list'))
129+
130+ self.assertRedirects(response, reverse('wc-index'))
131+
132+ def test_includes_apps_for_pkg_names(self):
133+ apps = [
134+ self.factory.make_application(),
135+ self.factory.make_application(),
136+ self.factory.make_application(),
137+ ]
138+
139+ response = self.client.get(
140+ reverse('wc-package-list') + '?' + "&".join(
141+ ['pkg_name=%s' % app.package_name for app in apps]))
142+
143+ self.assertEqual(200, response.status_code)
144+ self.assertEqual(apps, response.context['applications'])
145+
146+ def test_includes_depts_in_context(self):
147+ depts = Department.objects.filter(parent=None).order_by('name')
148+
149+ response = self.client.get(
150+ reverse('wc-package-list') + '?pkg_name=firefox')
151+
152+ self.assertEqual(200, response.status_code)
153+ self.assertEqual(list(depts), list(response.context['depts']))
154+
155+
156 class SearchTestCase(TestCaseWithFactory):
157 def setUp(self):
158 super(SearchTestCase, self).setUp()
159
160=== modified file 'src/webcatalog/urls.py'
161--- src/webcatalog/urls.py 2012-04-20 16:57:50 +0000
162+++ src/webcatalog/urls.py 2012-05-08 06:45:21 +0000
163@@ -36,6 +36,7 @@
164 'department_overview', name='wc-department'),
165 url(r'^department/(?P<dept_slug_or_id>[\w\d-]+)/$', 'department_overview',
166 name='wc-department'),
167+ url(r'^applications/$', 'application_list', name='wc-package-list'),
168 url(r'^applications/screenshots/(?P<package_name>[-.+:\w]+)/$',
169 'application_screenshots', name="wc-package-screenshots"),
170 url(r'^applications/(?P<distro>[-.+\w]+)/(?P<package_name>[-.+:\w]+)/$',
171
172=== modified file 'src/webcatalog/views.py'
173--- src/webcatalog/views.py 2012-05-07 08:58:26 +0000
174+++ src/webcatalog/views.py 2012-05-08 06:45:21 +0000
175@@ -159,6 +159,26 @@
176 context_instance=context)
177
178
179+def application_list(request):
180+ pkg_names = request.GET.getlist('pkg_name')
181+ if not pkg_names:
182+ # We have no need of a general paged view of apps here.
183+ return HttpResponseRedirect(reverse('wc-index'))
184+
185+ applications = []
186+ for pkg_name in pkg_names:
187+ latest = Application.objects.find_best(
188+ package_name=pkg_name)
189+ if latest:
190+ applications.append(latest)
191+
192+ depts = Department.objects.filter(parent=None).order_by('name')
193+
194+ return render_to_response('webcatalog/application_list.html',
195+ context_instance=RequestContext(request,
196+ dict(applications=applications, depts=depts)))
197+
198+
199 def application_detail(request, package_name, distro=None):
200 if distro is None:
201 app = Application.objects.find_best_or_404(package_name=package_name)

Subscribers

People subscribed via source and target branches