diff options
Diffstat (limited to 'uploader')
-rw-r--r-- | uploader/genotypes/models.py | 14 | ||||
-rw-r--r-- | uploader/genotypes/views.py | 4 | ||||
-rw-r--r-- | uploader/templates/genotypes/list-genotypes.html | 23 |
3 files changed, 22 insertions, 19 deletions
diff --git a/uploader/genotypes/models.py b/uploader/genotypes/models.py index 642caa6..29acd0b 100644 --- a/uploader/genotypes/models.py +++ b/uploader/genotypes/models.py @@ -41,12 +41,15 @@ def genotype_markers( return tuple(dict(row) for row in cursor.fetchall()) -def genotype_datasets( +def genotype_dataset( conn: mdb.Connection, species_id: int, population_id: int -) -> tuple[dict, ...]: - """Retrieve genotype datasets from the database.""" +) -> Optional[dict]: + """Retrieve genotype datasets from the database. + + Apparently, you should only ever have one genotype dataset for a population. + """ with conn.cursor(cursorclass=DictCursor) as cursor: cursor.execute( "SELECT gf.* FROM Species AS s INNER JOIN InbredSet AS iset " @@ -54,4 +57,7 @@ def genotype_datasets( "ON iset.Id=gf.InbredSetId " "WHERE s.Id=%s AND iset.Id=%s", (species_id, population_id)) - return tuple(dict(row) for row in cursor.fetchall()) + result = cursor.fetchone() + if bool(result): + return dict(result) + return None diff --git a/uploader/genotypes/views.py b/uploader/genotypes/views.py index 294da0e..8752b02 100644 --- a/uploader/genotypes/views.py +++ b/uploader/genotypes/views.py @@ -15,7 +15,7 @@ from uploader.population.models import (populations_by_species, population_by_species_and_id) from .models import (genotype_markers, - genotype_datasets, + genotype_dataset, genotype_markers_count, genocode_by_population) @@ -98,7 +98,7 @@ def list_genotypes(species_id: int, population_id: int): conn, population_id), total_markers=genotype_markers_count( conn, species_id), - datasets=genotype_datasets( + dataset=genotype_dataset( conn, species_id, population_id), activelink="list-genotypes") diff --git a/uploader/templates/genotypes/list-genotypes.html b/uploader/templates/genotypes/list-genotypes.html index 8afd591..3780f85 100644 --- a/uploader/templates/genotypes/list-genotypes.html +++ b/uploader/templates/genotypes/list-genotypes.html @@ -95,14 +95,8 @@ <p>The genotype data is organised under various genotype datasets. You can click on the link for the relevant dataset to view a little more information about it.</p> - <p>You can also create a new genotype dataset by clicking the button below. - <br /> - <a href="#create-new-genotype-dataset" - title="Create a new genotype dataset for the '{{population.FullName}}' population for the '{{species.FullName}}' species." - class="btn btn-primary"> - create new genotype dataset</a></p> - {%if datasets | length > 0%} + {%if dataset is defined %} <table class="table"> <thead> <tr> @@ -112,7 +106,6 @@ </thead> <tbody> - {%for dataset in datasets%} <tr> <td>{{dataset.Name}}</td> <td><a href="{{url_for('species.populations.genotypes.view_dataset', @@ -122,14 +115,18 @@ title="View details regarding and manage dataset '{{dataset.FullName}}'"> {{dataset.FullName}}</a></td> </tr> - {%endfor%} </tbody> </table> {%else%} - <p class="text-warning"> - <span class="glyphicon glyphicon-exclamation-sign"></span> - There are no genotype datasets to display, yet! - </p> + <p class="text-warning"> + <span class="glyphicon glyphicon-exclamation-sign"></span> + There is no genotype dataset defined for this population. + </p> + <p> + <a href="#create-new-genotype-dataset" + title="Create a new genotype dataset for the '{{population.FullName}}' population for the '{{species.FullName}}' species." + class="btn btn-primary"> + create new genotype dataset</a></p> {%endif%} </div> {%endblock%} |