From 5527ecc2b7bd81bab9bcb065adbbccd941b85be8 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Thu, 21 Mar 2019 16:59:18 -0700 Subject: major progress on release create form --- python/fatcat_web/__init__.py | 2 +- python/fatcat_web/forms.py | 81 ++++++ python/fatcat_web/routes.py | 30 +- python/fatcat_web/templates/release_create.html | 364 ++++++++++++------------ 4 files changed, 281 insertions(+), 196 deletions(-) create mode 100644 python/fatcat_web/forms.py (limited to 'python') diff --git a/python/fatcat_web/__init__.py b/python/fatcat_web/__init__.py index e80393c2..00bc84fd 100644 --- a/python/fatcat_web/__init__.py +++ b/python/fatcat_web/__init__.py @@ -46,7 +46,7 @@ else: print("No privileged token found") priv_api = None -from fatcat_web import routes, auth, cors +from fatcat_web import routes, auth, cors, forms gitlab_bp = create_flask_blueprint(Gitlab, oauth, auth.handle_oauth) app.register_blueprint(gitlab_bp, url_prefix='/auth/gitlab') diff --git a/python/fatcat_web/forms.py b/python/fatcat_web/forms.py new file mode 100644 index 00000000..f961faa0 --- /dev/null +++ b/python/fatcat_web/forms.py @@ -0,0 +1,81 @@ + +""" +Note: in thoery could use, eg, https://github.com/christabor/swagger_wtforms, +but can't find one that is actually maintained. +""" + +from flask_wtf import FlaskForm +from wtforms import SelectField, DateField, StringField, FormField, FieldList, validators + +release_type_options = [ + ('article-journal', 'Journal Article'), + ('paper-conference', 'Conference Proceeding'), + ('article', 'Article (non-journal)'), + ('book', 'Book'), + ('chapter', 'Book Chapter'), + ('dataset', 'Dataset'), + ('stub', 'Invalid/Stub'), +] +release_status_options = [ + ('draft', 'Draft'), + ('submitted', 'Submitted'), + ('accepted', 'Accepted'), + ('published', 'Published'), + ('updated', 'Updated'), +] +role_type_options = [ + ('author', 'Author'), + ('editor', 'Editor'), + ('translator', 'Translator'), +] + +class EntityEditForm(FlaskForm): + editgroup_id = StringField('Editgroup ID', + [validators.DataRequired()]) + editgroup_description = StringField('Editgroup Description', + [validators.Optional(True)]) + edit_description = StringField('Description of Changes', + [validators.Optional(True)]) + +class ReleaseContribForm(FlaskForm): + #surname + #given_name + #creator_id (?) + #orcid (for match?) + raw_name = StringField('Display Name') + role = SelectField(choices=role_type_options) + +class ReleaseEntityForm(EntityEditForm): + """ + TODO: + - field types: fatcat id + - date + """ + title = StringField('Title', [validators.InputRequired()]) + original_title = StringField('Original Title') + work_id = StringField('Work FCID') + container_id = StringField('Container FCID') + release_type = SelectField(choices=release_type_options) + release_status = SelectField(choices=release_status_options) + release_date = DateField('Release Date', + [validators.Optional(True)]) + #release_year + doi = StringField('DOI', + [validators.Regexp('^10\..*\/.*', message="DOI must be valid")]) + wikidata_qid = StringField('Wikidata QID') + isbn13 = StringField('ISBN-13') + pmid = StringField('PubMed Id') + pmcid = StringField('PubMed Central Id') + #core_id + #arxiv_id + #jstor_id + volume = StringField('Volume') + issue = StringField('Issue') + pages = StringField('Pages') + publisher = StringField('Publisher (optional)') + language = StringField('Language (code)') + license_slug = StringField('License (slug)') + contribs = FieldList(FormField(ReleaseContribForm)) + #refs + #abstracts + diff --git a/python/fatcat_web/routes.py b/python/fatcat_web/routes.py index e2c5fc3a..81c4c5c1 100644 --- a/python/fatcat_web/routes.py +++ b/python/fatcat_web/routes.py @@ -11,6 +11,7 @@ from fatcat_web import app, api, auth_api, priv_api from fatcat_web.auth import handle_token_login, handle_logout, load_user, handle_ia_xauth from fatcat_web.cors import crossdomain from fatcat_web.search import * +from fatcat_web.forms import * ### Views ################################################################### @@ -311,22 +312,23 @@ def release_lookup(): abort(ae.status) return redirect('/release/{}'.format(resp.ident)) -@app.route('/release/create', methods=['GET']) -@login_required -def release_create_view(): - return render_template('release_create.html') - -@app.route('/release/create', methods=['POST']) +@app.route('/release/create', methods=['GET', 'POST']) @login_required def release_create(): - raise NotImplementedError - params = dict() - for k in request.form: - if k.startswith('release_'): - params[k[10:]] = request.form[k] - release = None - #edit = api.create_release(release, params=params) - #return redirect("/release/{}".format(edit.ident)) + form = ReleaseEntityForm() + if form.is_submitted(): + print("got form!") + print(form.errors) + if form.validate_on_submit(): + return redirect('/') + else: + print("didn't validate...") + if len(form.contribs) == 0: + form.contribs.append_entry() + form.contribs.append_entry() + form.contribs.append_entry() + form.contribs.append_entry() + return render_template('release_create.html', form=form) @app.route('/release//history', methods=['GET']) def release_history(ident): diff --git a/python/fatcat_web/templates/release_create.html b/python/fatcat_web/templates/release_create.html index ac8a8169..e3a0c9ab 100644 --- a/python/fatcat_web/templates/release_create.html +++ b/python/fatcat_web/templates/release_create.html @@ -1,212 +1,214 @@ {% extends "base.html" %} + +{% macro form_field_errors(field) -%} + {% if field.errors %} + + {% endif %} +{%- endmacro %} + +{% macro form_field_basic(field, div_classes="") -%} +
+ {{ field.label }} + {{ field() }} + {{ form_field_errors(field) }} +
+{%- endmacro %} + +{% macro form_field_inline(field, div_classes="") -%} +
+
+
+ {{ field.label }} +
+
+
+
+ {{ field() }} + {{ form_field_errors(field) }} +
+
+
+
+
+{%- endmacro %} + {% block body %}
-

Adding a New Thing

+

Create New Release Entity

-
-

The Basics

+ + {{ form.hidden_tag() }} -
- - -
+

Edit Meta

+ {{ form_field_inline(form.editgroup_id) }} + {{ form_field_inline(form.editgroup_description) }} + {{ form_field_inline(form.edit_description) }} -
- - +

The Basics

+
+
+
+
+ {{ form_field_basic(form.release_type) }} + {{ form_field_basic(form.release_status) }} +
+
+
- -