diff options
| author | Frederick Muriuki Muriithi | 2026-04-09 09:06:57 -0500 |
|---|---|---|
| committer | Frederick Muriuki Muriithi | 2026-04-09 09:06:57 -0500 |
| commit | 3fdbad1fe6b83229bb0641377130f1364624d059 (patch) | |
| tree | 755bdecd6f7d937049fdeeb65c224e44d8a900b1 | |
| parent | 7c241531b4dae994173de14691c299ee1f81106c (diff) | |
| download | gn-uploader-3fdbad1fe6b83229bb0641377130f1364624d059.tar.gz | |
Prompt user for a name for the resource object.
| -rw-r--r-- | scripts/load_phenotypes_to_db.py | 29 | ||||
| -rw-r--r-- | uploader/phenotypes/views.py | 10 | ||||
| -rw-r--r-- | uploader/templates/phenotypes/review-job-data.html | 37 |
3 files changed, 64 insertions, 12 deletions
diff --git a/scripts/load_phenotypes_to_db.py b/scripts/load_phenotypes_to_db.py index e303bb3..9b70fed 100644 --- a/scripts/load_phenotypes_to_db.py +++ b/scripts/load_phenotypes_to_db.py @@ -5,7 +5,6 @@ import json import time import logging import argparse -import datetime from pathlib import Path from zipfile import ZipFile from typing import Any, Iterable @@ -198,13 +197,14 @@ save_phenotypes_n = partial(save_numeric_data, def update_auth(# pylint: disable=[too-many-locals,too-many-positional-arguments,too-many-arguments] - authserver, - token, + auth_details, + resource_details, species, population, dataset, xrefdata): """Grant the user access to their data.""" + authserver, token = auth_details _tries = 0 _delay = 1 headers = { @@ -259,14 +259,12 @@ def update_auth(# pylint: disable=[too-many-locals,too-many-positional-arguments def __create_resource__(user, linkeddata, category): logger.debug("… creating authorisation resource object") - now = datetime.datetime.now().isoformat() return mrequests.post( authserveruri("/auth/resource/create"), headers=headers, json={ + **resource_details, "resource_category": category["resource_category_id"], - "resource_name": (f"{user['email']}—{dataset['Name']}—{now}—" - f"{len(xrefdata)} phenotypes"), "public": "off" }).then(lambda cr_results: (user, linkeddata, cr_results)) @@ -516,8 +514,23 @@ if __name__ == "__main__": # Update authorisations (break this down) — maybe loop until it works? logger.info("Updating authorisation.") _job_metadata = job["metadata"] - return update_auth(_job_metadata["authserver"], - _job_metadata["token"], + + def __parse_resource_details__(meta) -> dict: + _key_mappings_ = { + "data_description": "description", + } + return { + "resource_name": _job_metadata["dataname"], + "resource_metadata": { + rkey: meta[mkey] + for mkey, rkey in _key_mappings_.items() + if mkey in meta + } + } + + return update_auth((_job_metadata["authserver"], + _job_metadata["token"]), + __parse_resource_details__(_job_metadata), *db_results) diff --git a/uploader/phenotypes/views.py b/uploader/phenotypes/views.py index 23bc682..9cacf61 100644 --- a/uploader/phenotypes/views.py +++ b/uploader/phenotypes/views.py @@ -662,6 +662,8 @@ def review_job_data( conn, int(_job_metadata["publicationid"])) if _job_metadata.get("publicationid") else None), + user=session.user_details(), + timestamp=datetime.datetime.now().isoformat(), activelink="add-phenotypes") @@ -741,9 +743,15 @@ def load_data_to_database( "publication_id": _meta["publicationid"], "authserver": oauth2client.authserver_uri(), "token": token["access_token"], + "dataname": request.form["data_name"].strip(), "success_handler": ( "uploader.phenotypes.views" - ".load_phenotypes_success_handler") + ".load_phenotypes_success_handler"), + **{ + key: request.form[key] + for key in ("data_description",) + if key in request.form.keys() + } }, external_id=session.logged_in_user_id()) ).then( diff --git a/uploader/templates/phenotypes/review-job-data.html b/uploader/templates/phenotypes/review-job-data.html index c8355b2..0e8f119 100644 --- a/uploader/templates/phenotypes/review-job-data.html +++ b/uploader/templates/phenotypes/review-job-data.html @@ -70,6 +70,9 @@ {%endif%} {%endfor%} </ul> +</div> + +<div class="row"> <form id="frm-review-phenotype-data" method="POST" @@ -78,10 +81,38 @@ population_id=population.Id, dataset_id=dataset.Id)}}"> <input type="hidden" name="data-qc-job-id" value="{{job.jobid}}" /> - <input type="submit" - value="continue" - class="btn btn-primary" /> + <div class="form-group"> + <label for="txt-data-name">data name</label> + <input type="text" + id="txt-data-name" + class="form-control" + name="data_name" + title="A short, descriptive name for this data." + placeholder="{{user.email}} - {{dataset.Name}} - {{timestamp}}" + value="{{user.email}} - {{dataset.Name}} - {{timestamp}}" + required="required"> + <span class="form-text text-muted"> + This is a short, descriptive name for the data. It is useful to humans, + enabling them identify what traits each data "resource" wraps around. + </span> + </div> + + {%if view_under_construction%} + <div class="form-group"> + <label for="txt-data-description">data description</label> + <textarea id="txt-data-description" + class="form-control" + name="data_description" + title="A longer description for this data." + rows="5"></textarea> + <span class="form-text text-muted"> + </span> + </div> + {%endif%} + + <button type="submit" class="btn btn-primary">continue</button> </form> + </div> {%else%} <div class="row"> |
