Example #1
0
def labs():
    """
    Renders the Laboratories List.
    """
    try:
        # We also want access to the experiment's list for the user.
        # TODO: Take into account the somewhat unclear difference between the loginweblabsessionid and the other one.
        cookie = request.cookies.get("weblabsessionid", None)
        if cookie is None:
            flash("You are not logged in", category="error")
            # _ext + _scheme is a workaround around an http(s) issue.
            return redirect(url_for(".index", _external=True, _scheme=request.scheme))

        # Prepare to call the weblab_api
        weblab_api.ctx.reservation_id = cookie
        experiments_raw = weblab_api.api.list_experiments()

        experiments, experiments_by_category = _get_experiment_info(experiments_raw)
        loggedin_info = _get_loggedin_info()
    except SessionNotFoundError as ex:
        flash("You are not logged in", category="error")
        next = request.full_path
        return redirect(url_for(".index", _external=True, _scheme=request.scheme, next=next))

    return render_template("webclient_web/labs.html", experiments=experiments,
                           experiments_by_category=experiments_by_category,
                           urllib=urllib, loggedin=loggedin_info)
Example #2
0
def lab():
    """
    Renders a specific laboratory.
    """

    try:
        name = request.values.get("name")
        category = request.values.get("category")
        type = request.values.get("type")

        if name is None or category is None or type is None:
            return "500 Please specify a name and category", 500

        sessionid = request.cookies.get("weblabsessionid")

        weblab_api.ctx.reservation_id = sessionid

        # Retrieve the loggedin information.
        loggedin_info = _get_loggedin_info()

        experiments_raw = weblab_api.api.list_experiments()
        experiments, experiments_by_category = _get_experiment_info(experiments_raw)

        experiment = experiments[name]

        # Get the target URL for the JS API.
        # Note: The following commented line should work best; but it doesn't make sure that the protocol matches.
        # core_server_url = weblab_api.server_instance.core_server_url
        core_server_url = os.path.join(*[url_for(".index"), "../../"])
        json_url = os.path.join(*[core_server_url, "json/"])
        # Old URL: lab_url = os.path.join(*[core_server_url, "client", "weblabclientlab/"])
        lab_url = os.path.join(url_for(".static", filename=""))

        return render_template("webclient_web/lab.html", experiment=experiment, loggedin=loggedin_info, json_url=json_url, lab_url=lab_url)

    except SessionNotFoundError as ex:
        flash("You are not logged in", category="error")
        next = request.full_path
        return redirect(url_for(".index", _external=True, _scheme=request.scheme, next=next))
    except Exception as ex:
        raise ex