summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2017-10-06 17:51:58 +0300
committerLars Wirzenius <liw@liw.fi>2017-10-09 21:00:43 +0300
commit892b9d623f76d2ad140835ebbf635357ca0e0c85 (patch)
tree6405a2d8c3b31909165ec42d3418aa585c6cc1a2
parent3ba601fc4a20d0c9c883562496bd23818029228d (diff)
downloadqvisqve-892b9d623f76d2ad140835ebbf635357ca0e0c85.tar.gz
Refactor: move subresource route creation into method
This applies for non-file subrsources only.
-rw-r--r--qvarn/api.py30
1 files changed, 18 insertions, 12 deletions
diff --git a/qvarn/api.py b/qvarn/api.py
index 909e202..926326f 100644
--- a/qvarn/api.py
+++ b/qvarn/api.py
@@ -265,22 +265,28 @@ class QvarnAPI:
},
]
+ files = rt.get_files()
for subpath in rt.get_subpaths():
- routes.extend([
- {
- 'method': 'GET',
- 'path': '{}/{}'.format(id_path, subpath),
- 'callback': self.get_subpath_callback(coll, subpath),
- },
- {
- 'method': 'PUT',
- 'path': '{}/{}'.format(id_path, subpath),
- 'callback': self.put_subpath_callback(coll, subpath),
- },
- ])
+ if subpath not in files:
+ routes.extend(
+ self.get_subresource_routes(id_path, coll, subpath))
return routes + self._get_notification_routes(coll, path, id_path)
+ def get_subresource_routes(self, id_path, coll, subpath):
+ return [
+ {
+ 'method': 'GET',
+ 'path': '{}/{}'.format(id_path, subpath),
+ 'callback': self.get_subpath_callback(coll, subpath),
+ },
+ {
+ 'method': 'PUT',
+ 'path': '{}/{}'.format(id_path, subpath),
+ 'callback': self.put_subpath_callback(coll, subpath),
+ },
+ ]
+
def _get_notification_routes(self, coll, path, id_path):
rt = self.get_listener_resource_type()
listeners = qvarn.CollectionAPI()