fnp
/
wolnelektury.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
9c6af64
)
API: handlers
author
Łukasz Anwajler
<lukasz@anwajler.com>
Wed, 23 Feb 2011 23:48:46 +0000
(15:48 -0800)
committer
Łukasz Anwajler
<lukasz@anwajler.com>
Wed, 23 Feb 2011 23:48:46 +0000
(15:48 -0800)
apps/api/handlers.py
patch
|
blob
|
history
diff --git
a/apps/api/handlers.py
b/apps/api/handlers.py
index
40121d6
..
ac47ac6
100644
(file)
--- a/
apps/api/handlers.py
+++ b/
apps/api/handlers.py
@@
-1,17
+1,37
@@
# -*- 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.
# -*- 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 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.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
class BookHandler(BaseHandler):
model = Book
@@
-32,4
+52,4
@@
class BookHandler(BaseHandler):
return rc.CREATED
else:
return rc.BAD_REQUEST
return rc.CREATED
else:
return rc.BAD_REQUEST
-
+"""
\ No newline at end of file