From 54c65b981838fba5c16eba7ffeefa97e47648383 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Wed, 25 Apr 2018 16:11:25 -0700 Subject: basic container creation via form --- fatcat/api.py | 30 ++++--- fatcat/routes.py | 14 +++ fatcat/templates/container_add.html | 168 +++++++++++++++++++++++++++++++++++ fatcat/templates/container_view.html | 8 +- 4 files changed, 206 insertions(+), 14 deletions(-) create mode 100644 fatcat/templates/container_add.html diff --git a/fatcat/api.py b/fatcat/api.py index 9cbb1939..eaf45d77 100644 --- a/fatcat/api.py +++ b/fatcat/api.py @@ -32,9 +32,10 @@ def api_work_get(ident): return work_schema.jsonify(entity) @app.route('/v0/work', methods=['POST']) -def api_work_create(): +def api_work_create(params=None): # TODO: Special-case to pull out primary and create that? - params = request.get_json() + if params == None: + params = request.get_json() editgroup = get_or_create_editgroup(params.get('editgroup')) rev = WorkRev( title=params.get('title', None), @@ -60,8 +61,9 @@ def api_release_get(ident): return release_schema.jsonify(entity) @app.route('/v0/release', methods=['POST']) -def api_release_create(): - params = request.get_json() +def api_release_create(params=None): + if params == None: + params = request.get_json() editgroup = get_or_create_editgroup(params.get('editgroup')) creators = params.get('creators', []) creators = [CreatorIdent.query.get_or_404(c) for c in creators] @@ -127,8 +129,9 @@ def api_creator_get(ident): return creator_schema.jsonify(entity) @app.route('/v0/creator', methods=['POST']) -def api_creator_create(): - params = request.get_json() +def api_creator_create(params=None): + if params == None: + params = request.get_json() editgroup = get_or_create_editgroup(params.get('editgroup')) rev = CreatorRev( name=params.get('name', None), @@ -162,8 +165,9 @@ def api_container_get(ident): return container_schema.jsonify(entity) @app.route('/v0/container', methods=['POST']) -def api_container_create(): - params = request.get_json() +def api_container_create(params=None): + if params == None: + params = request.get_json() editgroup = get_or_create_editgroup(params.get('editgroup')) rev = ContainerRev( name=params.get('name', None), @@ -198,8 +202,9 @@ def api_file_get(ident): return file_schema.jsonify(entity) @app.route('/v0/file', methods=['POST']) -def api_file_create(): - params = request.get_json() +def api_file_create(params=None): + if params == None: + params = request.get_json() editgroup = get_or_create_editgroup(params.get('editgroup')) releases = params.get('releases', []) releases = [ReleaseIdent.query.get_or_404(r) for r in releases] @@ -230,8 +235,9 @@ def api_editgroup_get(ident): return editgroup_schema.jsonify(entity) @app.route('/v0/editgroup', methods=['POST']) -def api_editgroup_create(): - params = request.get_json() +def api_editgroup_create(params=None): + if params == None: + params = request.get_json() eg = EditGroup( editor_id=1, description=params.get('description', None), diff --git a/fatcat/routes.py b/fatcat/routes.py index bc7d2821..0c86bd78 100644 --- a/fatcat/routes.py +++ b/fatcat/routes.py @@ -45,6 +45,20 @@ def release_random(): ident = rv.location.split('/')[-1] return redirect("/release/{}".format(ident)) +@app.route('/container/create', methods=['GET']) +def container_create_view(): + return render_template('container_add.html') + +@app.route('/container/create', methods=['POST']) +def container_create(): + params = dict() + for k in request.form: + if k.startswith('container_'): + params[k[10:]] = request.form[k] + rv = api.api_container_create(params=params) + container = json.loads(rv.data.decode('utf-8')) + return redirect("/container/{}".format(container['id'])) + @app.route('/creator/', methods=['GET']) def creator_view(ident): rv = api.api_creator_get(ident) diff --git a/fatcat/templates/container_add.html b/fatcat/templates/container_add.html new file mode 100644 index 00000000..15288142 --- /dev/null +++ b/fatcat/templates/container_add.html @@ -0,0 +1,168 @@ +{% extends "base.html" %} +{% block body %} +
+

Adding a New Container

+ +

A "container" is a anything that groups publications together. For example, +a journal (eg, "New England Journal of Medicine"), conference proceedings, a +book series, or a blog. + +

Not all publications are in a container. + +

+ +

The Basics

+ +
+ + +
+ +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + + + + + +

Anything Else?

+ +
Create container
+ +

Entity will be created as part of the current edit group, which needs to be +submited and approved before the entity will formally be included in the +catalog. + +

+ +
+{% endblock %} + +{% block postscript %} + +{% endblock %} diff --git a/fatcat/templates/container_view.html b/fatcat/templates/container_view.html index d842f7e1..483886b5 100644 --- a/fatcat/templates/container_view.html +++ b/fatcat/templates/container_view.html @@ -1,9 +1,13 @@ {% extends "base.html" %} {% block body %} -

Container: {{ container.id }}

+

Container: {{ container.name }}

-TODO: +

ID: {{ container.id }} +

ISSN: {{ container.issn }} +

Publisher: {{ container.publisher }} + +

TODO:

{{ container }}
-- cgit v1.2.3