Merge pull request #710 from monobot/asyncorm_update

modify the asyncorm example, with the new lazy querysets
This commit is contained in:
Raphael Deem 2017-05-11 10:35:52 -07:00 committed by GitHub
commit 23ee9f64d4
2 changed files with 12 additions and 13 deletions

View File

@ -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:

View File

@ -1,2 +1,2 @@
asyncorm==0.0.7
sanic==0.4.1
asyncorm==0.0.9
sanic==0.5.4