From 1696242aa80f489a8ed4e5a01a30a1fd813dd4f3 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Mon, 30 Sep 2024 16:36:53 -0500 Subject: 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. --- uploader/phenotypes/views.py | 48 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'uploader/phenotypes/views.py') 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( + "/populations//phenotypes/datasets" + "//phenotype/", + 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) -- cgit v1.2.3