aboutsummaryrefslogtreecommitdiff
path: root/uploader/population/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'uploader/population/views.py')
-rw-r--r--uploader/population/views.py28
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>",