From 795562b3855b2e4dca5632d53a922e84a2859bf0 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 3 Sep 2024 16:49:36 -0500 Subject: View a specific population's details. --- uploader/population/views.py | 24 +++++++- .../templates/populations/list-populations.html | 4 +- .../templates/populations/view-population.html | 70 ++++++++++++++++++++++ 3 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 uploader/templates/populations/view-population.html diff --git a/uploader/population/views.py b/uploader/population/views.py index 3be46d4..e21465c 100644 --- a/uploader/population/views.py +++ b/uploader/population/views.py @@ -14,7 +14,8 @@ from uploader.species.models import (all_species, order_species_by_family) from .models import (save_population, - populations_by_species) + populations_by_species, + population_by_species_and_id) __active_link__ = "populations" popbp = Blueprint("populations", __name__) @@ -117,4 +118,23 @@ def create_population(species_id: int): @require_login def view_population(species_id: int, population_id: int): """View the details of a population.""" - raise NotImplementedError("Please implement this too …") + with database_connection(app.config["SQL_URI"]) as conn: + species = species_by_id(conn, species_id) + population = population_by_species_and_id(conn, species_id, population_id) + error = False + + if not bool(species): + flash("You must select a species.", "alert-danger") + error = True + + if not bool(population): + flash("You must select a population.", "alert-danger") + error = True + + if error: + return redirect(url_for("species.populations.index")) + + return render_template("populations/view-population.html", + species=species, + population=population, + activelink="view-population") diff --git a/uploader/templates/populations/list-populations.html b/uploader/templates/populations/list-populations.html index c14a28c..c3ba180 100644 --- a/uploader/templates/populations/list-populations.html +++ b/uploader/templates/populations/list-populations.html @@ -59,7 +59,9 @@ {%for population in populations%}
+ Click any of the following links to use this population in performing the + subsequent operations. +
+ + +… maybe provide species details here, perhaps? …
+… maybe provide extra population details here, perhaps? …
+{%endblock%} -- cgit v1.2.3