X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/0e87ae0739ed3e72301b7b718098f97a7f06a5d8..dd425f4b68f52cd5ac634104780cb48998af9562:/apps/api/handlers.py diff --git a/apps/api/handlers.py b/apps/api/handlers.py index 03115d894..ac47ac60d 100644 --- a/apps/api/handlers.py +++ b/apps/api/handlers.py @@ -1,25 +1,49 @@ +# -*- coding: utf-8 -*- +# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. from django.shortcuts import get_object_or_404 from django.contrib.auth.decorators import login_required, user_passes_test from piston.handler import BaseHandler from piston.utils import rc, validate -from catalogue.models import Book +from catalogue.models import Book, Tag from catalogue.forms import BookImportForm +from catalogue.views import tagged_object_list +class TagHandler(BaseHandler): + allowed_methods = ('GET',) + model = Tag -staff_required = user_passes_test(lambda user: user.is_staff) + def read(self, request, tags=''): + if tags == '': + return Tag.objects.all() + else: + return tagged_object_list(request, tags, api=True) + +class BookHandler(BaseHandler): + model = Book + #fields = ('slug', 'title') + + def read(self, request, slug=None): + if slug: + return get_object_or_404(Book, slug=slug) + else: + return Book.objects.all() +# old +""" +staff_required = user_passes_test(lambda user: user.is_staff) class BookHandler(BaseHandler): model = Book fields = ('slug', 'title') - + @staff_required def read(self, request, slug=None): if slug: return get_object_or_404(Book, slug=slug) else: return Book.objects.all() - + @staff_required def create(self, request): form = BookImportForm(request.POST, request.FILES) @@ -28,4 +52,4 @@ class BookHandler(BaseHandler): return rc.CREATED else: return rc.BAD_REQUEST - +""" \ No newline at end of file