1 from django.shortcuts import get_object_or_404
2 from django.contrib.auth.decorators import login_required, user_passes_test
3 from piston.handler import BaseHandler
4 from piston.utils import rc, validate
5 from catalogue.models import Book
6 from catalogue.forms import BookImportForm
9 staff_required = user_passes_test(lambda user: user.is_staff)
12 class BookHandler(BaseHandler):
14 fields = ('slug', 'title')
17 def read(self, request, slug=None):
19 return get_object_or_404(Book, slug=slug)
21 return Book.objects.all()
24 def create(self, request):
25 form = BookImportForm(request.POST, request.FILES)