changeset 491:7dbdbb08e68c

For #233; add social media sharing buttons to the photo of the day app.
author Brian Neal <bgneal@gmail.com>
date Thu, 20 Oct 2011 01:00:19 +0000
parents f0f3966ea44f
children 3c48a555298d
files gpp/potd/models.py gpp/templates/core/social_sharing_begin.html gpp/templates/potd/view.html
diffstat 3 files changed, 23 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/gpp/potd/models.py	Thu Oct 20 00:36:37 2011 +0000
+++ b/gpp/potd/models.py	Thu Oct 20 01:00:19 2011 +0000
@@ -73,6 +73,20 @@
         thumb_name = os.path.basename(self.photo.path)
         self.thumb.save(thumb_name, ContentFile(s.getvalue()), save=False)
 
+    def ogp_tags(self):
+        """
+        Returns a dict of Open Graph Protocol meta tags.
+
+        """
+        desc = "Photo of the day: %s." % self.caption
+        return {
+            'og:title': self.caption,
+            'og:type': 'article',
+            'og:url': self.get_absolute_url(),
+            'og:image': self.photo.url,
+            'og:description': desc,
+        }
+
 
 class CurrentManager(models.Manager):
     def get_current_photo(self):
--- a/gpp/templates/core/social_sharing_begin.html	Thu Oct 20 00:36:37 2011 +0000
+++ b/gpp/templates/core/social_sharing_begin.html	Thu Oct 20 01:00:19 2011 +0000
@@ -1,5 +1,5 @@
 <div id="fb-root"></div>
-<script>(function(d, s, id) {
+<script type="text/javascript">(function(d, s, id) {
   var js, fjs = d.getElementsByTagName(s)[0];
   if (d.getElementById(id)) {return;}
   js = d.createElement(s); js.id = id; js.async = true;
--- a/gpp/templates/potd/view.html	Thu Oct 20 00:36:37 2011 +0000
+++ b/gpp/templates/potd/view.html	Thu Oct 20 01:00:19 2011 +0000
@@ -1,8 +1,12 @@
 {% extends 'base.html' %}
 {% load url from future %}
+{% load core_tags %}
 {% load comment_tags %}
 {% load script_tags %}
 {% block title %}Photo Of The Day{% endblock %}
+{% block custom_meta %}
+{% open_graph_meta_tags potd %}
+{% endblock %}
 {% block custom_css %}
 <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/potd.css" />
 <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/comments.css" />
@@ -11,6 +15,7 @@
 {% script_tags "markitup jquery-ui" %}
 <script type="text/javascript" src="{{ STATIC_URL }}js/comments.js"></script>
 {% endblock %}
+{% block begin_body %}{% include 'core/social_sharing_begin.html' %}{% endblock %}
 {% block content %}
 {% if is_current %}
 <h2>Photo Of The Day</h2>
@@ -28,11 +33,12 @@
 on {{ potd.date_added|date:"d F Y" }}.<br />
 This photo has been Photo of the Day {{ potd.potd_count }} time{{ potd.potd_count|pluralize }}.
 </p>
-<p class="description">{{ potd.description|safe }}</p>
+<div class="description">{{ potd.description|safe }}</div>
 <p class="details">
 If you would like us to feature your photo, send it along with your username, a title, and 
 short description to <a href="mailto:admin@surfguitar101.com">admin@surfguitar101.com</a>.
 </p>
+{% social_sharing potd.caption potd.get_absolute_url %}
 {% get_comment_count for potd as comment_count %}
 <p>This photo has <span id="comment-count">{{ comment_count }}</span> comment{{ comment_count|pluralize }}.</p>
 <hr />
@@ -50,3 +56,4 @@
 <p>We're sorry, there doesn't seem to be a photo of the day right now.</p>
 {% endif %}
 {% endblock %}
+{% block end_body %}{% include 'core/social_sharing_end.html' %}{% endblock %}