From 677798a0b4617712e5ccc28a9ea89f9ca1ec3afa Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Fri, 20 Jul 2018 15:02:55 -0700 Subject: python base32 idents --- python/fatcat/routes.py | 132 ++++++++++++++++++++------------------ python/fatcat/templates/home.html | 20 +++--- python/tests/routes.py | 31 +++++---- 3 files changed, 95 insertions(+), 88 deletions(-) diff --git a/python/fatcat/routes.py b/python/fatcat/routes.py index b23dc9d4..c92f6493 100644 --- a/python/fatcat/routes.py +++ b/python/fatcat/routes.py @@ -10,19 +10,11 @@ from fatcat.search import do_search ### Views ################################################################### -@app.route('/container/', methods=['GET']) -def container_view(ident): - try: - entity = api.get_container(str(ident)) - except ApiException as ae: - abort(ae.status) - return render_template('container_view.html', container=entity) - -@app.route('/container//history', methods=['GET']) +@app.route('/container//history', methods=['GET']) def container_history(ident): try: - entity = api.get_container(str(ident)) - history = api.get_container_history(str(ident)) + entity = api.get_container(ident) + history = api.get_container_history(ident) except ApiException as ae: abort(ae.status) print(history) @@ -32,15 +24,15 @@ def container_history(ident): entity=entity, history=history) -@app.route('/container//edit', methods=['GET']) +@app.route('/container//edit', methods=['GET']) def container_edit_view(ident): try: - entity = api.get_container(str(ident)) + entity = api.get_container(ident) except ApiException as ae: abort(ae.status) return render_template('entity_edit.html') -#@app.route('/container//edit', methods=['POST']) +#@app.route('/container//edit', methods=['POST']) #def container_edit(ident): # raise NotImplemented() # params = dict() @@ -76,20 +68,19 @@ def container_lookup(): abort(ae.status) return redirect('/container/{}'.format(resp.ident)) -@app.route('/creator/', methods=['GET']) -def creator_view(ident): +@app.route('/container/', methods=['GET']) +def container_view(ident): try: - entity = api.get_creator(str(ident)) - releases = api.get_creator_releases(str(ident)) + entity = api.get_container(ident) except ApiException as ae: abort(ae.status) - return render_template('creator_view.html', creator=entity, releases=releases) + return render_template('container_view.html', container=entity) -@app.route('/creator//history', methods=['GET']) +@app.route('/creator//history', methods=['GET']) def creator_history(ident): try: - entity = api.get_creator(str(ident)) - history = api.get_creator_history(str(ident)) + entity = api.get_creator(ident) + history = api.get_creator_history(ident) except ApiException as ae: abort(ae.status) return render_template('entity_history.html', @@ -98,10 +89,10 @@ def creator_history(ident): entity=entity, history=history) -@app.route('/creator//edit', methods=['GET']) +@app.route('/creator//edit', methods=['GET']) def creator_edit_view(ident): try: - entity = api.get_creator(str(ident)) + entity = api.get_creator(ident) except ApiException as ae: abort(ae.status) return render_template('entity_edit.html') @@ -117,19 +108,20 @@ def creator_lookup(): abort(ae.status) return redirect('/creator/{}'.format(resp.ident)) -@app.route('/file/', methods=['GET']) -def file_view(ident): +@app.route('/creator/', methods=['GET']) +def creator_view(ident): try: - entity = api.get_file(str(ident)) + entity = api.get_creator(ident) + releases = api.get_creator_releases(ident) except ApiException as ae: abort(ae.status) - return render_template('file_view.html', file=entity) + return render_template('creator_view.html', creator=entity, releases=releases) -@app.route('/file//history', methods=['GET']) +@app.route('/file//history', methods=['GET']) def file_history(ident): try: - entity = api.get_file(str(ident)) - history = api.get_file_history(str(ident)) + entity = api.get_file(ident) + history = api.get_file_history(ident) except ApiException as ae: abort(ae.status) return render_template('entity_history.html', @@ -138,10 +130,10 @@ def file_history(ident): entity=entity, history=history) -@app.route('/file//edit', methods=['GET']) +@app.route('/file//edit', methods=['GET']) def file_edit_view(ident): try: - entity = api.get_file(str(ident)) + entity = api.get_file(ident) except ApiException as ae: abort(ae.status) return render_template('entity_edit.html') @@ -157,20 +149,13 @@ def file_lookup(): abort(ae.status) return redirect('/file/{}'.format(resp.ident)) -@app.route('/release/', methods=['GET']) -def release_view(ident): +@app.route('/file/', methods=['GET']) +def file_view(ident): try: - entity = api.get_release(str(ident)) - files = api.get_release_files(str(ident)) - container = None - if entity.container_id is not None: - container = api.get_container(entity.container_id) + entity = api.get_file(ident) except ApiException as ae: abort(ae.status) - authors = [c for c in entity.contribs if c.role in ('author', None)] - authors = sorted(authors, key=lambda c: c.index) - return render_template('release_view.html', release=entity, - authors=authors, files=files, container=container) + return render_template('file_view.html', file=entity) @app.route('/release/lookup', methods=['GET']) def release_lookup(): @@ -196,11 +181,11 @@ def release_create(): edit = api.create_release(params=params) return redirect("/release/{}".format(edit.ident)) -@app.route('/release//history', methods=['GET']) +@app.route('/release//history', methods=['GET']) def release_history(ident): try: - entity = api.get_release(str(ident)) - history = api.get_release_history(str(ident)) + entity = api.get_release(ident) + history = api.get_release_history(ident) except ApiException as ae: abort(ae.status) return render_template('entity_history.html', @@ -209,28 +194,38 @@ def release_history(ident): entity=entity, history=history) -@app.route('/release//edit', methods=['GET']) +@app.route('/release//edit', methods=['GET']) def release_edit_view(ident): try: - entity = api.get_release(str(ident)) + entity = api.get_release(ident) except ApiException as ae: abort(ae.status) return render_template('entity_edit.html') -@app.route('/work/', methods=['GET']) -def work_view(ident): +@app.route('/release/', methods=['GET']) +def release_view(ident): try: - entity = api.get_work(str(ident)) - releases = api.get_work_releases(str(ident)) + entity = api.get_release(ident) + files = api.get_release_files(ident) + container = None + if entity.container_id is not None: + container = api.get_container(entity.container_id) except ApiException as ae: abort(ae.status) - return render_template('work_view.html', work=entity, releases=releases) + authors = [c for c in entity.contribs if c.role in ('author', None)] + authors = sorted(authors, key=lambda c: c.index) + return render_template('release_view.html', release=entity, + authors=authors, files=files, container=container) + +@app.route('/work/create', methods=['GET']) +def work_create_view(): + return abort(404) -@app.route('/work//history', methods=['GET']) +@app.route('/work//history', methods=['GET']) def work_history(ident): try: - entity = api.get_work(str(ident)) - history = api.get_work_history(str(ident)) + entity = api.get_work(ident) + history = api.get_work_history(ident) except ApiException as ae: abort(ae.status) return render_template('entity_history.html', @@ -239,22 +234,22 @@ def work_history(ident): entity=entity, history=history) -@app.route('/work//edit', methods=['GET']) +@app.route('/work//edit', methods=['GET']) def work_edit_view(ident): try: - entity = api.get_work(str(ident)) + entity = api.get_work(ident) except ApiException as ae: abort(ae.status) return render_template('entity_edit.html') -@app.route('/editgroup/', methods=['GET']) -def editgroup_view(ident): +@app.route('/work/', methods=['GET']) +def work_view(ident): try: - entity = api.get_editgroup(str(ident)) + entity = api.get_work(ident) + releases = api.get_work_releases(ident) except ApiException as ae: - print(ae.body) abort(ae.status) - return render_template('editgroup_view.html', editgroup=entity) + return render_template('work_view.html', work=entity, releases=releases) @app.route('/editgroup/current', methods=['GET']) def editgroup_current(): @@ -262,6 +257,15 @@ def editgroup_current(): #eg = api.get_or_create_editgroup() #return redirect('/editgroup/{}'.format(eg.id)) +@app.route('/editgroup/', methods=['GET']) +def editgroup_view(ident): + try: + entity = api.get_editgroup(str(ident)) + except ApiException as ae: + print(ae.body) + abort(ae.status) + return render_template('editgroup_view.html', editgroup=entity) + @app.route('/editor/', methods=['GET']) def editor_view(username): entity = api.get_editor(username) diff --git a/python/fatcat/templates/home.html b/python/fatcat/templates/home.html index f1377954..e8a5da21 100644 --- a/python/fatcat/templates/home.html +++ b/python/fatcat/templates/home.html @@ -37,8 +37,8 @@ indexing (aka, linking together of pre-prints and final copies).
journal article, pre-print, book
published version of a Work Create - Dummy -
Realistic + Dummy +
Realistic
@@ -48,8 +48,8 @@ indexing (aka, linking together of pre-prints and final copies). Container
journal or serial Create - Dummy -
Realistic + Dummy +
Realistic
@@ -60,8 +60,8 @@ indexing (aka, linking together of pre-prints and final copies). Creator
authors, editors, translators - Dummy -
Realistic + Dummy +
Realistic
@@ -71,8 +71,8 @@ indexing (aka, linking together of pre-prints and final copies). File
specific digital blobs (immutable) - Dummy -
Realistic + Dummy +
Realistic
@@ -82,8 +82,8 @@ indexing (aka, linking together of pre-prints and final copies). Work
for grouping Releases - Dummy -
Realistic + Dummy +
Realistic diff --git a/python/tests/routes.py b/python/tests/routes.py index 5a523efa..3391596e 100644 --- a/python/tests/routes.py +++ b/python/tests/routes.py @@ -19,18 +19,21 @@ def test_all_views(app): for route in ('work', 'release', 'creator', 'container', 'file'): print(route) rv = app.get('/{}/9999999999'.format(route)) - assert rv.status_code == 404 + assert rv.status_code == 400 rv = app.get('/{}/f1f046a3-45c9-ffff-ffff-ffffffffffff'.format(route)) + assert rv.status_code == 400 + + rv = app.get('/{}/ccccccccccccccccccccccccca'.format(route)) assert rv.status_code == 404 - rv = app.get('/container/00000000-0000-0000-1111-000000000002') + rv = app.get('/container/aaaaaaaaaaaaaeiraaaaaaaaai') assert rv.status_code == 200 - rv = app.get('/container/00000000-0000-0000-1111-000000000002/history') + rv = app.get('/container/aaaaaaaaaaaaaeiraaaaaaaaai/history') assert rv.status_code == 200 - rv = app.get('/container/00000000-0000-0000-1111-000000000002/edit') + rv = app.get('/container/aaaaaaaaaaaaaeiraaaaaaaaai/edit') assert rv.status_code == 200 rv = app.get('/container/create') @@ -45,31 +48,31 @@ def test_all_views(app): rv = app.get('/container/lookup?issnl=1234-5678') assert rv.status_code == 302 - rv = app.get('/creator/00000000-0000-0000-2222-000000000002') + rv = app.get('/creator/aaaaaaaaaaaaaircaaaaaaaaai') assert rv.status_code == 200 - rv = app.get('/creator/00000000-0000-0000-2222-000000000002/history') + rv = app.get('/creator/aaaaaaaaaaaaaircaaaaaaaaai/history') assert rv.status_code == 200 - rv = app.get('/creator/00000000-0000-0000-2222-000000000002/edit') + rv = app.get('/creator/aaaaaaaaaaaaaircaaaaaaaaai/edit') assert rv.status_code == 200 rv = app.get('/creator/lookup?orcid=0000-0003-2088-7465') assert rv.status_code == 302 - rv = app.get('/file/00000000-0000-0000-3333-000000000002') + rv = app.get('/file/aaaaaaaaaaaaamztaaaaaaaaai') assert rv.status_code == 200 rv = app.get('/file/lookup?sha1=7d97e98f8af710c7e7fe703abc8f639e0ee507c4') assert rv.status_code == 302 - rv = app.get('/release/00000000-0000-0000-4444-000000000002') + rv = app.get('/release/aaaaaaaaaaaaarceaaaaaaaaai') assert rv.status_code == 200 - rv = app.get('/release/00000000-0000-0000-4444-000000000002/history') + rv = app.get('/release/aaaaaaaaaaaaarceaaaaaaaaai/history') assert rv.status_code == 200 - rv = app.get('/release/00000000-0000-0000-4444-000000000002/edit') + rv = app.get('/release/aaaaaaaaaaaaarceaaaaaaaaai/edit') assert rv.status_code == 200 rv = app.get('/release/create') @@ -84,13 +87,13 @@ def test_all_views(app): rv = app.get('/release/search') assert rv.status_code == 200 - rv = app.get('/work/00000000-0000-0000-5555-000000000002') + rv = app.get('/work/aaaaaaaaaaaaavkvaaaaaaaaai') assert rv.status_code == 200 - rv = app.get('/work/00000000-0000-0000-5555-000000000002/history') + rv = app.get('/work/aaaaaaaaaaaaavkvaaaaaaaaai/history') assert rv.status_code == 200 - rv = app.get('/work/00000000-0000-0000-5555-000000000002/edit') + rv = app.get('/work/aaaaaaaaaaaaavkvaaaaaaaaai/edit') assert rv.status_code == 200 rv = app.get('/work/create') -- cgit v1.2.3