Merge pull request #710 from monobot/asyncorm_update
modify the asyncorm example, with the new lazy querysets
This commit is contained in:
commit
23ee9f64d4
|
@ -1,5 +1,5 @@
|
|||
from sanic import Sanic
|
||||
from sanic.exceptions import NotFound
|
||||
from sanic.exceptions import NotFound, URLBuildError
|
||||
from sanic.response import json
|
||||
from sanic.views import HTTPMethodView
|
||||
|
||||
|
@ -46,21 +46,21 @@ def ignore_404s(request, exception):
|
|||
|
||||
# now the propper sanic workflow
|
||||
class BooksView(HTTPMethodView):
|
||||
def arg_parser(self, request):
|
||||
parsed_args = {}
|
||||
for k, v in request.args.items():
|
||||
parsed_args[k] = v[0]
|
||||
return parsed_args
|
||||
|
||||
async def get(self, request):
|
||||
filtered_by = self.arg_parser(request)
|
||||
filtered_by = request.raw_args
|
||||
|
||||
if filtered_by:
|
||||
q_books = await Book.objects.filter(**filtered_by)
|
||||
try:
|
||||
q_books = Book.objects.filter(**filtered_by)
|
||||
except AttributeError as e:
|
||||
raise URLBuildError(e.args[0])
|
||||
else:
|
||||
q_books = await Book.objects.all()
|
||||
q_books = Book.objects.all()
|
||||
|
||||
books = [BookSerializer.serialize(book) for book in q_books]
|
||||
books = []
|
||||
async for book in q_books:
|
||||
books.append(BookSerializer.serialize(book))
|
||||
|
||||
return json({'method': request.method,
|
||||
'status': 200,
|
||||
|
@ -80,7 +80,6 @@ class BooksView(HTTPMethodView):
|
|||
'results': BookSerializer.serialize(book),
|
||||
})
|
||||
|
||||
|
||||
class BookView(HTTPMethodView):
|
||||
async def get_object(self, request, book_id):
|
||||
try:
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
asyncorm==0.0.7
|
||||
sanic==0.4.1
|
||||
asyncorm==0.0.9
|
||||
sanic==0.5.4
|
||||
|
|
Loading…
Reference in New Issue
Block a user