From 1691ff26ff3a33d619fbc1bd2983a9b07dbdbabc Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Sat, 2 Mar 2019 17:25:30 -0800 Subject: add basic fileset and webcapture views --- python/fatcat_web/routes.py | 89 ++++++++++++++++++++++++ python/fatcat_web/templates/fileset_view.html | 78 +++++++++++++++++++++ python/fatcat_web/templates/webcapture_view.html | 85 ++++++++++++++++++++++ 3 files changed, 252 insertions(+) create mode 100644 python/fatcat_web/templates/fileset_view.html create mode 100644 python/fatcat_web/templates/webcapture_view.html (limited to 'python/fatcat_web') diff --git a/python/fatcat_web/routes.py b/python/fatcat_web/routes.py index ab23c847..5ccfe238 100644 --- a/python/fatcat_web/routes.py +++ b/python/fatcat_web/routes.py @@ -218,6 +218,95 @@ def file_view(ident): abort(ae.status) return render_template('file_view.html', file=entity) +@app.route('/fileset//history', methods=['GET']) +def fileset_history(ident): + try: + entity = api.get_fileset(ident) + history = api.get_fileset_history(ident) + except ApiException as ae: + abort(ae.status) + return render_template('entity_history.html', + page_title=None, + entity_type="fileset", + entity=entity, + history=history) + +@app.route('/fileset//edit', methods=['GET']) +def fileset_edit_view(ident): + try: + entity = api.get_fileset(ident) + except ApiException as ae: + abort(ae.status) + return render_template('entity_edit.html') + +@app.route('/fileset/lookup', methods=['GET']) +def fileset_lookup(): + raise NotImplementedError + +@app.route('/fileset/', methods=['GET']) +def fileset_view(ident): + try: + entity = api.get_fileset(ident) + except ApiException as ae: + abort(ae.status) + if entity.state == "redirect": + return redirect('/fileset/{}'.format(entity.redirect)) + elif entity.state == "deleted": + return render_template('deleted_entity.html', entity=entity) + else: + try: + entity.releases = [] + for r in entity.release_ids: + entity.releases.append(api.get_release(r)) + except ApiException as ae: + abort(ae.status) + entity.total_size = sum([f.size for f in entity.manifest]) + return render_template('fileset_view.html', fileset=entity) + +@app.route('/webcapture//history', methods=['GET']) +def webcapture_history(ident): + try: + entity = api.get_webcapture(ident) + history = api.get_webcapture_history(ident) + except ApiException as ae: + abort(ae.status) + return render_template('entity_history.html', + page_title=None, + entity_type="webcapture", + entity=entity, + history=history) + +@app.route('/webcapture//edit', methods=['GET']) +def webcapture_edit_view(ident): + try: + entity = api.get_webcapture(ident) + except ApiException as ae: + abort(ae.status) + return render_template('entity_edit.html') + +@app.route('/webcapture/lookup', methods=['GET']) +def webcapture_lookup(): + raise NotImplementedError + +@app.route('/webcapture/', methods=['GET']) +def webcapture_view(ident): + try: + entity = api.get_webcapture(ident) + except ApiException as ae: + abort(ae.status) + if entity.state == "redirect": + return redirect('/webcapture/{}'.format(entity.redirect)) + elif entity.state == "deleted": + return render_template('deleted_entity.html', entity=entity) + else: + try: + entity.releases = [] + for r in entity.release_ids: + entity.releases.append(api.get_release(r)) + except ApiException as ae: + abort(ae.status) + return render_template('webcapture_view.html', webcapture=entity) + @app.route('/release/lookup', methods=['GET']) def release_lookup(): for key in ('doi', 'wikidata_qid', 'pmid', 'pmcid', 'isbn13', 'core_id'): diff --git a/python/fatcat_web/templates/fileset_view.html b/python/fatcat_web/templates/fileset_view.html new file mode 100644 index 00000000..11f69dd7 --- /dev/null +++ b/python/fatcat_web/templates/fileset_view.html @@ -0,0 +1,78 @@ +{% set entity = fileset %} +{% import "entity_macros.html" as entity_macros %} +{% extends "base.html" %} + +{% block fullbody %} + +
+
+
+

+
fileset {{ entity.ident }}

+
+
+ +
+
+
+ +{% if entity.extra %} + {{ entity_macros.extra_metadata(entity.extra) }} +{% endif %} + +

Releases

+{% if entity.releases != [] %} + {{ entity_macros.release_list(entity.releases) }} +{% else %} +

+ This File Set is not associated with any fatcat release. +{% endif %} + + +

File Manifest ({{ fileset.manifest|count }})

+{% if fileset.manifest %} +
+ {% for file in fileset.manifest %} +
+
+
+ {{ file.path }} ({{ file.size|filesizeformat }}{% if file.extra.mimetype %}, {{ file.extra.mimetype }}{% endif %}) +
+
+ {% if file.md5 %} md5:{{ file.md5 }}
{% endif %} + {% if file.sha1 %} sha1:{{ file.sha1 }}
{% endif %} + {% if file.sha256 %}sha256:{{ file.sha256 }}
{% endif %} +
+
+
+ {% endfor %} +
+{% else %} +This File Set is empty (contains no files). +{% endif %} + + +
+

Base URLs

+{% if entity.urls %} + {{ entity_macros.url_list(entity.urls) }} +{% else %} +No known public URL, mirror, or archive for this File Set. +{% endif %} + +
+
+ +{% if fileset.total_size != None %} +
+

Total Size  {{ fileset.total_size|filesizeformat }} +

+{% endif %} + +{{ entity_macros.fatcat_bits(entity, "fileset", "") }} + +
+
+ + +{% endblock %} diff --git a/python/fatcat_web/templates/webcapture_view.html b/python/fatcat_web/templates/webcapture_view.html new file mode 100644 index 00000000..08489fd3 --- /dev/null +++ b/python/fatcat_web/templates/webcapture_view.html @@ -0,0 +1,85 @@ +{% set entity = webcapture %} +{% import "entity_macros.html" as entity_macros %} +{% extends "base.html" %} + +{% block fullbody %} + +
+
+
+

+ {% if webcapture.original_url %} + {{ webcapture.original_url }} + {% endif %} +
webcapture {{ webcapture.ident }}

+
+
+ +
+
+
+ + +{% if entity.extra %} + {{ entity_macros.extra_metadata(entity.extra) }} +{% endif %} + +

Releases

+{% if entity.releases != [] %} + {{ entity_macros.release_list(entity.releases) }} +{% else %} +

+ This Web Capture is not associated with any fatcat release. +{% endif %} + + +

CDX Rows ({{ webcapture.cdx|count }})

+{% if webcapture.cdx %} +
+ {% for row in webcapture.cdx %} +
+
+ +
+ {{ row.timestamp }} + {% if row.mimetype %}| {{ row.mimetype }}{% endif %} +
+ + {% if row.sha1 %}sha1:{{ row.sha1 }}
{% endif %} + {% if row.sha256 %}sha256:{{ row.sha256 }}
{% endif %} +
+
+
+
+ {% endfor %} +
+{% else %} +This File Set is empty (contains no files). +{% endif %} + +
+

Archive URLs

+{% if webcapture.archive_urls != None %} + {{ entity_macros.url_list(webcapture.archive_urls) }} +{% else %} +No known public archive for this webcapture. +{% endif %} + +
+
+ +{% if webcapture.timestamp != None %} +
+

Capture Time  {{ webcapture.timestamp }} +

+{% endif %} + +{{ entity_macros.fatcat_bits(entity, "webcapture", "") }} + +
+
+ + +{% endblock %} -- cgit v1.2.3