From 2046919e5db5d1e7136f48641fe0adb701c145e4 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 3 Sep 2024 15:31:12 -0500 Subject: Put populations under species: improve hierarchy. Populations cannot exist without the species they are related to. This commit updates the URI hierarchy to reflect that expectation. --- uploader/__init__.py | 2 -- uploader/population/views.py | 14 +++++++------- uploader/species/views.py | 2 ++ uploader/templates/base.html | 4 ++-- uploader/templates/populations/base.html | 6 +++--- uploader/templates/populations/index.html | 2 +- uploader/templates/populations/list-populations.html | 4 ++-- uploader/templates/species/base.html | 4 ++-- uploader/templates/species/create-species.html | 2 +- uploader/templates/species/view-species.html | 2 +- 10 files changed, 21 insertions(+), 21 deletions(-) diff --git a/uploader/__init__.py b/uploader/__init__.py index 5028f79..347f170 100644 --- a/uploader/__init__.py +++ b/uploader/__init__.py @@ -10,7 +10,6 @@ from flask_session import Session from uploader.oauth2.client import user_logged_in, authserver_authorise_uri from .base_routes import base -from .population import popbp from .species import speciesbp from .dbinsert import dbinsertbp from .oauth2.views import oauth2 @@ -84,7 +83,6 @@ def create_app(): app.register_blueprint(base, url_prefix="/") app.register_blueprint(oauth2, url_prefix="/oauth2") app.register_blueprint(speciesbp, url_prefix="/species") - app.register_blueprint(popbp, url_prefix="/populations") app.register_blueprint(dbinsertbp, url_prefix="/dbinsert") app.register_blueprint(exprdatabp, url_prefix="/expression-data") diff --git a/uploader/population/views.py b/uploader/population/views.py index cd5e20b..3be46d4 100644 --- a/uploader/population/views.py +++ b/uploader/population/views.py @@ -21,7 +21,7 @@ popbp = Blueprint("populations", __name__) render_template = make_template_renderer("populations") -@popbp.route("/", methods=["GET", "POST"]) +@popbp.route("/populations", methods=["GET", "POST"]) @require_login def index(): """Entry point for populations.""" @@ -33,11 +33,11 @@ def index(): species = species_by_id(conn, request.args.get("species_id")) if not bool(species): flash("Invalid species identifier provided!", "alert-danger") - return redirect(url_for("populations.index")) - return redirect(url_for("populations.list_species_populations", + return redirect(url_for("species.populations.index")) + return redirect(url_for("species.populations.list_species_populations", species_id=species["SpeciesId"])) -@popbp.route("/", methods=["GET"]) +@popbp.route("//populations", methods=["GET"]) @require_login def list_species_populations(species_id: int): """List a particular species' populations.""" @@ -45,7 +45,7 @@ def list_species_populations(species_id: int): species = species_by_id(conn, species_id) if not bool(species): flash("No species was found for given ID.", "alert-danger") - return redirect(url_for("populations.index")) + return redirect(url_for("species.populations.index")) return render_template( "populations/list-populations.html", species=species, @@ -95,7 +95,7 @@ def create_population(species_id: int): error = True if error: - return redirect(url_for("populations.create_population", + return redirect(url_for("species.populations.create_population", **dict(request.args))) new_population = save_population(conn, { @@ -107,7 +107,7 @@ def create_population(species_id: int): "Description": request.form.get("description") or None }) - return redirect(url_for("populations.view_population", + return redirect(url_for("species.populations.view_population", species_id=species["SpeciesId"], population_id=new_population["InbredSetId"])) diff --git a/uploader/species/views.py b/uploader/species/views.py index 6f4d51f..77406a1 100644 --- a/uploader/species/views.py +++ b/uploader/species/views.py @@ -6,6 +6,7 @@ from flask import (flash, Blueprint, current_app as app) +from uploader.population import popbp from uploader.ui import make_template_renderer from uploader.authorisation import require_login from uploader.db_utils import database_connection @@ -14,6 +15,7 @@ from .models import all_species, save_species, species_by_id speciesbp = Blueprint("species", __name__) +speciesbp.register_blueprint(popbp, url_prefix="/") render_template = make_template_renderer("species") diff --git a/uploader/templates/base.html b/uploader/templates/base.html index fd6010b..d9696d0 100644 --- a/uploader/templates/base.html +++ b/uploader/templates/base.html @@ -45,7 +45,7 @@ @@ -63,7 +63,7 @@ {%endif%}> Home - {%block breadcrumbs%}{%endblock%} + {%block lvl1_breadcrumbs%}{%endblock%} diff --git a/uploader/templates/populations/base.html b/uploader/templates/populations/base.html index 1033927..d763fc1 100644 --- a/uploader/templates/populations/base.html +++ b/uploader/templates/populations/base.html @@ -1,12 +1,12 @@ -{%extends "base.html"%} +{%extends "species/base.html"%} -{%block breadcrumbs%} +{%block lvl2_breadcrumbs%} {%block lvl3_breadcrumbs%}{%endblock%} {%endblock%} diff --git a/uploader/templates/populations/index.html b/uploader/templates/populations/index.html index 14cf547..061ca1d 100644 --- a/uploader/templates/populations/index.html +++ b/uploader/templates/populations/index.html @@ -11,6 +11,6 @@
To continue, you need to select the species: - {{select_species_form(url_for("populations.index"), species)}} + {{select_species_form(url_for("species.populations.index"), species)}}
{%endblock%} diff --git a/uploader/templates/populations/list-populations.html b/uploader/templates/populations/list-populations.html index bf6cf98..c14a28c 100644 --- a/uploader/templates/populations/list-populations.html +++ b/uploader/templates/populations/list-populations.html @@ -12,7 +12,7 @@ {%else%} class="breadcrumb-item" {%endif%}> - List {%endblock%} @@ -35,7 +35,7 @@ exist, click on the "Create Population" button below to create a new one.

- diff --git a/uploader/templates/species/base.html b/uploader/templates/species/base.html index 8fb697d..04391db 100644 --- a/uploader/templates/species/base.html +++ b/uploader/templates/species/base.html @@ -1,6 +1,6 @@ {%extends "base.html"%} -{%block breadcrumbs%} +{%block lvl1_breadcrumbs%}

-{%block lvl3_breadcrumbs%}{%endblock%} +{%block lvl2_breadcrumbs%}{%endblock%} {%endblock%} diff --git a/uploader/templates/species/create-species.html b/uploader/templates/species/create-species.html index 678b010..1bc3b61 100644 --- a/uploader/templates/species/create-species.html +++ b/uploader/templates/species/create-species.html @@ -5,7 +5,7 @@ {%block pagetitle%}Create Species{%endblock%} -{%block lvl3_breadcrumbs%} +{%block lvl2_breadcrumbs%}