about summary refs log tree commit diff
path: root/uploader/phenotypes/views.py
diff options
context:
space:
mode:
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)