Created
August 11, 2011 19:16
-
-
Save joshourisman/1140495 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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