# HG changeset patch # User Brian Neal # Date 1318896277 0 # Node ID bbbc357ac5f3730fc667627116c75d0b278f56c0 # Parent 3ac558402014e784088334aa35e692e08b6b84d0 For #233; first commit for adding social media sharing buttons to news stories. diff -r 3ac558402014 -r bbbc357ac5f3 gpp/bio/forms.py --- a/gpp/bio/forms.py Sat Oct 15 22:04:18 2011 +0000 +++ b/gpp/bio/forms.py Tue Oct 18 00:04:37 2011 +0000 @@ -48,12 +48,12 @@ class Media: css = { - 'all': settings.GPP_THIRD_PARTY_CSS['markitup'] + \ - settings.GPP_THIRD_PARTY_CSS['jquery-ui'] + 'all': (settings.GPP_THIRD_PARTY_CSS['markitup'] + + settings.GPP_THIRD_PARTY_CSS['jquery-ui']) } - js = settings.GPP_THIRD_PARTY_JS['markitup'] + \ - settings.GPP_THIRD_PARTY_JS['jquery-ui'] + \ - ('js/bio.js', 'js/timezone.js') + js = (settings.GPP_THIRD_PARTY_JS['markitup'] + + settings.GPP_THIRD_PARTY_JS['jquery-ui'] + + ['js/bio.js', 'js/timezone.js']) class UploadAvatarForm(forms.Form): diff -r 3ac558402014 -r bbbc357ac5f3 gpp/comments/forms.py --- a/gpp/comments/forms.py Sat Oct 15 22:04:18 2011 +0000 +++ b/gpp/comments/forms.py Tue Oct 18 00:04:37 2011 +0000 @@ -71,4 +71,4 @@ } js = (settings.GPP_THIRD_PARTY_JS['markitup'] + settings.GPP_THIRD_PARTY_JS['jquery-ui'] + - ('js/comments.js', )) + ['js/comments.js']) diff -r 3ac558402014 -r bbbc357ac5f3 gpp/core/templatetags/core_tags.py --- a/gpp/core/templatetags/core_tags.py Sat Oct 15 22:04:18 2011 +0000 +++ b/gpp/core/templatetags/core_tags.py Tue Oct 18 00:04:37 2011 +0000 @@ -8,6 +8,7 @@ from django import template from django.conf import settings from django.core.cache import cache +from django.contrib.sites.models import Site import repoze.timeago @@ -50,6 +51,39 @@ } +@register.inclusion_tag('core/social_sharing_tag.html') +def social_sharing(title, url): + """ + Displays social media sharing buttons. + + """ + if url.startswith('/'): + url = 'http://%s%s' % (Site.objects.get_current().domain, url) + + return { + 'title': title, + 'url': url, + } + + +@register.inclusion_tag('core/open_graph_meta_tag.html') +def open_graph_meta_tags(item): + """ + Generates Open Graph meta tags by interrogating the given item. + + """ + site = Site.objects.get_current() + + props = item.ogp_tags() + props['og:site_name'] = site.name + props['fb:admins'] = settings.OGP_FB_ID + + if 'og:image' not in props: + props['og:image'] = settings.OGP_DEFAULT_IMAGE + + return {'props': props} + + # A somewhat ugly hack until we decide if we should be using UTC time # everywhere or not. repoze.timeago._NOW = datetime.datetime.now diff -r 3ac558402014 -r bbbc357ac5f3 gpp/forums/forms.py --- a/gpp/forums/forms.py Sat Oct 15 22:04:18 2011 +0000 +++ b/gpp/forums/forms.py Tue Oct 18 00:04:37 2011 +0000 @@ -28,7 +28,7 @@ } js = (settings.GPP_THIRD_PARTY_JS['markitup'] + settings.GPP_THIRD_PARTY_JS['jquery-ui'] + - ('js/forums.js', )) + ['js/forums.js']) def __init__(self, *args, **kwargs): super(NewPostForm, self).__init__(*args, **kwargs) @@ -82,7 +82,7 @@ } js = (settings.GPP_THIRD_PARTY_JS['markitup'] + settings.GPP_THIRD_PARTY_JS['jquery-ui'] + - ('js/forums.js', )) + ['js/forums.js']) def __init__(self, user, forum, *args, **kwargs): super(NewTopicForm, self).__init__(*args, **kwargs) @@ -159,7 +159,7 @@ } js = (settings.GPP_THIRD_PARTY_JS['markitup'] + settings.GPP_THIRD_PARTY_JS['jquery-ui'] + - ('js/forums.js', )) + ['js/forums.js']) def __init__(self, *args, **kwargs): topic_name = kwargs.pop('topic_name', None) diff -r 3ac558402014 -r bbbc357ac5f3 gpp/gcalendar/forms.py --- a/gpp/gcalendar/forms.py Sat Oct 15 22:04:18 2011 +0000 +++ b/gpp/gcalendar/forms.py Tue Oct 18 00:04:37 2011 +0000 @@ -86,11 +86,11 @@ css = { 'all': (settings.GPP_THIRD_PARTY_CSS['markitup'] + settings.GPP_THIRD_PARTY_CSS['jquery-ui'] + - ('css/gcalendar.css', )) + ['css/gcalendar.css']) } js = (settings.GPP_THIRD_PARTY_JS['markitup'] + settings.GPP_THIRD_PARTY_JS['jquery-ui'] + - ('js/timezone.js', 'js/gcalendar.js', )) + ['js/timezone.js', 'js/gcalendar.js']) def __init__(self, *args, **kwargs): initial = kwargs.get('initial', {}) diff -r 3ac558402014 -r bbbc357ac5f3 gpp/news/models.py --- a/gpp/news/models.py Sat Oct 15 22:04:18 2011 +0000 +++ b/gpp/news/models.py Tue Oct 18 00:04:37 2011 +0000 @@ -98,3 +98,16 @@ def search_summary(self): return u"\n".join((self.short_text, self.long_text)) + + def ogp_tags(self): + """ + Returns a dict of Open Graph Protocol meta tags. + + """ + return { + 'og:title': self.title, + 'og:type': 'article', + 'og:url': self.get_absolute_url(), + 'og:image': self.category.icon.url, + 'og:description': self.title, + } diff -r 3ac558402014 -r bbbc357ac5f3 gpp/settings.py --- a/gpp/settings.py Sat Oct 15 22:04:18 2011 +0000 +++ b/gpp/settings.py Tue Oct 18 00:04:37 2011 +0000 @@ -289,35 +289,45 @@ QUEUE_REDIS_DB = 0 ####################################################################### +# Open Graph Protocol related settings +####################################################################### +OGP_DEFAULT_IMAGE = 'http://surfguitar101.com/media/podcast/podcast_logo.jpg' +OGP_FB_ID = '100001558124013' + +####################################################################### # URL's of 3rd party Javascript and CSS files. # These dictionaries are used by core/templatetags/script_tags, and # should also be used by developers when creating form media classes. GPP_THIRD_PARTY_JS = { - 'jquery': ( + 'jquery': [ 'http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js', - ), - 'jquery-jeditable': ( + ], + 'jquery-jeditable': [ 'js/jquery.jeditable.mini.js', - ), - 'jquery-ui': ( + ], + 'jquery-ui': [ 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js', - ), - 'markitup': ( + ], + 'markitup': [ 'js/markitup/jquery.markitup.pack.js', 'js/markitup/sets/markdown/set.js', - ), - 'tiny_mce': ( + ], + 'tiny_mce': [ 'js/tiny_mce/tiny_mce.js', 'js/tiny_mce_init_std.js', - ), + ], + 'social': [ + 'http://platform.twitter.com/widgets.js', + 'https://apis.google.com/js/plusone.js', + ], } GPP_THIRD_PARTY_CSS = { - 'jquery-ui': ( + 'jquery-ui': [ 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/themes/redmond/jquery-ui.css', - ), - 'markitup': ( + ], + 'markitup': [ 'js/markitup/skins/markitup/style.css', 'js/markitup/sets/markdown/style.css', - ), + ], } diff -r 3ac558402014 -r bbbc357ac5f3 gpp/templates/base.html --- a/gpp/templates/base.html Sat Oct 15 22:04:18 2011 +0000 +++ b/gpp/templates/base.html Tue Oct 18 00:04:37 2011 +0000 @@ -1,7 +1,10 @@ - + {% load url from future %} {% load shoutbox_tags %} {% load irc_tags %} @@ -17,6 +20,7 @@ +{% block custom_meta %}{% endblock %}