aboutsummaryrefslogtreecommitdiff
path: root/uploader
diff options
context:
space:
mode:
Diffstat (limited to 'uploader')
-rw-r--r--uploader/__init__.py6
-rw-r--r--uploader/phenotypes/models.py7
-rw-r--r--uploader/phenotypes/views.py34
-rw-r--r--uploader/templates/phenotypes/bulk-edit-upload.html61
-rw-r--r--uploader/templates/phenotypes/view-dataset.html42
5 files changed, 137 insertions, 13 deletions
diff --git a/uploader/__init__.py b/uploader/__init__.py
index cae531b..4f3538c 100644
--- a/uploader/__init__.py
+++ b/uploader/__init__.py
@@ -6,6 +6,7 @@ from pathlib import Path
from flask import Flask, request
from flask_session import Session
+from cachelib import FileSystemCache
from uploader.oauth2.client import user_logged_in, authserver_authorise_uri
@@ -69,6 +70,11 @@ def create_app():
# Silently ignore secrets if the file does not exist.
app.config.from_pyfile(secretsfile)
+ app.config["SESSION_CACHELIB"] = FileSystemCache(
+ cache_dir=Path(app.config["SESSION_FILESYSTEM_CACHE_PATH"]).absolute(),
+ threshold=int(app.config["SESSION_FILESYSTEM_CACHE_THRESHOLD"]),
+ default_timeout=int(app.config["SESSION_FILESYSTEM_CACHE_TIMEOUT"]))
+
setup_logging(app)
# setup jinja2 symbols
diff --git a/uploader/phenotypes/models.py b/uploader/phenotypes/models.py
index ce7720c..4a229e6 100644
--- a/uploader/phenotypes/models.py
+++ b/uploader/phenotypes/models.py
@@ -262,8 +262,11 @@ def phenotypes_data_by_ids(
) -> tuple[dict, ...]:
"""Fetch all phenotype data, filtered by the `inbred_pheno_xref` mapping."""
_paramstr = ",".join(["(%s, %s, %s)"] * len(inbred_pheno_xref))
- _query = ("SELECT pheno.*, pxr.*, pd.*, str.*, iset.InbredSetCode "
- "FROM Phenotype AS pheno "
+ _query = ("SELECT "
+ "pub.PubMed_ID, pheno.*, pxr.*, pd.*, str.*, iset.InbredSetCode "
+ "FROM Publication AS pub "
+ "RIGHT JOIN PublishXRef AS pxr0 ON pub.Id=pxr0.PublicationId "
+ "INNER JOIN Phenotype AS pheno ON pxr0.PhenotypeId=pheno.id "
"INNER JOIN PublishXRef AS pxr ON pheno.Id=pxr.PhenotypeId "
"INNER JOIN PublishData AS pd ON pxr.DataId=pd.Id "
"INNER JOIN Strain AS str ON pd.StrainId=str.Id "
diff --git a/uploader/phenotypes/views.py b/uploader/phenotypes/views.py
index 407493c..a50a8e7 100644
--- a/uploader/phenotypes/views.py
+++ b/uploader/phenotypes/views.py
@@ -866,16 +866,17 @@ def process_phenotype_data_for_download(pheno: dict) -> dict:
}
}
+
@phenotypesbp.route(
"<int:species_id>/populations/<int:population_id>/phenotypes/datasets"
- "/<int:dataset_id>/download",
+ "/<int:dataset_id>/edit-download",
methods=["POST"])
@require_login
@with_dataset(
species_redirect_uri="species.populations.phenotypes.index",
population_redirect_uri="species.populations.phenotypes.select_population",
redirect_uri="species.populations.phenotypes.list_datasets")
-def download_phenotype_data(# pylint: disable=[unused-argument]
+def edit_download_phenotype_data(# pylint: disable=[unused-argument]
species: dict,
population: dict,
dataset: dict,
@@ -919,7 +920,8 @@ def download_phenotype_data(# pylint: disable=[unused-argument]
"Pre_publication_abbreviation",
"Pre_publication_description",
"Original_description",
- "Post_publication_abbreviation"
+ "Post_publication_abbreviation",
+ "PubMed_ID"
] + samples_list,
dialect="excel-tab")
writer.writeheader()
@@ -931,3 +933,29 @@ def download_phenotype_data(# pylint: disable=[unused-argument]
mimetype="text/csv",
as_attachment=True,
download_name=secure_filename(f"{dataset['Name']}_data"))
+
+
+@phenotypesbp.route(
+ "<int:species_id>/populations/<int:population_id>/phenotypes/datasets"
+ "/<int:dataset_id>/edit-upload",
+ methods=["GET", "POST"])
+@require_login
+@with_dataset(
+ species_redirect_uri="species.populations.phenotypes.index",
+ population_redirect_uri="species.populations.phenotypes.select_population",
+ redirect_uri="species.populations.phenotypes.list_datasets")
+def edit_upload_phenotype_data(# pylint: disable=[unused-argument]
+ species: dict,
+ population: dict,
+ dataset: dict,
+ **kwargs
+):
+ if request.method == "GET":
+ return render_template(
+ "phenotypes/bulk-edit-upload.html",
+ species=species,
+ population=population,
+ dataset=dataset,
+ activelink="edit-phenotype")
+
+ return "NOT Implemented: Would do actual edit."
diff --git a/uploader/templates/phenotypes/bulk-edit-upload.html b/uploader/templates/phenotypes/bulk-edit-upload.html
new file mode 100644
index 0000000..926bcf5
--- /dev/null
+++ b/uploader/templates/phenotypes/bulk-edit-upload.html
@@ -0,0 +1,61 @@
+{%extends "phenotypes/base.html"%}
+{%from "flash_messages.html" import flash_all_messages%}
+{%from "macro-table-pagination.html" import table_pagination%}
+{%from "populations/macro-display-population-card.html" import display_population_card%}
+
+{%block title%}Phenotypes{%endblock%}
+
+{%block pagetitle%}Phenotypes{%endblock%}
+
+{%block lvl4_breadcrumbs%}
+<li {%if activelink=="view-dataset"%}
+ class="breadcrumb-item active"
+ {%else%}
+ class="breadcrumb-item"
+ {%endif%}>
+ <a href="{{url_for('species.populations.phenotypes.view_dataset',
+ species_id=species.SpeciesId,
+ population_id=population.Id,
+ dataset_id=dataset.Id)}}">View</a>
+</li>
+{%endblock%}
+
+{%block contents%}
+<div class="row">
+ <p>Upload the edited file you downloaded and edited.</p>
+</div>
+
+<div class="row">
+ <form id="frm-bulk-edit-upload"
+ class="form-horizontal"
+ method="POST"
+ action="{{url_for(
+ 'species.populations.phenotypes.edit_upload_phenotype_data',
+ species_id=species.SpeciesId,
+ population_id=population.Id,
+ dataset_id=dataset.Id)}}"
+ enctype="multipart/form-data">
+
+ <div class="form-group row">
+ <label for="file-upload-bulk-edit-upload"
+ class="form-label col-form-label col-sm-2">
+ Edited File</label>
+ <div class="col-sm-10">
+ <input id="file-upload-bulk-edit-upload"
+ name="file_upload_bulk_edit_upload"
+ class="form-control"
+ type="file"
+ required="required" />
+ </div>
+ </div>
+
+ <input type="submit" class="btn btn-primary"
+ value="upload to edit" />
+
+ </form>
+</div>
+{%endblock%}
+
+
+{%block javascript%}
+{%endblock%}
diff --git a/uploader/templates/phenotypes/view-dataset.html b/uploader/templates/phenotypes/view-dataset.html
index fa1044b..21563d6 100644
--- a/uploader/templates/phenotypes/view-dataset.html
+++ b/uploader/templates/phenotypes/view-dataset.html
@@ -147,6 +147,8 @@
},
{
text: "Bulk Edit (Download Data)",
+ className: "btn btn-info btn-bulk-edit",
+ titleAttr: "Click to download data for editing.",
action: (event, dt, node, config) => {
var phenoids = [];
var selected = dt.rows({selected: true, page: "all"}).data();
@@ -160,10 +162,23 @@
alert("No record selected. Nothing to do!");
return false;
}
+
+ $(".btn-bulk-edit").prop("disabled", true);
+ $(".btn-bulk-edit").addClass("d-none");
+ var spinner = $(
+ "<div id='bulk-edit-spinner' class='spinner-grow text-info'>");
+ spinner_content = $(
+ "<span class='visually-hidden'>");
+ spinner_content.html(
+ "Downloading data &hellip;");
+ spinner.append(spinner_content)
+ $(".btn-bulk-edit").parent().append(
+ spinner);
+
$.ajax(
(`/species/${species_id}/populations/` +
`${population_id}/phenotypes/datasets/` +
- `${dataset_id}/download`),
+ `${dataset_id}/edit-download`),
{
method: "POST",
data: JSON.stringify(phenoids),
@@ -185,19 +200,30 @@
console.log("Experienced an error: ", textStatus);
console.log("The ERROR: ", errorThrown);
},
+ complete: (jqXHR, textStatus) => {
+ $("#bulk-edit-spinner").remove();
+ $(".btn-bulk-edit").removeClass(
+ "d-none");
+ $(".btn-bulk-edit").prop(
+ "disabled", false);
+ },
contentType: "application/json"
});
- },
- className: "btn btn-info",
- titleAttr: "Click to download data for editing."
+ }
},
{
text: "Bulk Edit (Upload Data)",
+ className: "btn btn-info btn-bulk-edit",
+ titleAttr: "Click to upload edited data you got by clicking the `Bulk Edit (Download Data)` button.",
action: (event, dt, node, config) => {
- alert("Not implemented yet!")
- },
- className: "btn btn-info",
- titleAttr: "Click to upload edited data you got by clicking the `Bulk Edit (Download Data)` button."
+ window.location.assign(
+ `${window.location.protocol}//` +
+ `${window.location.host}` +
+ `/species/${species_id}` +
+ `/populations/${population_id}` +
+ `/phenotypes/datasets/${dataset_id}` +
+ `/edit-upload`)
+ }
}
]
},