from django.http.response import HttpResponse
from django.utils.functional import lazy
from django.db import models
+from migdal.models import Entry
from piston.handler import AnonymousBaseHandler, BaseHandler
from piston.utils import rc
from sorl.thumbnail import default
if count:
books = books[:count]
return books
+
+
+class BlogEntryHandler(BaseHandler):
+ model = Entry
+ fields = ('title', 'lead', 'body', 'place', 'time', 'image_url', 'gallery_urls', 'type', 'key')
+
+ def read(self, request):
+ after = request.GET.get('after')
+ count = int(request.GET.get('count', 20))
+ entries = Entry.published_objects.filter(in_stream=True).order_by('-first_published_at')
+ if after:
+ entries = entries.filter(first_published_at__lt=after)
+ if count:
+ entries = entries[:count]
+ return entries
+
+ @classmethod
+ def image_url(cls, entry):
+ return entry.image.url if entry.image else None
+
+ @classmethod
+ def gallery_urls(cls, entry):
+ return [photo.url() for photo in entry.photo_set.all()]
+
+ @classmethod
+ def key(cls, entry):
+ return entry.first_published_at
picture_resource = CsrfExemptResource(handler=handlers.PictureHandler, authentication=auth)
+blog_resource = Resource(handler=handlers.BlogEntryHandler)
+
tags_re = r'^(?P<tags>(?:(?:[a-z0-9-]+/){2}){0,6})'
paginate_re = r'(?:before/(?P<before>[a-z0-9-]+)/)?(?:after/(?P<after>[a-z0-9-]+)/)?(?:count/(?P<count>[0-9]+)/)?$'
url(r'^pictures/$', picture_resource),
+ url(r'^blog/$', blog_resource),
+
# fragments by book, tags, themes
# this should be paged
url(r'^(?P<tags>(?:(?:[a-z0-9-]+/){2}){1,6})fragments/$', fragment_list_resource),