From 1f165c34a6179f96b6de0c616f21a319e3c4ccce Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Wed, 20 Mar 2019 13:39:07 -0700 Subject: add wtforms deps --- python/Pipfile | 2 ++ python/Pipfile.lock | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/python/Pipfile b/python/Pipfile index e793ad96..9c108cba 100644 --- a/python/Pipfile +++ b/python/Pipfile @@ -24,6 +24,8 @@ Flask = ">=1" flask-uuid = "*" flask-debugtoolbar = "*" flask-login = "*" +flask-wtf = "*" +WTForms = "*" loginpass = "*" requests = ">=2" raven = { extras = ['flask'], version = "*" } diff --git a/python/Pipfile.lock b/python/Pipfile.lock index c4271c88..8b08d613 100644 --- a/python/Pipfile.lock +++ b/python/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "9b4f0371d2f2963acb915f4a3be7d46b1fb6923a099b79b2dd5d109c5b976a23" + "sha256": "f51694c4f6cfb984a07aca94d21f8803eaf381c72e3b35fabeb1fa68294216ba" }, "pipfile-spec": 6, "requires": { @@ -179,6 +179,14 @@ "index": "pypi", "version": "==0.2" }, + "flask-wtf": { + "hashes": [ + "sha256:5d14d55cfd35f613d99ee7cba0fc3fbbe63ba02f544d349158c14ca15561cc36", + "sha256:d9a9e366b32dcbb98ef17228e76be15702cd2600675668bca23f63a7947fd5ac" + ], + "index": "pypi", + "version": "==0.14.2" + }, "ftfy": { "hashes": [ "sha256:84a1614190173bb447ac9d581e50185c6aa35b538754b6bedaba0cc0f83d8e80", @@ -429,6 +437,14 @@ "sha256:ee11b0f0640c56fb491b43b38356c4b588b3202b415a1e03eacf1c5561c961cf" ], "version": "==0.15.0" + }, + "wtforms": { + "hashes": [ + "sha256:0cdbac3e7f6878086c334aa25dc5a33869a3954e9d1e015130d65a69309b3b61", + "sha256:e3ee092c827582c50877cdbd49e9ce6d2c5c1f6561f849b3b068c1b8029626f1" + ], + "index": "pypi", + "version": "==2.2.1" } }, "develop": { -- cgit v1.2.3 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 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 %} +
    + {% for err in field.errors %} +
  • {{ err }} + {% endfor %} +
+ {% 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) }} +
+
+
- -