diff options
author | Frederick Muriuki Muriithi | 2024-09-25 12:09:46 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-09-25 12:11:58 -0500 |
commit | 3e028bf0e9f8239b552bcd4b2d6133bb7965abd9 (patch) | |
tree | 9a58c1b95748c99c04bec5e5f34d70f7070af287 /uploader/genotypes/views.py | |
parent | 44a07c95a3ae77441e1b45b9f5fba9c6d77a2871 (diff) | |
download | gn-uploader-3e028bf0e9f8239b552bcd4b2d6133bb7965abd9.tar.gz |
Create new genotype datasets.
Diffstat (limited to 'uploader/genotypes/views.py')
-rw-r--r-- | uploader/genotypes/views.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/uploader/genotypes/views.py b/uploader/genotypes/views.py index 41cd21e..f79caba 100644 --- a/uploader/genotypes/views.py +++ b/uploader/genotypes/views.py @@ -1,4 +1,5 @@ """Views for the genotypes.""" +from MySQLdb.cursors import DictCursor from flask import (flash, request, url_for, @@ -18,6 +19,7 @@ from uploader.population.models import (populations_by_species, from .models import (genotype_markers, genotype_dataset, + save_new_dataset, genotype_markers_count, genocode_by_population) @@ -148,3 +150,35 @@ def view_dataset(species_id: int, population_id: int, dataset_id: int): population=population, dataset=dataset, activelink="view-dataset") + + +@genotypesbp.route( + "/<int:species_id>/populations/<int:population_id>/genotypes/datasets/" + "create", + methods=["GET", "POST"]) +@require_login +@with_population(species_redirect_uri="species.populations.genotypes.index", + redirect_uri="species.populations.genotypes.select_population") +def create_dataset(species: dict, population: dict, **kwargs):# pylint: disable=[unused-argument] + """Create a genotype dataset.""" + with (database_connection(app.config["SQL_URI"]) as conn, + conn.cursor(cursorclass=DictCursor) as cursor): + if request.method == "GET": + return render_template("genotypes/create-dataset.html", + species=species, + population=population, + activelink="create-dataset") + + form = request.form + _new_dataset = save_new_dataset( + cursor, + population["Id"], + form["geno-dataset-name"], + form["geno-dataset-fullname"], + form["geno-dataset-shortname"]) + + flash("Successfully created genotype dataset." + "alert-success") + return redirect(url_for("species.populations.genotypes.list_genotypes", + species_id=species["SpeciesId"], + population_id=population["Id"])) |