From 7e54ea61c374e15df31c41c1ca87a001acd85242 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 17 Sep 2024 12:46:31 -0500 Subject: UI Improvements: Enumerate data in tables. --- uploader/datautils.py | 7 +++++++ uploader/population/views.py | 4 +++- uploader/samples/views.py | 6 +++--- uploader/species/views.py | 4 ++-- uploader/templates/populations/list-populations.html | 2 ++ uploader/templates/samples/list-samples.html | 2 ++ uploader/templates/species/list-species.html | 2 ++ 7 files changed, 21 insertions(+), 6 deletions(-) diff --git a/uploader/datautils.py b/uploader/datautils.py index b95a9e0..2c2a3dc 100644 --- a/uploader/datautils.py +++ b/uploader/datautils.py @@ -1,7 +1,14 @@ """Generic data utilities: Rename module.""" import math +from typing import Sequence from functools import reduce +def enumerate_sequence(seq: Sequence[dict]) -> Sequence[dict]: + """Enumerate sequence beginning at 1""" + return tuple({**item, "sequence_number": seqno} + for seqno, item in enumerate(seq, start=1)) + + def order_by_family(items: tuple[dict, ...], family_key: str = "Family", order_key: str = "FamilyOrderId") -> list: diff --git a/uploader/population/views.py b/uploader/population/views.py index 5136ee0..39a5762 100644 --- a/uploader/population/views.py +++ b/uploader/population/views.py @@ -19,6 +19,7 @@ from uploader.ui import make_template_renderer from uploader.authorisation import require_login from uploader.genotypes.views import genotypesbp from uploader.db_utils import database_connection +from uploader.datautils import enumerate_sequence from uploader.species.models import (all_species, species_by_id, order_species_by_family) @@ -64,7 +65,8 @@ def list_species_populations(species_id: int): return render_template( "populations/list-populations.html", species=species, - populations=populations_by_species(conn, species_id), + populations=enumerate_sequence(populations_by_species( + conn, species_id)), activelink="list-populations") diff --git a/uploader/samples/views.py b/uploader/samples/views.py index 4332c21..fd3c601 100644 --- a/uploader/samples/views.py +++ b/uploader/samples/views.py @@ -19,9 +19,9 @@ from flask import ( from uploader import jobs from uploader.files import save_file -from uploader.datautils import order_by_family from uploader.authorisation import require_login from uploader.input_validation import is_integer_input +from uploader.datautils import order_by_family, enumerate_sequence from uploader.db_utils import ( with_db_connection, database_connection, @@ -107,8 +107,8 @@ def list_samples(species_id: int, population_id: int): "species.populations.samples.select_population", species_id=species_id)) - all_samples = samples_by_species_and_population( - conn, species_id, population_id) + all_samples = enumerate_sequence(samples_by_species_and_population( + conn, species_id, population_id)) total_samples = len(all_samples) offset = int(request.args.get("from") or 0) if offset < 0: diff --git a/uploader/species/views.py b/uploader/species/views.py index 55b0dd3..08d3728 100644 --- a/uploader/species/views.py +++ b/uploader/species/views.py @@ -8,11 +8,11 @@ from flask import (flash, current_app as app) from uploader.population import popbp -from uploader.datautils import order_by_family from uploader.ui import make_template_renderer from uploader.db_utils import database_connection from uploader.oauth2.client import oauth2_get, oauth2_post from uploader.authorisation import require_login, require_token +from uploader.datautils import order_by_family, enumerate_sequence from .models import (all_species, save_species, @@ -31,7 +31,7 @@ def list_species(): """List and display all the species in the database.""" with database_connection(app.config["SQL_URI"]) as conn: return render_template("species/list-species.html", - allspecies=all_species(conn)) + allspecies=enumerate_sequence(all_species(conn))) @speciesbp.route("/", methods=["GET"]) @require_login diff --git a/uploader/templates/populations/list-populations.html b/uploader/templates/populations/list-populations.html index c83c18c..7c7145f 100644 --- a/uploader/templates/populations/list-populations.html +++ b/uploader/templates/populations/list-populations.html @@ -51,6 +51,7 @@ Populations for {{species.FullName}} + # Name Full Name Description @@ -60,6 +61,7 @@ {%for population in populations%} + {{population["sequence_number"]}} + # Name Auxilliary Name Symbol @@ -83,6 +84,7 @@ {%for sample in samples%} + {{sample.sequence_number}} {{sample.Name}} {{sample.Name2}} {{sample.Symbol or "-"}} diff --git a/uploader/templates/species/list-species.html b/uploader/templates/species/list-species.html index d3dae7f..85c9d40 100644 --- a/uploader/templates/species/list-species.html +++ b/uploader/templates/species/list-species.html @@ -29,6 +29,7 @@ Available Species + # Common Name Organism Name @@ -42,6 +43,7 @@ {%for species in allspecies%} + {{species["sequence_number"]}} {{species["SpeciesName"]}}