class IgnoredCustomView(MyAbstractView): __ignore__ = True app = ObjectProxy() @lazy_decorate(app.route("/bar", methods=["GET"])) async def company_list(self, request): return json({"hello": "ignored"})
class MyCustomView(LazyView): app = ObjectProxy() sanicjwt = ObjectProxy() @lazy_decorate(sanicjwt.protected()) @lazy_decorate(app.route("/", methods=["GET"])) async def company_list(self, request): return json({"hello": "world"}) @lazy_decorate(app.route("/foo", methods=["GET"]), sanicjwt.protected(debug=False)) async def another_test(self, request): print(self.sanicjwt.config.debug()) return json({"another": "test"}) @lazy_decorate(app.listener("before_server_start")) async def simple_assert_check(self, app, loop): assert self.app == app
class MyCustomView(make_lazy_view("MyCustomView", MyViewHelper)): app = ObjectProxy() @lazy_decorate(app.route("/", methods=["GET"]), app.route("/baz")) async def company_list(self, request): return json({"hello": "world"}) @lazy_decorate(app.middleware("response")) async def add_sid(self, request, response): response.headers.update({"x-sid": self.get_random_string()})
class AnotherCustomView(LazyView): app = ObjectProxy() @lazy_decorate(app.middleware) async def create_request_id(self, request): request["request_id"] = uuid.uuid4() @lazy_decorate(app.middleware("response")) async def attach_request_id(self, request, response): response.headers.update( {"x-my-custom-uuid": request.get("request_id")})
class SanicSessionView(make_lazy_view("sanic_session")): app = ObjectProxy() interface = MyInterface() @lazy_decorate(app.middleware("request")) async def add_session_to_request(self, request): await self.interface.open(request) @lazy_decorate(app.middleware("response")) async def save_session(self, request, response): await self.interface.save(request, response)
class MyCustomView(MyAbstractView): app = ObjectProxy() @lazy_decorate(app.route("/", methods=["GET"]), app.route("/baz")) async def company_list(self, request): return json({"hello": "world"}) @lazy_decorate(app.route("/foo", methods=["GET"])) @lazy_decorate(app.route("/oof")) async def another_test(self, request): return json({"another": "test"}) @lazy_decorate(app.listener("before_server_start")) async def simple_assert_check(self, app, loop): assert self.app == app
class MyCustomView(make_lazy_view()): app = ObjectProxy() @lazy_decorate(app.route("/", methods=["GET"])) async def company_list(self, request): return json({"hello": "world"})