aboutsummaryrefslogtreecommitdiff
path: root/uploader/species
diff options
context:
space:
mode:
Diffstat (limited to 'uploader/species')
-rw-r--r--uploader/species/models.py28
-rw-r--r--uploader/species/views.py7
2 files changed, 20 insertions, 15 deletions
diff --git a/uploader/species/models.py b/uploader/species/models.py
index 1abed6d..51f941c 100644
--- a/uploader/species/models.py
+++ b/uploader/species/models.py
@@ -28,7 +28,7 @@ def order_species_by_family(species: tuple[dict, ...]) -> list:
**ordered,
_key: ordered.get(_key, tuple()) + (current,)
}
- ordered = reduce(__order__, species, {})
+ ordered = reduce(__order__, species, {})# type: ignore[var-annotated]
return sorted(tuple(ordered.items()), key=lambda item: item[0][0])
@@ -47,7 +47,7 @@ def save_species(conn: mdb.Connection,
common_name: str,
scientific_name: str,
family: str,
- taxon_id: Optional[str] = None) -> int:
+ taxon_id: Optional[str] = None) -> dict:
"""
Save a new species to the database.
@@ -58,14 +58,14 @@ def save_species(conn: mdb.Connection,
common_name: The species' common name.
scientific_name; The species' scientific name.
"""
- genus, species = scientific_name.split(" ")
+ genus, species_name = scientific_name.split(" ")
families = species_families(conn)
with conn.cursor() as cursor:
cursor.execute("SELECT MAX(OrderId) FROM Species")
species = {
"common_name": common_name,
"common_name_lower": common_name.lower(),
- "menu_name": f"{common_name} ({genus[0]}. {species.lower()})",
+ "menu_name": f"{common_name} ({genus[0]}. {species_name.lower()})",
"scientific_name": scientific_name,
"family": family,
"family_order": families[family],
@@ -91,13 +91,15 @@ def save_species(conn: mdb.Connection,
}
-def update_species(conn: mdb.Connection,
- species_id: int,
- common_name: str,
- scientific_name: str,
- family: str,
- family_order: int,
- species_order: int):
+def update_species(# pylint: disable=[too-many-arguments]
+ conn: mdb.Connection,
+ species_id: int,
+ common_name: str,
+ scientific_name: str,
+ family: str,
+ family_order: int,
+ species_order: int
+):
"""Update a species' details.
Parameters
@@ -114,12 +116,12 @@ def update_species(conn: mdb.Connection,
species_order: The ordering of this species in relation to others
"""
with conn.cursor(cursorclass=DictCursor) as cursor:
- genus, species = scientific_name.split(" ")
+ genus, species_name = scientific_name.split(" ")
species = {
"species_id": species_id,
"common_name": common_name,
"common_name_lower": common_name.lower(),
- "menu_name": f"{common_name} ({genus[0]}. {species.lower()})",
+ "menu_name": f"{common_name} ({genus[0]}. {species_name.lower()})",
"scientific_name": scientific_name,
"family": family,
"family_order": family_order,
diff --git a/uploader/species/views.py b/uploader/species/views.py
index 55b0dd3..10715a5 100644
--- a/uploader/species/views.py
+++ b/uploader/species/views.py
@@ -8,11 +8,12 @@ from flask import (flash,
current_app as app)
from uploader.population import popbp
-from uploader.datautils import order_by_family
+from uploader.platforms import platformsbp
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,
@@ -23,15 +24,17 @@ from .models import (all_species,
speciesbp = Blueprint("species", __name__)
speciesbp.register_blueprint(popbp, url_prefix="/")
+speciesbp.register_blueprint(platformsbp, url_prefix="/")
render_template = make_template_renderer("species")
@speciesbp.route("/", methods=["GET"])
+@require_login
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("/<int:species_id>", methods=["GET"])
@require_login