mirror of
https://github.com/fergalmoran/dss.git
synced 2026-03-25 15:05:51 +00:00
Fixed user profile update errors
This commit is contained in:
@@ -13,6 +13,7 @@ logger = logging.getLogger('spa')
|
||||
|
||||
|
||||
def post_notification(user, message):
|
||||
pass
|
||||
try:
|
||||
r = redis.StrictRedis(host='localhost', port=6379, db=0)
|
||||
r.publish('realtime', user.username + ': ' + message)
|
||||
|
||||
@@ -47,15 +47,13 @@ class PlaylistResource(BackboneCompatibleResource):
|
||||
return bundle
|
||||
|
||||
def dehydrate(self, bundle):
|
||||
try:
|
||||
bundle.data['playlist_image'] = bundle.obj.mixes.objects.all()[0].get_image_url()
|
||||
except:
|
||||
bundle.data['playlist_image'] = UserProfile.get_default_avatar_image()
|
||||
|
||||
bundle.data['playlist_image'] = bundle.obj.get_image_url()
|
||||
bundle.data['item_url'] = '/playlist/%s' % bundle.obj.slug
|
||||
return bundle
|
||||
|
||||
def obj_update(self, bundle, skip_errors=False, **kwargs):
|
||||
if 'playlist_image' in kwargs: del kwargs['playlist_image']
|
||||
if 'item_url' in kwargs: del kwargs['item_url']
|
||||
mixes = bundle.data['mixes']
|
||||
bundle.data.pop('mixes')
|
||||
result = super(PlaylistResource, self).obj_update(bundle, **kwargs)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
from django.db import models
|
||||
from sorl.thumbnail import get_thumbnail
|
||||
from core.utils.url import unique_slugify
|
||||
from dss import settings
|
||||
from spa.models import BaseModel, UserProfile, Mix
|
||||
|
||||
|
||||
@@ -27,4 +29,18 @@ class Playlist(BaseModel):
|
||||
if not self.id:
|
||||
self.slug = unique_slugify(self, self.name)
|
||||
|
||||
super(Playlist, self).save(force_insert, force_update, using, update_fields)
|
||||
super(Playlist, self).save(force_insert, force_update, using, update_fields)
|
||||
|
||||
def get_image_url(self, size='160x160', default=''):
|
||||
if self.mixes.count() != 0:
|
||||
image = self.mixes.all()[0].get_image_url()
|
||||
try:
|
||||
ret = get_thumbnail(image, size, crop='center')
|
||||
return "%s/%s" % (settings.MEDIA_URL, ret.name)
|
||||
except Exception, ex:
|
||||
pass
|
||||
|
||||
return super(Playlist, self).get_image_url(self.mix_image, settings.STATIC_URL + 'img/default-track.png')
|
||||
|
||||
def get_absolute_url(self):
|
||||
return '/playlist/%s' % self.slug
|
||||
@@ -6,6 +6,7 @@ urlpatterns = patterns(
|
||||
url(r'^redirect/mix/(?P<slug>[\w\d_.-]+)/$', 'spa.social.views.mix', name='social_redirect_mix_slug'),
|
||||
url(r'^mix/(?P<mix_id>\d+)/$', 'spa.social.views.mix', name='social_mix'),
|
||||
url(r'^mix/(?P<slug>[\w\d_.-]+)/$', 'spa.social.views.mix', name='social_mix_slug'),
|
||||
url(r'^playlist/(?P<slug>[\w\d_.-]+)/$', 'spa.social.views.playlist', name='social_playlist_slug'),
|
||||
url(r'^user/(?P<user_id>\w+)/$', 'spa.social.views.user', name='social_user'),
|
||||
url(r'^like/(?P<mix_id>\d+)/$', 'spa.social.views.post_like', name='social_like'),
|
||||
url(r'^$', 'spa.social.views.index', name='social_index')
|
||||
|
||||
@@ -12,6 +12,7 @@ from allauth.socialaccount.models import SocialToken
|
||||
from core.utils.url import wrap_full
|
||||
|
||||
from dss import settings
|
||||
from spa.models import Playlist
|
||||
from spa.models.mix import Mix
|
||||
from spa.models.userprofile import UserProfile
|
||||
|
||||
@@ -22,6 +23,7 @@ logger = logging.getLogger(__name__)
|
||||
Handles callbacks from facebook and twitter
|
||||
"""
|
||||
|
||||
|
||||
def _getPayload(request):
|
||||
return {
|
||||
"app_id": settings.FACEBOOK_APP_ID,
|
||||
@@ -59,6 +61,31 @@ def mix(request, args):
|
||||
return response
|
||||
|
||||
|
||||
def playlist(request, args):
|
||||
try:
|
||||
playlist = Playlist.objects.get(slug=args['slug'])
|
||||
except Playlist.DoesNotExist:
|
||||
raise Http404
|
||||
|
||||
image = playlist.get_image_url('400x400')
|
||||
playlist_url = playlist.get_absolute_url()
|
||||
default = _getPayload(request)
|
||||
extras = {
|
||||
"description": "Deep South Sounds Playlist by %s" % playlist.user.get_nice_name(),
|
||||
"title": playlist.name,
|
||||
"image_url": image,
|
||||
"playlist_url": 'http://%s%s' % (Site.objects.get_current().domain, playlist_url)
|
||||
}
|
||||
payload = dict(default.items() + extras.items())
|
||||
response = render_to_response(
|
||||
'inc/facebook/playlist.html',
|
||||
payload,
|
||||
context_instance=RequestContext(request)
|
||||
)
|
||||
print response.content
|
||||
return response
|
||||
|
||||
|
||||
def user(request, args):
|
||||
try:
|
||||
user = UserProfile.objects.get(slug=args['user_id'])
|
||||
|
||||
@@ -92,18 +92,14 @@
|
||||
id="like-<%= id %>"
|
||||
data-id="<%= id %>">
|
||||
<i class="ace-icon fa fa-heart"></i> Like
|
||||
<% if (liked) { %>
|
||||
d
|
||||
<% } %>
|
||||
<% if (liked) { %>d<% } %>
|
||||
</a>
|
||||
</div>
|
||||
<div class="favourite-button footer-button">
|
||||
<a class="btn <% if (favourited) { %>btn-pink<% } else { %>btn-light<% } %> btn-xs"
|
||||
id="favourite-<%= id %>"
|
||||
data-id="<%= id %>"><i class="ace-icon fa fa-star-empty"></i> Favourite
|
||||
<% if (favourited) { %>
|
||||
d
|
||||
<% } %>
|
||||
<% if (favourited) { %>d<% } %>
|
||||
</a>
|
||||
</div>
|
||||
<% } %>
|
||||
|
||||
17
templates/inc/facebook/playlist.html
Normal file
17
templates/inc/facebook/playlist.html
Normal file
@@ -0,0 +1,17 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:og="http://ogp.me/ns#"
|
||||
xmlns:fb="https://www.facebook.com/2008/fbml">
|
||||
<head>
|
||||
<meta property="fb:app_id" content="{{ app_id }}"/>
|
||||
<meta property="og:url" content="{{ playlist_url }}/"/>
|
||||
|
||||
<meta property="og:site_name" content="Deep South Sounds Playlist"/>
|
||||
<meta property="og:type" content="deepsouthsounds:playlist"/>
|
||||
<meta property="og:title" content="{{ title }}"/>
|
||||
<meta property="og:description" content="{{ description }}"/>
|
||||
<meta property="og:image" content="{{ image_url }}"/>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user