Browse Source

added child resource lookup to pagination base resource

php2python
Holger Frey 7 years ago
parent
commit
bafb16453a
  1. 14
      ordr2/resources/base.py

14
ordr2/resources/base.py

@ -30,8 +30,13 @@ class BaseResource(object):
def __getitem__(self, key): def __getitem__(self, key):
klass = self.nodes[key] klass = self.nodes.get(key, None)
if klass:
return klass(key, self) return klass(key, self)
try:
return super().__getitem__(key)
except AttributeError:
raise KeyError()
@classmethod @classmethod
@ -210,3 +215,10 @@ class PaginationResourceMixin(object):
params = self.query_params(*args, **kwargs) params = self.query_params(*args, **kwargs)
return self.request.resource_url(self, query=params) 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)