def dehydrate(self, bundle): bundle.data['url'] = bundle.obj.profile.get_absolute_url() # return full user data with follows and casted votes if hasattr(bundle.request, 'REQUEST') and 'user_full' in bundle.request.REQUEST: follows = [] follow_rsc = FollowResource() for f in DateaFollow.objects.filter(user=bundle.obj, published=True): f_bundle = follow_rsc.build_bundle(obj=f) f_bundle = follow_rsc.full_dehydrate(f_bundle) follows.append(f_bundle.data) bundle.data['follows'] = follows votes = [] vote_rsc = VoteResource() for v in DateaVote.objects.filter(user=bundle.obj): v_bundle = vote_rsc.build_bundle(obj=v) v_bundle = vote_rsc.full_dehydrate(v_bundle) votes.append(v_bundle.data) bundle.data['votes'] = votes if 'with_action_ids' in bundle.request.REQUEST: bundle.data['actions'] = [a.id for a in DateaAction.objects.filter(user=bundle.obj)] if 'api_key' in bundle.request.REQUEST: keyauth = ApiKeyAuthentication() if keyauth.is_authenticated(bundle.request): if bundle.request.user and bundle.request.user == bundle.obj: bundle.data['email'] = bundle.obj.email return bundle
def get_user_votes(context): request = context['request'] # follow keys votes = [] vote_rsc = VoteResource() for inst in DateaVote.objects.filter(user=request.user): v_bundle = vote_rsc.build_bundle(obj=inst) v_bundle = vote_rsc.full_dehydrate(v_bundle) votes.append(vote_rsc.serialize(None, v_bundle, 'application/json')) return '['+",".join(votes)+']'