summaryrefslogtreecommitdiffstats
path: root/python/fatcat_web
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2019-06-12 19:35:28 -0700
committerBryan Newbold <bnewbold@robocracy.org>2019-06-12 19:35:28 -0700
commit13f2faaeb3f01478eba32ba22972a2a8ec07df51 (patch)
tree0f77e1b6b09e80c380eb127c371991c876a6065a /python/fatcat_web
parent668d8110c5d4e0a7eaac7e3ecc15430eb92fe2a3 (diff)
downloadfatcat-13f2faaeb3f01478eba32ba22972a2a8ec07df51.tar.gz
fatcat-13f2faaeb3f01478eba32ba22972a2a8ec07df51.zip
web entity helpers (for refactored views)
Diffstat (limited to 'python/fatcat_web')
-rw-r--r--python/fatcat_web/entity_helpers.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/python/fatcat_web/entity_helpers.py b/python/fatcat_web/entity_helpers.py
new file mode 100644
index 00000000..28ed3045
--- /dev/null
+++ b/python/fatcat_web/entity_helpers.py
@@ -0,0 +1,41 @@
+
+from flask import abort
+from fatcat_client.rest import ApiException
+from fatcat_tools.transforms import *
+from fatcat_web import api
+
+
+def generic_get_entity(entity_type, ident):
+ try:
+ if entity_type == 'container':
+ entity = api.get_container(ident)
+ if entity.state == "active":
+ entity.es = container_to_elasticsearch(entity, force_bool=False)
+ return entity
+ else:
+ raise NotImplementedError
+ except ApiException as ae:
+ abort(ae.status)
+
+def generic_get_editgroup_entity(editgroup, entity_type, ident):
+ if entity_type == 'container':
+ edits = editgroup.edits.containers
+ else:
+ raise NotImplementedError
+ for e in edits:
+ if e.ident == ident:
+ revision_id = e.revision
+ edit = e
+ break
+ if not revision_id:
+ # couldn't find relevent edit in this editgroup
+ abort(404)
+ try:
+ if entity_type == 'container':
+ entity = api.get_container_revision(revision_id)
+ else:
+ raise NotImplementedError
+ except ApiException as ae:
+ abort(ae.status)
+ entity.ident = ident
+ return entity, edit