From bafb16453a555b9374ebcb46a7b970cfd1874987 Mon Sep 17 00:00:00 2001 From: Holger Frey Date: Sat, 30 Sep 2017 12:37:20 +0200 Subject: [PATCH] added child resource lookup to pagination base resource --- ordr2/resources/base.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/ordr2/resources/base.py b/ordr2/resources/base.py index 224c6e5..b25ea29 100644 --- a/ordr2/resources/base.py +++ b/ordr2/resources/base.py @@ -30,8 +30,13 @@ class BaseResource(object): def __getitem__(self, key): - klass = self.nodes[key] - return klass(key, self) + klass = self.nodes.get(key, None) + if klass: + return klass(key, self) + try: + return super().__getitem__(key) + except AttributeError: + raise KeyError() @classmethod @@ -210,3 +215,10 @@ class PaginationResourceMixin(object): params = self.query_params(*args, **kwargs) return self.request.resource_url(self, query=params) + + def __getitem__(self, key): + model = self.request.dbsession.query(self.sql_model_class).get(key) + if not model: + raise KeyError() + return self.child_resource_class.from_sqla(model, self) +