1 # -*- coding: utf-8 -*-
2 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 from django.shortcuts import get_object_or_404
5 from django.contrib.auth.decorators import login_required, user_passes_test
6 from piston.handler import BaseHandler
7 from piston.utils import rc, validate
8 from catalogue.models import Book, Tag
9 from catalogue.forms import BookImportForm
10 from catalogue.views import tagged_object_list
12 class TagHandler(BaseHandler):
13 allowed_methods = ('GET',)
16 def read(self, request, tags=''):
18 return Tag.objects.all()
20 return tagged_object_list(request, tags, api=True)
22 class BookHandler(BaseHandler):
24 #fields = ('slug', 'title')
26 def read(self, request, slug=None):
28 return get_object_or_404(Book, slug=slug)
30 return Book.objects.all()
34 staff_required = user_passes_test(lambda user: user.is_staff)
36 class BookHandler(BaseHandler):
38 fields = ('slug', 'title')
41 def read(self, request, slug=None):
43 return get_object_or_404(Book, slug=slug)
45 return Book.objects.all()
48 def create(self, request):
49 form = BookImportForm(request.POST, request.FILES)