diff --git a/spa/ajax.py b/spa/ajax.py index 0d87ab0..050171f 100644 --- a/spa/ajax.py +++ b/spa/ajax.py @@ -64,6 +64,7 @@ def get_mix_stream_url(request, mix_id): data = { 'stream_url': mix.get_stream_path(), 'description': mix.description, + 'item_url': mix.get_absolute_url(), 'title': mix.title } return HttpResponse(json.dumps(data), mimetype="application/json") diff --git a/spa/api/v1/UserResource.py b/spa/api/v1/UserResource.py index 4f12fb7..71a4468 100644 --- a/spa/api/v1/UserResource.py +++ b/spa/api/v1/UserResource.py @@ -1,5 +1,7 @@ from django.conf.urls import url +from tastypie.authentication import Authentication from tastypie.authorization import Authorization +from tastypie.constants import ALL_WITH_RELATIONS from spa.api.v1.BackboneCompatibleResource import BackboneCompatibleResource from spa.models import UserProfile @@ -7,6 +9,11 @@ class UserResource(BackboneCompatibleResource): class Meta: queryset = UserProfile.objects.all() authorization = Authorization() + authentication = Authentication() + always_return_data = True + filtering = { + 'user': ALL_WITH_RELATIONS, + } def dehydrate(self, bundle): bundle.data['display_name'] = bundle.obj.display_name @@ -15,7 +22,6 @@ class UserResource(BackboneCompatibleResource): bundle.data['email'] = bundle.obj.email return bundle - def override_urls(self): - return [ - url(r"^(?P%s)/(?P[\w\d_.-]+)/$" % self._meta.resource_name, self.wrap_view('dispatch_detail'), name="api_dispatch_detail"), - ] \ No newline at end of file + def apply_authorization_limits(self, request, object_list): + if request.user is not None: + return object_list.filter(user=request.user) \ No newline at end of file diff --git a/spa/models/UserProfile.py b/spa/models/UserProfile.py index 68e7155..d1f9662 100644 --- a/spa/models/UserProfile.py +++ b/spa/models/UserProfile.py @@ -62,4 +62,7 @@ class UserProfile(_BaseModel): elif avatar_type == 'custom' or avatar_type: return self.avatar_image.url - return urlparse.urljoin(settings.STATIC_URL, "img/default-avatar-32.png") \ No newline at end of file + return urlparse.urljoin(settings.STATIC_URL, "img/default-avatar-32.png") + + def save(self, force_insert=False, force_update=False, using=None): + return super(UserProfile, self).save(force_insert, force_update, using) \ No newline at end of file diff --git a/static/js/app/app.js b/static/js/app/app.js index ceb072c..9eb5e89 100644 --- a/static/js/app/app.js +++ b/static/js/app/app.js @@ -1,6 +1,5 @@ var AppRouter = Backbone.Router.extend({ routes:{ - "":"defaultRoute", "/mixes":"mixList", "/mixes/:type":"mixList", "/mix/:id":"mixDetails", @@ -8,9 +7,11 @@ var AppRouter = Backbone.Router.extend({ "/release/:id":"releaseDetails", "/events":"eventList", "/event/:id":"eventDetails", + "/accounts/social/connections/":"connectAccounts", "/accounts/login/":"login", "/accounts/logout/":"logout", - "/me":"userDetails" + "/me":"userDetails", + "*path":"defaultRoute" }, initialize:function () { this.headerView = new HeaderView(); @@ -18,9 +19,7 @@ var AppRouter = Backbone.Router.extend({ $('#site-content-fill').html(''); }, defaultRoute:function (path) { - if (!path) - this.mixList('latest'); - else if (path == "" || path == "/") + if (path == undefined || path == "" || path == "/") this.mixList('latest'); }, mixList:function (type) { @@ -107,7 +106,10 @@ var AppRouter = Backbone.Router.extend({ logout:function () { window.utils.showAlert("Success", "You are now logged out", "alert-success"); }, - userDetails: function(){ + connectAccounts:function () { + alert("sdfkjsdlfj"); + }, + userDetails:function () { var user = new User(); $('#site-content-fill').html(''); user.fetch({success:function () { @@ -118,12 +120,12 @@ var AppRouter = Backbone.Router.extend({ }); utils.loadTemplate([ - 'HeaderView', 'SidebarView', 'UserView', - 'MixListView', 'MixListItemView', 'MixView', - 'CommentListView', 'CommentListItemView', - 'ReleaseListView', 'ReleaseListItemView', 'ReleaseItemView', 'ReleaseView', 'ReleaseAudioListView', 'ReleaseAudioItemView', - 'EventListView', 'EventListItemView', 'EventView', 'EventItemView' - ], function () { + 'HeaderView', 'SidebarView', 'UserView', + 'MixListView', 'MixListItemView', 'MixView', + 'CommentListView', 'CommentListItemView', + 'ReleaseListView', 'ReleaseListItemView', 'ReleaseItemView', 'ReleaseView', 'ReleaseAudioListView', 'ReleaseAudioItemView', + 'EventListView', 'EventListItemView', 'EventView', 'EventItemView' +], function () { window.app = new AppRouter(); Backbone.history.start(); } diff --git a/static/js/app/utils.js b/static/js/app/utils.js index 47ff0a3..56bdc93 100644 --- a/static/js/app/utils.js +++ b/static/js/app/utils.js @@ -59,13 +59,21 @@ window.utils = { $('.help-inline', controlGroup).html(''); }, - showAlert:function (title, text, klass) { + showAlert:function (title, text, klass, fade) { $('.alert').removeClass("alert-error alert-warning alert-success alert-info"); $('.alert').addClass(klass); $('.alert').html('' + title + ' ' + text); $('.alert').show(); + if (fade) { + $('.alert').fadeOut(5000, function () { + }); + }else{ + $('.alert').click(function() { + $('.alert').fadeOut('slow', function() { + }); + }); + } }, - hideAlert:function () { $('.alert').hide(); } @@ -88,3 +96,10 @@ window.TastypieCollection = Backbone.Collection.extend({ return response.objects || response; } }); + +(function () { + var proxied = window.alert; + window.alert = function () { + return proxied.apply(this, arguments); + }; +})(); \ No newline at end of file diff --git a/static/js/app/views/header.js b/static/js/app/views/header.js index d2172ac..df73648 100644 --- a/static/js/app/views/header.js +++ b/static/js/app/views/header.js @@ -14,6 +14,7 @@ window.HeaderView = Backbone.View.extend({ }, trackChanged:function (data) { $(this.el).find('#track-description').text(data.title); + $(this.el).find('#track-description').attr("href", "#" + data.item_url); }, trackPlaying:function (data) { $(this.el).find('#header-play-button-icon').removeClass('icon-play'); diff --git a/static/js/app/views/user.js b/static/js/app/views/user.js index 2816bc4..d750ad2 100644 --- a/static/js/app/views/user.js +++ b/static/js/app/views/user.js @@ -12,7 +12,17 @@ window.UserView = Backbone.View.extend({ return this; }, saveChanges: function(){ - this.model.save(); + this.model.save( + null,{ + success: function(){ + window.utils.showAlert("Success", "Successfully updated yourself", "alert-info", true); + window.history.back(); + }, + error: function(){ + window.utils.showAlert("Success", "Successfully updated yourself", "alert-info", false); + alert("Error"); + } + }); return false; }, changed:function(evt) { diff --git a/templates/base.html b/templates/base.html index ae1ebed..997c9b1 100644 --- a/templates/base.html +++ b/templates/base.html @@ -44,15 +44,17 @@ {% include 'inc/ancient_browser.html' %} -
-
-