Merge lp:~canonical-ca-hackers/ubuntu-webcatalog/938223-share-applications into lp:ubuntu-webcatalog

Proposed by Łukasz Czyżykowski
Status: Merged
Approved by: Anthony Lenton
Approved revision: no longer in the source branch.
Merged at revision: 70
Proposed branch: lp:~canonical-ca-hackers/ubuntu-webcatalog/938223-share-applications
Merge into: lp:ubuntu-webcatalog
Diff against target: 219 lines (+95/-19)
7 files modified
src/webcatalog/static/css/webcatalog.css (+20/-6)
src/webcatalog/templates/webcatalog/application_detail.html (+22/-12)
src/webcatalog/templates/webcatalog/facebook_share_snippet.html (+10/-0)
src/webcatalog/templates/webcatalog/googleplus_share_snippet.html (+8/-0)
src/webcatalog/templates/webcatalog/twitter_share_snippet.html (+2/-0)
src/webcatalog/tests/test_views.py (+31/-1)
src/webcatalog/views.py (+2/-0)
To merge this branch: bzr merge lp:~canonical-ca-hackers/ubuntu-webcatalog/938223-share-applications
Reviewer Review Type Date Requested Status
Anthony Lenton Pending
Review via email: mp+96607@code.launchpad.net

Commit message

Added sharing to Twitter, Google Plus and Facebook.

Description of the change

Overview
========
This branch adds three "Share" buttons to application_detail page. Those are Twitter, Facebbok and Google +1.

Details
=======
I wasn't able to figure out a way of making a mechanism to add a new one easy, as those are quite specific. At least Twitter one is. Other two only require a static html snippet to be added, but still, that's not a single line.

Currently, when running locally, Twitter share will not include an url, because JavaScript Twitter code filters out localhost urls, I guess to prevent flooding it with in-development links.

To post a comment you must log in.
68. By Łukasz Czyżykowski

[r=elachuni] Branch based deployment fabric task.

69. By Danny Tamez

[r=elachuni],[bug=938217] Send a link via email for the user to download the application at a later time.

70. By Łukasz Czyżykowski

[r=elachuni],[bug=938223] Added sharing to Twitter, Google Plus and Facebook.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/webcatalog/static/css/webcatalog.css'
2--- src/webcatalog/static/css/webcatalog.css 2012-03-08 18:13:11 +0000
3+++ src/webcatalog/static/css/webcatalog.css 2012-03-08 20:31:18 +0000
4@@ -38,6 +38,9 @@
5 .license th {
6 width: 50px;
7 }
8+.share {
9+ padding: 16px;
10+}
11 .description {
12 padding: 42px 16px;
13 font-size: 14px;
14@@ -330,8 +333,9 @@
15 }
16
17 #sendButton {
18- margin-left: 127px;
19+ margin-left: 107px;
20 margin-bottom: 3px;
21+ width: 80px;
22 }
23 form ul {
24 list-style: none;
25@@ -349,14 +353,24 @@
26 p.error {
27 background-color: #f2cfce;
28 }
29-#emailcontainer {
30- padding-top: 8px;
31- padding-left: 9px;
32-}
33+.emaillinkportlet {
34+ margin-top: 64px;
35+ border-bottom: 1px dotted gray;
36+}
37+
38+.emaillinkportlet .portletheader{
39+ background: #bbb;
40+ margin-bottom: 8px;
41+}
42+
43 #emailForm label {
44- display: block;
45+ display: inline;
46 padding-bottom: 3px;
47 }
48+#emailForm input#id_email {
49+ width: 120px;
50+}
51+
52 .message {
53 -moz-border-radius: 4px;
54 -webkit-border-radius: 4px;
55
56=== modified file 'src/webcatalog/templates/webcatalog/application_detail.html'
57--- src/webcatalog/templates/webcatalog/application_detail.html 2012-03-08 18:13:11 +0000
58+++ src/webcatalog/templates/webcatalog/application_detail.html 2012-03-08 20:31:18 +0000
59@@ -21,6 +21,13 @@
60 Y.io(uri);
61 });
62 </script>
63+<meta property="og:site_name" content="Ubuntu Apps Directory" />
64+<meta property="og:title" content="{{ application.name }}" />
65+{% if application.icon %}
66+ <meta property="og:image" content="{{ application.icon.url }}" />
67+{% else %}
68+ <meta property="og:image" content="{{ STATIC_URL }}images/applications-other-64.png" />
69+{% endif %}
70 {% endblock %}
71
72 {% block content %}
73@@ -42,20 +49,18 @@
74 <a href="{% url wc-package-detail ds.code_name application.package_name %}">Ubuntu {{ ds.version }} ({{ ds.code_name }})</a>
75 {% endifequal %}</li>
76 {% endfor %}
77- <li>
78- <div id='emailcontainer'>
79- <div id='emailtext'>Email me a link to download</div>
80- <div id='emailForm'>
81- <form action="." method="post" accept-charset="utf-8">
82- {% csrf_token %}
83- {{ email_form.as_p }}
84- <button type='submit' id='sendButton' class='install-butotn'>Send it</button>
85- </form>
86- </div>
87- </div>
88- </li>
89 </ul>
90 </div>
91+ <div class="portlet emaillinkportlet">
92+ <div class="portletheader">Email me a link to download</div>
93+ <div id='emailForm'>
94+ <form action="." method="post" accept-charset="utf-8">
95+ {% csrf_token %}
96+ {{ email_form.as_p }}
97+ <button type='submit' id='sendButton' class='install-butotn'>Send it</button>
98+ </form>
99+ </div>
100+ </div>
101 </div>
102 <div id="sc-mockup">
103 <div class="header">
104@@ -91,6 +96,11 @@
105 </tr>
106 </table>
107 </div>
108+ <div class="share">
109+ {% include "webcatalog/twitter_share_snippet.html" %}
110+ {% include "webcatalog/googleplus_share_snippet.html" %}
111+ {% include "webcatalog/facebook_share_snippet.html" %}
112+ </div>
113 <div class="reviews">
114 <h2>{% trans "Reviews" %}</h2>
115 <div id="reviews_placeholder">
116
117=== added file 'src/webcatalog/templates/webcatalog/facebook_share_snippet.html'
118--- src/webcatalog/templates/webcatalog/facebook_share_snippet.html 1970-01-01 00:00:00 +0000
119+++ src/webcatalog/templates/webcatalog/facebook_share_snippet.html 2012-03-08 20:31:18 +0000
120@@ -0,0 +1,10 @@
121+<div class="fb-like" data-send="true" data-width="400" data-show-faces="false"></div>
122+
123+<div id="fb-root"></div>
124+<script>(function(d, s, id) {
125+ var js, fjs = d.getElementsByTagName(s)[0];
126+ if (d.getElementById(id)) return;
127+ js = d.createElement(s); js.id = id;
128+ js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
129+ fjs.parentNode.insertBefore(js, fjs);
130+}(document, 'script', 'facebook-jssdk'));</script>
131
132=== added file 'src/webcatalog/templates/webcatalog/googleplus_share_snippet.html'
133--- src/webcatalog/templates/webcatalog/googleplus_share_snippet.html 1970-01-01 00:00:00 +0000
134+++ src/webcatalog/templates/webcatalog/googleplus_share_snippet.html 2012-03-08 20:31:18 +0000
135@@ -0,0 +1,8 @@
136+<g:plusone size="medium"></g:plusone>
137+<script type="text/javascript">
138+ (function() {
139+ var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
140+ po.src = 'https://apis.google.com/js/plusone.js';
141+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
142+ })();
143+</script>
144
145=== added file 'src/webcatalog/templates/webcatalog/twitter_share_snippet.html'
146--- src/webcatalog/templates/webcatalog/twitter_share_snippet.html 1970-01-01 00:00:00 +0000
147+++ src/webcatalog/templates/webcatalog/twitter_share_snippet.html 2012-03-08 20:31:18 +0000
148@@ -0,0 +1,2 @@
149+<a href="https://twitter.com/share" class="twitter-share-button" data-text="Check out {{ application.name }} in Ubuntu Apps Directory" data-hashtags="ubuntu" data-url="{{ absolute_url }}">Tweet</a>
150+<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
151
152=== modified file 'src/webcatalog/tests/test_views.py'
153--- src/webcatalog/tests/test_views.py 2012-03-08 18:13:11 +0000
154+++ src/webcatalog/tests/test_views.py 2012-03-08 20:31:18 +0000
155@@ -22,6 +22,8 @@
156 with_statement,
157 )
158
159+import re
160+
161 from decimal import Decimal
162
163 from django.conf import settings
164@@ -133,7 +135,7 @@
165 response, app = self.get_app_and_response()
166
167 self.assertContains(response, 'Install %s' % app.name)
168- self.assertNotContains(response, 'Purcchase %s' % app.name)
169+ self.assertNotContains(response, 'Purchase %s' % app.name)
170
171 def test_button_for_for_puchase_app(self):
172 response, app = self.get_app_and_response(for_purchase=True)
173@@ -141,6 +143,34 @@
174 self.assertContains(response, 'Purchase %s' % app.name)
175 self.assertNotContains(response, 'Install %s' % app.name)
176
177+ def test_open_graph_tags_are_present(self):
178+ response, app = self.get_app_and_response()
179+ regex = r'<meta property="([^"]+)" content="([^"]+)" />'
180+ og_tags = dict(m for m in re.findall(regex, response.content)
181+ if 'og:' in m[0])
182+
183+ self.assertEqual(og_tags, {
184+ 'og:site_name': "Ubuntu Apps Directory",
185+ 'og:title': app.name,
186+ 'og:image': '/assets/images/applications-other-64.png'
187+ })
188+
189+ def test_twitter_button_is_present(self):
190+ response, app = self.get_app_and_response()
191+
192+ self.assertContains(response, "Tweet</a>")
193+ self.assertContains(response, "https://twitter.com/share")
194+
195+ def test_google_plus_button_is_present(self):
196+ response, app = self.get_app_and_response()
197+
198+ self.assertContains(response, "<g:plusone")
199+
200+ def test_facebook_like_button_is_present(self):
201+ response, app = self.get_app_and_response()
202+
203+ self.assertContains(response, '<div class="fb-like"')
204+
205 def test_link_to_different_series(self):
206 # If the users series is different from the app, but the app is
207 # available for their series, then we display a link to the app
208
209=== modified file 'src/webcatalog/views.py'
210--- src/webcatalog/views.py 2012-03-07 22:57:41 +0000
211+++ src/webcatalog/views.py 2012-03-08 20:31:18 +0000
212@@ -213,6 +213,8 @@
213 'available_distroseries': app.available_distroseries(),
214 'breadcrumbs': app.crumbs(),
215 'distroseries': distro,
216+ 'absolute_url': request.build_absolute_uri(
217+ reverse('wc-package-detail', args=[distro, package_name])),
218 'email_form': form,
219 }
220

Subscribers

People subscribed via source and target branches