Started the creation of an API and implemented infinite scroll. Closes issue #7.

This commit is contained in:
Isaac Bythewood
2012-04-27 19:59:55 +00:00
parent ce95b7ef7f
commit f88a06aefa
13 changed files with 237 additions and 21 deletions

21
pinry/api/views.py Normal file
View File

@@ -0,0 +1,21 @@
from django.utils import simplejson
from django.http import HttpResponse
from pinry.pins.models import Pin
def pins_recent(request, page=1):
start_pin = abs(int(page) - 1) * 25
end_pin = int(page) * 25
pins = Pin.objects.order_by('-id')[start_pin:end_pin]
recent_pins = []
for pin in pins:
recent_pins.append({
'id': pin.id,
'thumbnail': pin.image.url_200x1000,
'original': pin.image.url,
'description': pin.description,
})
return HttpResponse(simplejson.dumps(recent_pins), mimetype="application/json")