Fixed wrong user being tagged due to tastypie API change

This commit is contained in:
Fergal Moran
2013-04-19 11:26:32 +01:00
parent ccb7132f65
commit 4ded0781c9
8 changed files with 51 additions and 19 deletions

View File

@@ -1,10 +1,10 @@
from django.conf.urls import url
from tastypie.authentication import Authentication
from tastypie.authorization import Authorization
from tastypie.constants import ALL_WITH_RELATIONS
from tastypie.constants import ALL, ALL_WITH_RELATIONS
from spa.api.v1.BackboneCompatibleResource import BackboneCompatibleResource
from spa.models import UserProfile
class UserResource(BackboneCompatibleResource):
class Meta:
queryset = UserProfile.objects.all()
@@ -14,7 +14,15 @@ class UserResource(BackboneCompatibleResource):
always_return_data = True
filtering = {
'user': ALL_WITH_RELATIONS,
}
'username': ALL,
'id': ALL,
}
def full_dehydrate(self, bundle, for_list=False):
return super(UserResource, self).full_dehydrate(bundle, for_list)
def authorized_read_list(self, object_list, bundle):
return object_list.filter(user_id=bundle.request.user.id)
def dehydrate(self, bundle):
bundle.data['display_name'] = bundle.obj.display_name
@@ -23,25 +31,27 @@ class UserResource(BackboneCompatibleResource):
bundle.data['email'] = bundle.obj.email
if bundle.obj.activity_sharing is not None:
bundle.data['activity_share_likes'] = (bundle.obj.activity_sharing & UserProfile.ACTIVITY_SHARE_LIKES) != 0;
bundle.data['activity_share_favourites'] = (bundle.obj.activity_sharing & UserProfile.ACTIVITY_SHARE_FAVOURITES) != 0;
bundle.data['activity_share_comments'] = (bundle.obj.activity_sharing & UserProfile.ACTIVITY_SHARE_COMMENTS) != 0;
bundle.data['activity_share_likes'] = \
(bundle.obj.activity_sharing & UserProfile.ACTIVITY_SHARE_LIKES) != 0
bundle.data['activity_share_favourites'] = \
(bundle.obj.activity_sharing & UserProfile.ACTIVITY_SHARE_FAVOURITES) != 0
bundle.data['activity_share_comments'] = \
(bundle.obj.activity_sharing & UserProfile.ACTIVITY_SHARE_COMMENTS) != 0
else:
bundle.data['activity_share_likes'] =0
bundle.data['activity_share_favourites'] =0
bundle.data['activity_share_comments'] =0
bundle.data['activity_share_likes'] = 0
bundle.data['activity_share_favourites'] = 0
bundle.data['activity_share_comments'] = 0
if bundle.obj.activity_sharing_networks is not None:
bundle.data['activity_share_networks_facebook'] = (bundle.obj.activity_sharing_networks & UserProfile.ACTIVITY_SHARE_NETWORK_FACEBOOK) != 0;
bundle.data['activity_share_networks_twitter'] = (bundle.obj.activity_sharing_networks& UserProfile.ACTIVITY_SHARE_NETWORK_TWITTER) != 0;
bundle.data['activity_share_networks_facebook'] = \
(bundle.obj.activity_sharing_networks & UserProfile.ACTIVITY_SHARE_NETWORK_FACEBOOK) != 0
bundle.data['activity_share_networks_twitter'] = \
(bundle.obj.activity_sharing_networks & UserProfile.ACTIVITY_SHARE_NETWORK_TWITTER) != 0
else:
bundle.data['activity_share_networks_facebook'] = 0
bundle.data['activity_share_networks_facebook'] = 0
return bundle
def apply_authorization_limits(self, request, object_list):
if request.user is not None:
return object_list.filter(user=request.user)
return bundle
def hydrate_slug(self, bundle):
if bundle.data['slug'] == '':