diff options
| -rw-r--r-- | uploader/background_jobs.py | 17 | ||||
| -rw-r--r-- | uploader/base_routes.py | 5 | ||||
| -rw-r--r-- | uploader/phenotypes/views.py | 65 | ||||
| -rw-r--r-- | uploader/population/views.py | 9 | ||||
| -rw-r--r-- | uploader/species/views.py | 6 | ||||
| -rw-r--r-- | uploader/sui.py | 8 |
6 files changed, 60 insertions, 50 deletions
diff --git a/uploader/background_jobs.py b/uploader/background_jobs.py index a9c0345..fc59ec7 100644 --- a/uploader/background_jobs.py +++ b/uploader/background_jobs.py @@ -16,6 +16,9 @@ from gn_libs import jobs from gn_libs import sqlite3 from gn_libs.jobs.jobs import JobNotFound + +from uploader.sui import sui_template + from uploader.flask_extensions import url_for from uploader.authorisation import require_login @@ -77,8 +80,7 @@ def handler(job: dict, handler_type: str) -> HandlerType: ).get(handler_type) if bool(_handler): return _handler(job) - _sui = "sui-" if request.args.get("streamlined_ui") else "" - return render_template(f"background-jobs/{_sui}default-success-page.html", + return render_template(sui_template("background-jobs/default-success-page.html"), job=job) @@ -90,7 +92,6 @@ success_handler = partial(handler, handler_type="success") @require_login def job_status(job_id: uuid.UUID): """View the job status.""" - _sui = "sui-" if request.args.get("streamlined_ui") else "" with sqlite3.connection(app.config["ASYNCHRONOUS_JOBS_SQLITE_DB"]) as conn: try: job = jobs.job(conn, job_id, fulldetails=True) @@ -103,10 +104,10 @@ def job_status(job_id: uuid.UUID): if status == "completed": return success_handler(job) - return render_template(f"jobs/{_sui}job-status.html", job=job) + return render_template(sui_template("jobs/job-status.html"), job=job) except JobNotFound as _jnf: return render_template( - f"jobs/{_sui}job-not-found.html", + sui_template("jobs/job-not-found.html"), job_id=job_id) @@ -114,10 +115,10 @@ def job_status(job_id: uuid.UUID): @require_login def job_error(job_id: uuid.UUID): """Handle job errors in a generic manner.""" - _sui = "sui-" if request.args.get("streamlined_ui") else "" with sqlite3.connection(app.config["ASYNCHRONOUS_JOBS_SQLITE_DB"]) as conn: try: job = jobs.job(conn, job_id, fulldetails=True) - return render_template(f"jobs/{_sui}job-error.html", job=job) + return render_template(sui_template("jobs/job-error.html"), job=job) except JobNotFound as _jnf: - return render_template(f"jobs/{_sui}job-not-found.html", job_id=job_id) + return render_template(sui_template("jobs/job-not-found.html"), + job_id=job_id) diff --git a/uploader/base_routes.py b/uploader/base_routes.py index 80a15a0..cc2a270 100644 --- a/uploader/base_routes.py +++ b/uploader/base_routes.py @@ -11,6 +11,9 @@ from flask import (flash, current_app as app, send_from_directory) + +from uploader.sui import sui_template + from uploader.flask_extensions import url_for from uploader.ui import make_template_renderer from uploader.oauth2.client import user_logged_in @@ -42,7 +45,7 @@ def index(): print("We found a species ID. Processing...") if not bool(request.args.get("species_id")): return render_template( - "sui-index.html",# TODO: Rename: sui-index.html, sui_base.html + sui_template("index.html"), gn2server_intro=urljoin(app.config["GN2_SERVER_URL"], "/intro"), species=all_species(conn), streamlined_ui=streamlined_ui) diff --git a/uploader/phenotypes/views.py b/uploader/phenotypes/views.py index 364fc79..5b32fc0 100644 --- a/uploader/phenotypes/views.py +++ b/uploader/phenotypes/views.py @@ -32,6 +32,8 @@ from r_qtl import r_qtl2_qc as rqc from r_qtl import exceptions as rqe +from uploader.sui import sui_template + from uploader import jobs from uploader import session from uploader.files import save_file @@ -423,11 +425,10 @@ def add_phenotypes(species: dict, population: dict, dataset: dict, **kwargs):# p with Redis.from_url(_redisuri, decode_responses=True) as rconn: if request.method == "GET": today = datetime.date.today() - _sui="sui-" if request.args.get("streamlined_ui") else "" return render_template( - (f"phenotypes/{_sui}add-phenotypes-with-rqtl2-bundle.html" - if use_bundle - else f"phenotypes/{_sui}add-phenotypes-raw-files.html"), + sui_template("phenotypes/add-phenotypes-with-rqtl2-bundle.html" + if use_bundle + else f"phenotypes/add-phenotypes-raw-files.html"), species=species, population=population, dataset=dataset, @@ -514,8 +515,7 @@ def job_status( except jobs.JobNotFound as _jnf: job = None - _sui = "sui-" if bool(request.args.get("streamlined_ui")) else "" - return render_template(f"phenotypes/{_sui}job-status.html", + return render_template(sui_template("phenotypes/job-status.html"), species=species, population=population, dataset=dataset, @@ -595,8 +595,7 @@ def review_job_data( for filetype,meta in metadata.items() } _job_metadata = json.loads(job["job-metadata"]) - _sui = "sui-" if bool(request.args.get("streamlined_ui")) else "" - return render_template(f"phenotypes/{_sui}review-job-data.html", + return render_template(sui_template("phenotypes/review-job-data.html"), species=species, population=population, dataset=dataset, @@ -986,34 +985,34 @@ def load_data_success( _publication["Authors"], (_publication["Title"] or "")) if item != "") - _sui="sui-" if request.args.get("streamlined_ui") else "" - return render_template(f"phenotypes/{_sui}load-phenotypes-success.html", - species=species, - population=population, - dataset=dataset, - job=job, - search_page_uri=urlunparse(ParseResult( - scheme=gn2_uri.scheme, - netloc=gn2_uri.netloc, - path="/search", - params="", - query=urlencode({ - "species": species["Name"], - "group": population["Name"], - "type": "Phenotypes", - "dataset": dataset["Name"], - "search_terms_or": ( - # Very long URLs will cause - # errors. + return render_template( + sui_template("phenotypes/load-phenotypes-success.html"), + species=species, + population=population, + dataset=dataset, + job=job, + search_page_uri=urlunparse(ParseResult( + scheme=gn2_uri.scheme, + netloc=gn2_uri.netloc, + path="/search", + params="", + query=urlencode({ + "species": species["Name"], + "group": population["Name"], + "type": "Phenotypes", + "dataset": dataset["Name"], + "search_terms_or": ( + # Very long URLs will cause + # errors. " ".join(_xref_ids) if len(_xref_ids) <= 100 else ""), - "search_terms_and": " ".join( - _search_terms).strip(), - "accession_id": "None", - "FormID": "searchResult" - }), - fragment=""))) + "search_terms_and": " ".join( + _search_terms).strip(), + "accession_id": "None", + "FormID": "searchResult" + }), + fragment=""))) except JobNotFound as _jnf: return render_template("jobs/job-not-found.html", job_id=job_id) diff --git a/uploader/population/views.py b/uploader/population/views.py index 1f84ddb..a6e2358 100644 --- a/uploader/population/views.py +++ b/uploader/population/views.py @@ -11,6 +11,8 @@ from flask import (flash, Blueprint, current_app as app) +from uploader.sui import sui_template + from uploader.samples.views import samplesbp from uploader.flask_extensions import url_for from uploader.oauth2.client import oauth2_post @@ -242,8 +244,5 @@ def view_population(species_id: int, population_id: int): dataset_phenotypes(conn, population["Id"], _dataset["Id"])) } - return render_template( - ("populations/sui-view-population.html" - if bool(streamlined_ui) - else "populations/view-population.html"), - **_kwargs) + return render_template(sui_template("populations/view-population.html"), + **_kwargs) diff --git a/uploader/species/views.py b/uploader/species/views.py index 20acd01..9b14d01 100644 --- a/uploader/species/views.py +++ b/uploader/species/views.py @@ -8,6 +8,8 @@ from flask import (flash, Blueprint, current_app as app) +from uploader.sui import sui_template + from uploader.population import popbp from uploader.platforms import platformsbp from uploader.flask_extensions import url_for @@ -54,9 +56,7 @@ def view_species(species_id: int): species_id=species_id, population_id=population["Id"])) return render_template( - ("species/sui-view-species.html" - if bool(streamlined_ui) - else "species/view-species.html"), + sui_template("species/view-species.html"), species=species, activelink="view-species", populations=populations_by_species(conn, species["SpeciesId"])) diff --git a/uploader/sui.py b/uploader/sui.py new file mode 100644 index 0000000..8eb863d --- /dev/null +++ b/uploader/sui.py @@ -0,0 +1,8 @@ +"""Utilities for streamlined UI. This is a temporary module.""" +from flask import request + +def sui_template(template_path: str) -> str: + """Return the streamlined UI template for given template path.""" + _sui="sui-" if request.args.get("streamlined_ui") else "" + _parts = template_path.split("/") + return "/".join(_parts[:-1] + [f"{_sui}{_parts[-1]}"]) |
