Skip to content

Instantly share code, notes, and snippets.

@joshourisman
Created August 11, 2011 19:16
Show Gist options
  • Save joshourisman/1140495 to your computer and use it in GitHub Desktop.
Save joshourisman/1140495 to your computer and use it in GitHub Desktop.
import requests
import json
from django.http import HttpResponse
from django.views.generic import View
from disco_utils.views import JSONResponseMixin
class GetAlbumsView(JSONResponseMixin, View):
def dispatch(self, *args, **kwargs):
request = args[0]
self.profile = request.user.get_profile()
return self.get_albums(self.profile)
def get_albums(self, profile):
raw = self.profile.albums
self.albums = raw['data']
if len(self.albums) >= 5:
next = raw['paging']['next']
self.albums.append(self.get_next(next))
return self.render_to_response(self.albums)
def get_next(self, next):
raw = json.loads(requests.get(next).content)
albums = raw['data']
if len(albums) == 0:
return albums
else:
next = raw['paging']['next']
return albums.extend(self.get_next(next))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment