diff options
author | Frederick Muriuki Muriithi | 2024-09-03 16:49:36 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-09-03 16:51:28 -0500 |
commit | 795562b3855b2e4dca5632d53a922e84a2859bf0 (patch) | |
tree | 555a959e488941dadbef604add51feb609716290 /uploader/population | |
parent | f1add5f4ea332ddfb2e902fb8c38e88a1dbcf6a2 (diff) | |
download | gn-uploader-795562b3855b2e4dca5632d53a922e84a2859bf0.tar.gz |
View a specific population's details.
Diffstat (limited to 'uploader/population')
-rw-r--r-- | uploader/population/views.py | 24 |
1 files changed, 22 insertions, 2 deletions
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") |