From 72b4611695c6a254f1f83ddb6d2c37c83e902abb Mon Sep 17 00:00:00 2001 From: "fergal.moran" Date: Thu, 16 Aug 2012 16:10:58 +0100 Subject: [PATCH] Added redirect for FB like --- _working/create | 0 dss/settings.py | 6 +-- spa/social.py | 41 ++++++++++++++++++ spa/urls.py | 4 +- spa/views.py | 15 +++++-- static/bin/sm/soundmanager2.swf | Bin static/bin/sm/soundmanager2_debug.swf | Bin static/bin/sm/soundmanager2_flash9.swf | Bin static/bin/sm/soundmanager2_flash9_debug.swf | Bin static/bin/sm/soundmanager2_flash_xdomain.zip | Bin static/js/app/app.js | 25 ++++++----- static/js/app/utils.js | 23 +++++++++- static/js/app/views/mix.js | 16 ++----- templates/inc/fb_like.html | 14 ++++++ 14 files changed, 111 insertions(+), 33 deletions(-) mode change 100755 => 100644 _working/create create mode 100644 spa/social.py mode change 100755 => 100644 static/bin/sm/soundmanager2.swf mode change 100755 => 100644 static/bin/sm/soundmanager2_debug.swf mode change 100755 => 100644 static/bin/sm/soundmanager2_flash9.swf mode change 100755 => 100644 static/bin/sm/soundmanager2_flash9_debug.swf mode change 100755 => 100644 static/bin/sm/soundmanager2_flash_xdomain.zip create mode 100644 templates/inc/fb_like.html diff --git a/_working/create b/_working/create old mode 100755 new mode 100644 diff --git a/dss/settings.py b/dss/settings.py index 473ef5c..1c74209 100644 --- a/dss/settings.py +++ b/dss/settings.py @@ -109,7 +109,7 @@ MIDDLEWARE_CLASSES = ( 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.gzip.GZipMiddleware', - 'pipeline.middleware.MinifyHTMLMiddleware' + #'pipeline.middleware.MinifyHTMLMiddleware' ) WSGI_APPLICATION = 'dss.wsgi.application' @@ -128,7 +128,7 @@ INSTALLED_APPS = ( 'django_facebook', 'djcelery', 'crispy_forms', - 'pipeline', + #'pipeline', 'avatar', 'notification', 'spa', @@ -195,7 +195,7 @@ DSS_TEMP_PATH = localsettings.DSS_TEMP_PATH DSS_LAME_PATH = localsettings.DSS_LAME_PATH DSS_WAVE_PATH = localsettings.DSS_WAVE_PATH PIPELINE_YUI_BINARY = localsettings.PIPELINE_YUI_BINARY -PIPELINE = True +PIPELINE = False PIPELINE_CSS = { 'defaults': { 'source_filenames': ( diff --git a/spa/social.py b/spa/social.py new file mode 100644 index 0000000..5aedc0f --- /dev/null +++ b/spa/social.py @@ -0,0 +1,41 @@ +from django.conf.urls import url +from django.contrib.sites.models import Site +from django.core.serializers import json +from django.http import HttpResponse, Http404 +from django.shortcuts import render_to_response +from django.template.context import RequestContext +from dss import localsettings, settings +from spa.models.Mix import Mix + +class SocialHandler(object): + import logging + logger = logging.getLogger(__name__) + + def __init__(self, api_name="v1"): + self.api_name = api_name + + @property + def urls(self): + pattern_list = [ + url(r'^redirect/mix/(?P\d+)/$', 'spa.social.redirect_mix', name='social_redirect'), + #url(r'^redirect/mix/(?P\d+)/$', 'spa.social.redirect_mix', name='social_redirect-mix'), + ] + return pattern_list + + +def redirect_mix(request, mix_id): + try: + mix = Mix.objects.get(pk=mix_id) + except Mix.DoesNotExist: + raise Http404 + response = render_to_response( + 'inc/fb_like.html', + { + "app_id" : settings.FACEBOOK_APP_ID, + "description" : mix.title, + "image_url" : 'http://%s:%s%s' % (Site.objects.get_current().domain, request.META['SERVER_PORT'], mix.get_image()), + "redirect" : 'http://%s:%s#%s' % (Site.objects.get_current().domain, request.META['SERVER_PORT'], mix.get_absolute_url()) + }, + context_instance = RequestContext(request) + ) + return response diff --git a/spa/urls.py b/spa/urls.py index fb040e5..bb7f175 100644 --- a/spa/urls.py +++ b/spa/urls.py @@ -7,8 +7,8 @@ from spa.api.v1.EventResource import EventResource from spa.api.v1.MixResource import MixResource from spa.api.v1.ReleaseAudioResource import ReleaseAudioResource from spa.api.v1.ReleaseResource import ReleaseResource -import spa from spa.api.v1.UserResource import UserResource +from spa.social import SocialHandler v1_api = Api(api_name='v1') v1_api.register(MixResource()) @@ -18,12 +18,14 @@ v1_api.register(ReleaseAudioResource()) v1_api.register(EventResource()) v1_api.register(UserResource()) ajax = AjaxHandler() +social = SocialHandler() urlpatterns = django.conf.urls.patterns( '', url(r'^$', 'spa.views.app', name='home'), url(r'^tpl/(?P\w+)/$', 'spa.templates.get_template'), url(r'^tplex/(?P\w+)/$', 'spa.templates.get_template_ex'), + (r'^social/', include(social.urls)), (r'^ajax/', include(ajax.urls)), (r'^api/', include(v1_api.urls)), ) \ No newline at end of file diff --git a/spa/views.py b/spa/views.py index 99e1742..efcfd66 100644 --- a/spa/views.py +++ b/spa/views.py @@ -1,5 +1,14 @@ -from core.decorators import render_template +from django.shortcuts import render_to_response +from django.template.context import RequestContext -@render_template def app(request): - return "inc/app.html" + response = render_to_response("inc/app.html", context_instance=RequestContext(request)) + """ + set the fb headers, for now just do it on every response. + + + + + """ + + return response diff --git a/static/bin/sm/soundmanager2.swf b/static/bin/sm/soundmanager2.swf old mode 100755 new mode 100644 diff --git a/static/bin/sm/soundmanager2_debug.swf b/static/bin/sm/soundmanager2_debug.swf old mode 100755 new mode 100644 diff --git a/static/bin/sm/soundmanager2_flash9.swf b/static/bin/sm/soundmanager2_flash9.swf old mode 100755 new mode 100644 diff --git a/static/bin/sm/soundmanager2_flash9_debug.swf b/static/bin/sm/soundmanager2_flash9_debug.swf old mode 100755 new mode 100644 diff --git a/static/bin/sm/soundmanager2_flash_xdomain.zip b/static/bin/sm/soundmanager2_flash_xdomain.zip old mode 100755 new mode 100644 diff --git a/static/js/app/app.js b/static/js/app/app.js index 9eb5e89..d864e7b 100644 --- a/static/js/app/app.js +++ b/static/js/app/app.js @@ -39,18 +39,19 @@ var AppRouter = Backbone.Router.extend({ }, mixDetails:function (id) { var mix = new Mix({id:id}); - mix.fetch({success:function () { - var html = new MixView({model:mix}); - $('#content').html(html.el); - $('#site-content-fill').html(''); - var comments = new CommentCollection(); - comments.url = window.appSettings.urlRoot + mix.attributes.item_url + "/comments/"; - comments.mix_id = id; - comments.mix = mix.get("resource_uri"); - comments.fetch({success:function (data) { - var content = new CommentListView({collection:comments}).render(); - $('#site-content-fill').html(content.el); - }}); + mix.fetch({ + success:function () { + var html = new MixView({model:mix}); + $('#content').html(html.el); + $('#site-content-fill').html(''); + var comments = new CommentCollection(); + comments.url = window.appSettings.urlRoot + mix.attributes.item_url + "/comments/"; + comments.mix_id = id; + comments.mix = mix.get("resource_uri"); + comments.fetch({success:function (data) { + var content = new CommentListView({collection:comments}).render(); + $('#site-content-fill').html(content.el); + }}); }}); }, releaseList:function (page) { diff --git a/static/js/app/utils.js b/static/js/app/utils.js index d9004a8..83355f3 100644 --- a/static/js/app/utils.js +++ b/static/js/app/utils.js @@ -77,6 +77,9 @@ window.utils = { $('.alert').hide(); } }; +setHashbangHeader = function (xhr) { + xhr.setRequestHeader('X-FB-Nonsense', 'Argle-Bargle'); +} window.TastypieModel = Backbone.Model.extend({ base_url:function () { @@ -85,7 +88,13 @@ window.TastypieModel = Backbone.Model.extend({ }, url:function () { return this.base_url(); - } + }/*, + fetch:function(){ + return Backbone.Model.prototype.fetch.call( + this, + {beforeSync: setHashbangHeader} + ); + }*/ }); window.TastypieCollection = Backbone.Collection.extend({ @@ -100,4 +109,14 @@ window.TastypieCollection = Backbone.Collection.extend({ window.alert = function () { return proxied.apply(this, arguments); }; -})(); \ No newline at end of file +})(); + +function setOrCreateMetaTag(metaName, name, value) { + var t = 'meta['+metaName+'='+name+']'; + var mt = $(t); + if (mt.length === 0) { + t = ''; + mt = $(t).appendTo('head'); + } + mt.attr('content', value); +} \ No newline at end of file diff --git a/static/js/app/views/mix.js b/static/js/app/views/mix.js index dc37eca..6375ea4 100644 --- a/static/js/app/views/mix.js +++ b/static/js/app/views/mix.js @@ -26,19 +26,8 @@ window.MixListItemView = Backbone.View.extend({ function (data) { } ); - var data = { - 'name':'Deep South Sounds', - 'description':'This is a test of the Deep South Sounds Broadcast System. If this was real, you would be reading something useful.', - 'media':[ - { - 'type':'image', - 'src':'http://deepsouthsounds.com/images/facebook_image.png', - 'href':'http://www.deepsouthsounds.com/#/mixes/1/' - } - ] - }; var body = 'This is a test of the Deep South Sounds Broadcast System. If this was real, you would be reading something useful'; - FB.api('/me/deepsouthsounds:like', 'post', { mix: 'http://www.deepsouthsounds.com/static/html/fb_mix.html' }, function (response) { + FB.api('/me/deepsouthsounds:like', 'post', { mix: 'http://' + window.location.host + '/social/redirect/mix/' + id}, function (response) { if (!response || response.error) { alert('Error occured: ' + response.error.message); } else { @@ -104,6 +93,9 @@ window.MixView = Backbone.View.extend({ var item = new MixListItemView({model:this.model}).render(); $('.mix-listing', this.el).append(item.el); $('#mix-description', this.el).html(this.model.get("description")); + + //set meta tags for facebook + //setOrCreateMetaTag('property', 'fb:app_id', '154504534677009'); return this; } }); \ No newline at end of file diff --git a/templates/inc/fb_like.html b/templates/inc/fb_like.html new file mode 100644 index 0000000..6d5177e --- /dev/null +++ b/templates/inc/fb_like.html @@ -0,0 +1,14 @@ + + + + + + + + + + + + \ No newline at end of file