aboutsummaryrefslogtreecommitdiff
path: root/uploader/phenotypes/views.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-09-30 16:36:53 -0500
committerFrederick Muriuki Muriithi2024-09-30 16:36:53 -0500
commit1696242aa80f489a8ed4e5a01a30a1fd813dd4f3 (patch)
treeb4549590c2320dc70dee96a9a03c179f4683e8f9 /uploader/phenotypes/views.py
parent35419644dd9093630649093a4e2fba06c19ffb0c (diff)
downloadgn-uploader-1696242aa80f489a8ed4e5a01a30a1fd813dd4f3.tar.gz
Initialise views for a specific phenotype
Each phenotype is independent, of all others, and they are only put into datasets mostly for easy coralling of phenotypes related to a specific populations. As such, the system will probably need to provide a way to view (and possibly edit) each phenotype independent of all the others. This also fits in with the auth.
Diffstat (limited to 'uploader/phenotypes/views.py')
-rw-r--r--uploader/phenotypes/views.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/uploader/phenotypes/views.py b/uploader/phenotypes/views.py
index a79e863..7fc3b08 100644
--- a/uploader/phenotypes/views.py
+++ b/uploader/phenotypes/views.py
@@ -9,15 +9,18 @@ from flask import (flash,
render_template,
current_app as app)
+from uploader.oauth2.client import oauth2_post
from uploader.authorisation import require_login
from uploader.db_utils import database_connection
from uploader.species.models import all_species, species_by_id
+from uploader.monadic_requests import make_either_error_handler
from uploader.request_checks import with_species, with_population
from uploader.datautils import safe_int, order_by_family, enumerate_sequence
from uploader.population.models import (populations_by_species,
population_by_species_and_id)
from .models import (dataset_by_id,
+ phenotype_by_id,
phenotypes_count,
dataset_phenotypes,
datasets_by_population)
@@ -168,3 +171,48 @@ def view_dataset(# pylint: disable=[unused-argument]
limit=count),
start=start_at+1),
activelink="view-dataset")
+
+
+@phenotypesbp.route(
+ "<int:species_id>/populations/<int:population_id>/phenotypes/datasets"
+ "/<int:dataset_id>/phenotype/<xref_id>",
+ methods=["GET"])
+@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 view_phenotype(# pylint: disable=[unused-argument]
+ species: dict,
+ population: dict,
+ dataset: dict,
+ xref_id: int,
+ **kwargs
+):
+ """View an individual phenotype from the dataset."""
+ with database_connection(app.config["SQL_URI"]) as conn:
+ return oauth2_post(
+ "/auth/resource/phenotypes/individual/linked-resource",
+ json={
+ "species_id": species["SpeciesId"],
+ "population_id": population["Id"],
+ "dataset_id": dataset["Id"],
+ "xref_id": xref_id
+ }
+ ).then(
+ lambda resource: render_template(
+ "phenotypes/view-phenotype.html",
+ species=species,
+ population=population,
+ dataset=dataset,
+ phenotype=phenotype_by_id(conn,
+ species["SpeciesId"],
+ population["Id"],
+ dataset["Id"],
+ xref_id),
+ resource=resource,
+ activelink="view-phenotype")
+ ).either(
+ make_either_error_handler(
+ "There was an error fetching the roles and privileges."),
+ lambda resp: resp)