aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bh20sequploader/bh20seq-options.yml16
-rw-r--r--bh20simplewebuploader/main.py37
-rw-r--r--bh20simplewebuploader/templates/form.html10
-rw-r--r--setup.py2
4 files changed, 57 insertions, 8 deletions
diff --git a/bh20sequploader/bh20seq-options.yml b/bh20sequploader/bh20seq-options.yml
new file mode 100644
index 0000000..02e911f
--- /dev/null
+++ b/bh20sequploader/bh20seq-options.yml
@@ -0,0 +1,16 @@
+# Contains suggested human-readable field values and their corresponding IRIs.
+# Keyed on the field names in the types in the schema. Relies on field names
+# being unique or at least using the same options in different containing
+# types.
+
+host_age_unit:
+ year: http://purl.obolibrary.org/obo/UO_0000036
+ month: http://purl.obolibrary.org/obo/UO_0000035
+ week: http://purl.obolibrary.org/obo/UO_0000035
+ day: http://purl.obolibrary.org/obo/UO_0000034
+ hour: http://purl.obolibrary.org/obo/UO_0000032
+
+host_sex:
+ Male: http://purl.obolibrary.org/obo/NCIT_C20197
+ Female: http://purl.obolibrary.org/obo/NCIT_C27993
+ unknown: http://purl.obolibrary.org/obo/NCIT_C17998
diff --git a/bh20simplewebuploader/main.py b/bh20simplewebuploader/main.py
index c7f63ea..c8fdc3f 100644
--- a/bh20simplewebuploader/main.py
+++ b/bh20simplewebuploader/main.py
@@ -60,14 +60,25 @@ def is_iri(string):
return string.startswith('http')
-def generate_form(schema):
+def generate_form(schema, options):
"""
- Linearize the schema and send a bunch of dicts.
+ Linearize the schema into a list of dicts.
+
Each dict either has a 'heading' (in which case we put a heading for a
form section in the template) or an 'id', 'label', 'type', and 'required'
- (in which case we make a form field in the template).
+ (in which case we make a form field in the template). Non-heading dicts
+ with type 'select' will have an 'options' field, with a list of (name,
+ value) tuples, and represent a form dropdown element.
+
+ Takes the deserialized metadata schema YAML, and also a deserialized YAML
+ of option values. The option values are keyed on (unscoped) field name in
+ the schema, and each is a dict of human readable option -> corresponding
+ IRI.
"""
+ print(schema)
+ print(options)
+
# Get the list of form components, one of which is the root
components = schema.get('$graph', [])
@@ -141,14 +152,27 @@ def generate_form(schema):
for item in walk_fields(field_type, parent_keys + [field_name], subtree_optional or optional):
yield item
else:
- # We know how to make a string input
+ # This is a leaf field. We need an input for it.
record = {}
record['id'] = '.'.join(parent_keys + [field_name])
record['label'] = name_to_label(field_name)
record['required'] = not optional and not subtree_optional
if ref_iri:
record['ref_iri'] = ref_iri
- if field_type == 'string':
+
+ print(field_name)
+
+ if field_name in options:
+ print("Has options: {}".format(options[field_name]))
+ # The field will be a 'select' type no matter what its real
+ # data type is.
+ record['type'] = 'select' # Not a real HTML input type. It's its own tag.
+ # We have a set of values to present
+ record['options'] = []
+ for name, value in options[field_name].items():
+ # Make a tuple for each one
+ record['options'].append((name, value))
+ elif field_type == 'string':
record['type'] = 'text' # HTML input type
elif field_type == 'int':
record['type'] = 'number'
@@ -161,7 +185,8 @@ def generate_form(schema):
# At startup, we need to load the metadata schema from the uploader module, so we can make a form for it
METADATA_SCHEMA = yaml.safe_load(pkg_resources.resource_stream("bh20sequploader", "bh20seq-schema.yml"))
-FORM_ITEMS = generate_form(METADATA_SCHEMA)
+METADATA_OPTION_DEFINITIONS = yaml.safe_load(pkg_resources.resource_stream("bh20sequploader", "bh20seq-options.yml"))
+FORM_ITEMS = generate_form(METADATA_SCHEMA, METADATA_OPTION_DEFINITIONS)
@app.route('/')
def send_form():
diff --git a/bh20simplewebuploader/templates/form.html b/bh20simplewebuploader/templates/form.html
index 9cfb60f..012b9c5 100644
--- a/bh20simplewebuploader/templates/form.html
+++ b/bh20simplewebuploader/templates/form.html
@@ -211,7 +211,6 @@
<div id="metadata_fill_form_spot">
<div id="metadata_fill_form">
- {{ record }}
{% for record in fields %}
{% if 'heading' in record %}
@@ -228,8 +227,17 @@
<a href="{{ record['ref_iri'] }}" title="More Info" target="_blank">?</a>
{% endif %}
</label>
+ {% if record['type'] == 'select' %}
+ <select id="{{ record['id'] }}" name="{{ record['id'] }}" {{ "required" if record['required'] else "" }}>
+ <option value="" selected>Choose one...</option>
+ {% for option in record['options'] %}
+ <option value="{{ option[1] }}">{{ option[0] }}</option>
+ {% endfor %}
+ </select>
+ {% else %}
<input type="{{ record['type'] }}" id="{{ record['id'] }}" name="{{ record['id'] }}" {{ "required" if record['required'] else "" }}>
{% endif %}
+ {% endif %}
{% if loop.index == loop.length %}
</div>
{% endif %}
diff --git a/setup.py b/setup.py
index 18e858e..0e91274 100644
--- a/setup.py
+++ b/setup.py
@@ -31,7 +31,7 @@ setup(
author_email="peter.amstutz@curii.com",
license="Apache 2.0",
packages=["bh20sequploader", "bh20seqanalyzer", "bh20simplewebuploader"],
- package_data={"bh20sequploader": ["bh20seq-schema.yml", "validation/formats"],
+ package_data={"bh20sequploader": ["bh20seq-schema.yml", "bh20seq-options.yml", "validation/formats"],
},
install_requires=install_requires,
extras_require={