mirror of
https://github.com/fergalmoran/dss.git
synced 2025-12-22 09:38:18 +00:00
Added redirect for FB like
This commit is contained in:
0
_working/create
Executable file → Normal file
0
_working/create
Executable file → Normal file
@@ -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': (
|
||||
|
||||
41
spa/social.py
Normal file
41
spa/social.py
Normal file
@@ -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<mix_id>\d+)/$', 'spa.social.redirect_mix', name='social_redirect'),
|
||||
#url(r'^redirect/mix/(?P<mix_id>\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
|
||||
@@ -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<template_name>\w+)/$', 'spa.templates.get_template'),
|
||||
url(r'^tplex/(?P<template_name>\w+)/$', 'spa.templates.get_template_ex'),
|
||||
(r'^social/', include(social.urls)),
|
||||
(r'^ajax/', include(ajax.urls)),
|
||||
(r'^api/', include(v1_api.urls)),
|
||||
)
|
||||
15
spa/views.py
15
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.
|
||||
<meta property="fb:app_id" content="154504534677009" />
|
||||
<meta property="og:type" content="deepsouthsounds:mix" />
|
||||
<meta property="og:title" content="June 2012" />
|
||||
<meta property="og:image" content="http://www-test.deepsouthsounds.com:8000/static/img/site-logo-gr.png" />
|
||||
"""
|
||||
|
||||
return response
|
||||
|
||||
0
static/bin/sm/soundmanager2.swf
Executable file → Normal file
0
static/bin/sm/soundmanager2.swf
Executable file → Normal file
0
static/bin/sm/soundmanager2_debug.swf
Executable file → Normal file
0
static/bin/sm/soundmanager2_debug.swf
Executable file → Normal file
0
static/bin/sm/soundmanager2_flash9.swf
Executable file → Normal file
0
static/bin/sm/soundmanager2_flash9.swf
Executable file → Normal file
0
static/bin/sm/soundmanager2_flash9_debug.swf
Executable file → Normal file
0
static/bin/sm/soundmanager2_flash9_debug.swf
Executable file → Normal file
0
static/bin/sm/soundmanager2_flash_xdomain.zip
Executable file → Normal file
0
static/bin/sm/soundmanager2_flash_xdomain.zip
Executable file → Normal file
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
})();
|
||||
})();
|
||||
|
||||
function setOrCreateMetaTag(metaName, name, value) {
|
||||
var t = 'meta['+metaName+'='+name+']';
|
||||
var mt = $(t);
|
||||
if (mt.length === 0) {
|
||||
t = '<meta '+metaName+'="'+name+'" />';
|
||||
mt = $(t).appendTo('head');
|
||||
}
|
||||
mt.attr('content', value);
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
});
|
||||
14
templates/inc/fb_like.html
Normal file
14
templates/inc/fb_like.html
Normal file
@@ -0,0 +1,14 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta property="fb:app_id" content="{{ app_id }}" />
|
||||
<meta property="og:type" content="deepsouthsounds:mix" />
|
||||
<meta property="og:title" content="{{ description }}" />
|
||||
<meta property="og:image" content="{{ image_url }}" />
|
||||
<script type="text/javascript">
|
||||
window.location = '{{ redirect }}'
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user