diff options
author | Frederick Muriuki Muriithi | 2024-09-27 11:40:08 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-09-27 11:40:08 -0500 |
commit | 0729e38e2f5bbc5ab23153adfed3d35ee59dc3d5 (patch) | |
tree | bd33450676c54be6444261b00c1d683a17b5366a /uploader/population | |
parent | 1b6b9a90a4dbe38aefc00293309fb48d9f478b13 (diff) | |
download | gn-uploader-0729e38e2f5bbc5ab23153adfed3d35ee59dc3d5.tar.gz |
Extract common functionality into reusable function.
Diffstat (limited to 'uploader/population')
-rw-r--r-- | uploader/population/views.py | 28 |
1 files changed, 7 insertions, 21 deletions
diff --git a/uploader/population/views.py b/uploader/population/views.py index 23bf242..3638453 100644 --- a/uploader/population/views.py +++ b/uploader/population/views.py @@ -2,9 +2,7 @@ import re import json import base64 -import traceback -from requests.models import Response from MySQLdb.cursors import DictCursor from flask import (flash, request, @@ -18,10 +16,11 @@ from uploader.oauth2.client import oauth2_post from uploader.ui import make_template_renderer from uploader.authorisation import require_login from uploader.genotypes.views import genotypesbp -from uploader.phenotypes.views import phenotypesbp -from uploader.expression_data.views import exprdatabp from uploader.db_utils import database_connection from uploader.datautils import enumerate_sequence +from uploader.phenotypes.views import phenotypesbp +from uploader.expression_data.views import exprdatabp +from uploader.monadic_requests import make_either_error_handler from uploader.species.models import (all_species, species_by_id, order_species_by_family) @@ -174,22 +173,6 @@ def create_population(species_id: int): "GeneticType": request.form.get("population_genetic_type") or None }) - def __handle_error__(error): - error_format = ( - "\n\nThere was an error creating the population:\n\t%s\n\n") - if issubclass(type(error), Exception): - app.logger.debug(error_format, traceback.format_exc()) - raise error - if issubclass(type(error), Response): - try: - _data = error.json() - except Exception as _exc: - raise Exception(error.content) from _exc - raise Exception(_data) - - app.logger.debug(error_format, error) - raise Exception(error) - def __flash_success__(_success): flash("Successfully created resource.", "alert-success") return redirect(url_for( @@ -206,7 +189,10 @@ def create_population(species_id: int): "population_id": new_population["Id"], "public": "on" } - ).either(__handle_error__, __flash_success__) + ).either( + make_either_error_handler( + "There was an error creating the population"), + __flash_success__) @popbp.route("/<int:species_id>/populations/<int:population_id>", |