summaryrefslogtreecommitdiffstats
path: root/python/fatcat_web
diff options
context:
space:
mode:
Diffstat (limited to 'python/fatcat_web')
-rw-r--r--python/fatcat_web/forms.py42
-rw-r--r--python/fatcat_web/templates/release_edit.html26
2 files changed, 44 insertions, 24 deletions
diff --git a/python/fatcat_web/forms.py b/python/fatcat_web/forms.py
index 2efc84a3..ff885fcb 100644
--- a/python/fatcat_web/forms.py
+++ b/python/fatcat_web/forms.py
@@ -4,6 +4,8 @@ Note: in thoery could use, eg, https://github.com/christabor/swagger_wtforms,
but can't find one that is actually maintained.
"""
+import datetime
+
import toml
from flask_wtf import FlaskForm
from wtforms import SelectField, DateField, StringField, IntegerField, \
@@ -31,6 +33,16 @@ release_stage_options = [
('published', 'Published'),
('updated', 'Updated'),
]
+withdrawn_status_options = [
+ ('', 'Not Withdrawn (blank)'),
+ ('retracted', 'Retracted'),
+ ('withdrawn', 'Withdrawn'),
+ ('concern', 'Concern Noted'),
+ ('spam', 'Spam'),
+ ('legal', 'Legal Taketown'),
+ ('safety', 'Public Safety'),
+ ('national-security', 'National Security'),
+]
role_type_options = [
('author', 'Author'),
('editor', 'Editor'),
@@ -70,25 +82,13 @@ RELEASE_SIMPLE_ATTRS = ['title', 'original_title', 'work_id', 'container_id',
RELEASE_EXTID_ATTRS = ['doi', 'wikidata_qid', 'isbn13', 'pmid', 'pmcid']
-def valid_date(form, field):
- try:
- datetime.date.fromisoformat(field.data)
- except ValueError as ve:
- raise ValidationError(
- f"Date must be valid ISO format (like '2017-04-20'): {field.data}")
-
def valid_year(form, field):
- try:
- year = int(field.data)
- except ValueError as ve:
- raise ValidationError(
- f"Date must be valid ISO format (like '2017-04-20'): {field.data}")
- if year > datetime.date.today().year + 5:
+ if field.data > datetime.date.today().year + 5:
raise ValidationError(
- f"Year is too far in the future: {year}")
- if year < 10:
+ f"Year is too far in the future: {field.data}")
+ if field.data < 10:
raise ValidationError(
- f"Year is too far in the past: {year}")
+ f"Year is too far in the past: {field.data}")
def valid_2char_ascii(form, field):
if len(field.data) != 2 or len(field.data.encode('utf-8')) != 2 or not field.data.isalpha() or field.data != field.data.lower():
@@ -115,9 +115,13 @@ class ReleaseEntityForm(EntityEditForm):
choices=release_type_options,
default='')
release_stage = SelectField(choices=release_stage_options)
+ withdrawn_status = SelectField("Withdrawn Status",
+ [validators.Optional(True)],
+ choices=withdrawn_status_options,
+ default='')
release_date = DateField('Release Date',
- [validators.Optional(True), valid_date])
- release_year = DateField('Release Year',
+ [validators.Optional(True)])
+ release_year = IntegerField('Release Year',
[validators.Optional(True), valid_year])
doi = StringField('DOI',
[validators.Regexp(r'^10\..*\/.*', message="DOI must be valid"),
@@ -185,6 +189,8 @@ class ReleaseEntityForm(EntityEditForm):
if a == '':
a = None
setattr(re.ext_ids, extid_attr, a)
+ if self.release_date.data:
+ re.release_year = self.release_date.data.year
# bunch of complexity here to preserve old contrib metadata (eg,
# affiliation and extra) not included in current forms
# TODO: this may be broken; either way needs tests
diff --git a/python/fatcat_web/templates/release_edit.html b/python/fatcat_web/templates/release_edit.html
index 21c8cf68..50f73b8c 100644
--- a/python/fatcat_web/templates/release_edit.html
+++ b/python/fatcat_web/templates/release_edit.html
@@ -27,21 +27,22 @@
<br>
<h3 class="ui dividing header">The Basics</h3>
+
+ {{ edit_macros.form_field_inline(form.release_type, "required") }}
+ {{ edit_macros.form_field_inline(form.title, "required") }}
+ {{ edit_macros.form_field_inline(form.original_title) }}
+
<div class="ui grid">
<div class="three wide column" style="padding-bottom: 0px;"></div>
<div class="twelve wide column" style="padding-bottom: 0px;">
<div class="ui equal width fields">
- {{ edit_macros.form_field_basic(form.release_type, "required") }}
- {{ edit_macros.form_field_basic(form.release_stage) }}
+ {{ edit_macros.form_field_basic(form.release_year) }}
+ {{ edit_macros.form_field_basic(form.release_date) }}
</div>
</div>
<div class="one wide column" style="padding-bottom: 0px;"></div>
</div>
- {{ edit_macros.form_field_inline(form.title, "required") }}
- {{ edit_macros.form_field_inline(form.original_title) }}
- {{ edit_macros.form_field_inline(form.work_id) }}
- {{ edit_macros.form_field_inline(form.release_date) }}
<div class="ui grid">
<div class="three wide column" style="padding-bottom: 0px;"></div>
<div class="twelve wide column" style="padding-bottom: 0px;">
@@ -53,6 +54,19 @@
<div class="one wide column" style="padding-bottom: 0px;"></div>
</div>
+ <div class="ui grid">
+ <div class="three wide column" style="padding-bottom: 0px;"></div>
+ <div class="twelve wide column" style="padding-bottom: 0px;">
+ <div class="ui equal width fields">
+ {{ edit_macros.form_field_basic(form.release_stage) }}
+ {{ edit_macros.form_field_basic(form.withdrawn_status) }}
+ </div>
+ </div>
+ <div class="one wide column" style="padding-bottom: 0px;"></div>
+ </div>
+
+ {{ edit_macros.form_field_inline(form.work_id) }}
+
<br>
<h3 class="ui dividing header">Contributors</h3>
<div class="list-group" id="contrib_list" name="contrib_list">