From ad68739df78511d307417ee0c061f08a12f1a51b Mon Sep 17 00:00:00 2001 From: monobot Date: Thu, 11 May 2017 18:15:04 +0100 Subject: [PATCH] modify the asyncorm example, for the new lazy querysets --- examples/asyncorm/__main__.py | 21 ++++++++++----------- examples/asyncorm/requirements.txt | 4 ++-- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/examples/asyncorm/__main__.py b/examples/asyncorm/__main__.py index 20537f7b..6e4d4ff2 100644 --- a/examples/asyncorm/__main__.py +++ b/examples/asyncorm/__main__.py @@ -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: diff --git a/examples/asyncorm/requirements.txt b/examples/asyncorm/requirements.txt index 9b824ce6..b4aa9cae 100644 --- a/examples/asyncorm/requirements.txt +++ b/examples/asyncorm/requirements.txt @@ -1,2 +1,2 @@ -asyncorm==0.0.7 -sanic==0.4.1 +asyncorm==0.0.9 +sanic==0.5.4