"""Endpoints for publications""" import json from gn_libs.mysqldb import database_connection from flask import request, Blueprint, render_template, current_app as app from uploader.authorisation import require_login from .models import ( fetch_publications, fetch_publication_by_id, fetch_publication_phenotypes) from gn_libs.debug import __pk__ pubbp = Blueprint("publications", __name__) @pubbp.route("/", methods=["GET"]) @require_login def index(): """Index page for publications.""" with database_connection(app.config["SQL_URI"]) as conn: return render_template("publications/index.html") @pubbp.route("/list", methods=["GET"]) @require_login def list_publications(): with database_connection(app.config["SQL_URI"]) as conn: return json.dumps({ "publications": tuple({ **row, "index": idx } for idx,row in enumerate( fetch_publications(conn), start=1)), "status": "success" }) @pubbp.route("/view/", methods=["GET"]) @require_login def view_publication(publication_id: int): """View more details on a particular publication.""" with database_connection(app.config["SQL_URI"]) as conn: return render_template( "publications/view-publication.html", publication=fetch_publication_by_id(conn, publication_id), linked_phenotypes=tuple(fetch_publication_phenotypes( conn, publication_id))) @pubbp.route("/create", methods=["GET", "POST"]) @require_login def create_publication(): """Create a new publication.""" if(request.method == "GET"): return render_template("publications/create-publication.html") return "Not Implemented"