<s> from __future__ import print_function , unicode_literals <EOL> import os <EOL> from flask import render_template , url_for , request , flash , redirect , session , g <EOL> from weblab . core . i18n import gettext , get_locale <EOL> from weblab . core . exc import SessionNotFoundError <EOL> from weblab . core . webclient . view_login import demo <EOL> from weblab . core . webclient . helpers import _get_experiment , _get_experiment_data , _hook_native_experiments <EOL> from weblab . core . wl import weblab_api <EOL> from weblab . core . webclient import login_required <EOL> from weblab . core . reservations import Reservation <EOL> @ weblab_api . route_webclient ( "<STR_LIT>" ) <EOL> def lab ( category_name , experiment_name ) : <EOL> """<STR_LIT>""" <EOL> federated_reservation_id = session . get ( '<STR_LIT>' ) <EOL> federated_mode = federated_reservation_id is not None <EOL> if federated_mode : <EOL> back_url = session . get ( '<STR_LIT>' ) <EOL> else : <EOL> back_url = None <EOL> experiment = None <EOL> if federated_mode : <EOL> weblab_api . ctx . reservation_id = federated_reservation_id <EOL> try : <EOL> experiment = _get_experiment_data ( weblab_api . api . get_reservation_experiment_info ( ) ) <EOL> reservation_status = weblab_api . api . get_reservation_status ( ) <EOL> except SessionNotFoundError : <EOL> session . pop ( '<STR_LIT>' , None ) <EOL> session . pop ( '<STR_LIT>' , None ) <EOL> federated_mode = False <EOL> try : <EOL> experiment_list = weblab_api . api . list_experiments ( experiment_name , category_name ) <EOL> except SessionNotFoundError : <EOL> return render_template ( "<STR_LIT>" , error_message = gettext ( "<STR_LIT>" ) , federated_mode = True , back_url = back_url ) <EOL> else : <EOL> if experiment is not None and reservation_status is not None and experiment [ '<STR_LIT:type>' ] == '<STR_LIT>' : <EOL> if reservation_status . status == Reservation . CONFIRMED : <EOL> local_url = reservation_status . url <EOL> if local_url is not None : <EOL> return redirect ( local_url . replace ( "<STR_LIT>" , unicode ( local_url . time ) ) ) <EOL> if experiment is None : <EOL> try : <EOL> experiment_list = weblab_api . api . list_experiments ( experiment_name , category_name ) <EOL> except SessionNotFoundError : <EOL> flash ( gettext ( "<STR_LIT>" ) , '<STR_LIT>' ) <EOL> return redirect ( url_for ( '<STR_LIT>' , next = request . url ) ) <EOL> for exp_allowed in experiment_list : <EOL> if exp_allowed . experiment . name == experiment_name and exp_allowed . experiment . category . name == category_name : <EOL> experiment = _get_experiment ( exp_allowed ) <EOL> if experiment is None : <EOL> if weblab_api . db . check_experiment_exists ( experiment_name , category_name ) : <EOL> flash ( gettext ( "<STR_LIT>" ) , '<STR_LIT>' ) <EOL> else : <EOL> flash ( gettext ( "<STR_LIT>" ) , '<STR_LIT>' ) <EOL> return redirect ( url_for ( '<STR_LIT>' ) ) <EOL> return render_template ( "<STR_LIT>" , experiment = experiment , federated_mode = federated_mode , back_url = back_url , federated_reservation_id = federated_reservation_id ) <EOL> @ weblab_api . route_webclient ( "<STR_LIT>" ) <EOL> def demo_lab ( category_name , experiment_name ) : <EOL> try : <EOL> experiment_list = weblab_api . api . list_experiments ( experiment_name , category_name ) <EOL> except SessionNotFoundError : <EOL> g . next_url = url_for ( '<STR_LIT>' , category_name = category_name , experiment_name = experiment_name ) <EOL> return demo ( ) <EOL> except : <EOL> flash ( gettext ( "<STR_LIT>" ) , '<STR_LIT>' ) <EOL> return redirect ( url_for ( '<STR_LIT>' ) ) <EOL> else : <EOL> return redirect ( url_for ( '<STR_LIT>' , category_name = category_name , experiment_name = experiment_name ) ) <EOL> @ weblab_api . route_webclient ( '<STR_LIT>' ) <EOL> def demos_index ( ) : <EOL> return redirect ( url_for ( '<STR_LIT>' ) ) <EOL> @ weblab_api . route_webclient ( '<STR_LIT>' ) <EOL> def demos_index_labs ( ) : <EOL> return redirect ( url_for ( '<STR_LIT>' ) ) <EOL> @ weblab_api . route_webclient ( '<STR_LIT>' ) <EOL> def demos_index_labs_category ( category_name ) : <EOL> return redirect ( url_for ( '<STR_LIT>' ) ) <EOL> @ weblab_api . route_webclient ( "<STR_LIT>" ) <EOL> def lab_config ( category_name , experiment_name ) : <EOL> experiment_config = { } <EOL> try : <EOL> experiment = weblab_api . db . get_experiment ( experiment_name , category_name ) <EOL> except Exception as ex : <EOL> pass <EOL> else : <EOL> if experiment is not None : <EOL> _hook_native_experiments ( experiment ) <EOL> experiment_config = experiment . client . configuration <EOL> scripts = [ <EOL> url_for ( '<STR_LIT>' , filename = '<STR_LIT>' , _external = True ) <EOL> ] <EOL> locale = get_locale ( ) . language <EOL> return weblab_api . jsonify ( locale = locale , targetURL = url_for ( '<STR_LIT>' ) , fileUploadURL = url_for ( '<STR_LIT>' ) , scripts = scripts , config = experiment_config , currentURL = weblab_api . core_server_url ) <EOL> @ weblab_api . route_webclient ( "<STR_LIT>" ) <EOL> @ login_required <EOL> def latest_uses ( category_name , experiment_name ) : <EOL> uses = [ ] <EOL> for use in weblab_api . api . get_latest_uses_per_lab ( category_name , experiment_name ) : <EOL> current_use = { <EOL> '<STR_LIT>' : use [ '<STR_LIT>' ] . strftime ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : url_for ( '<STR_LIT>' , id = use [ '<STR_LIT:id>' ] ) <EOL> } <EOL> if use [ '<STR_LIT>' ] : <EOL> current_use [ '<STR_LIT:location>' ] = '<STR_LIT>' . format ( use [ '<STR_LIT>' ] , use [ '<STR_LIT>' ] ) <EOL> else : <EOL> current_use [ '<STR_LIT:location>' ] = use [ '<STR_LIT>' ] <EOL> uses . append ( current_use ) <EOL> return weblab_api . jsonify ( uses = uses [ : : - <NUM_LIT:1> ] ) <EOL> @ weblab_api . route_webclient ( "<STR_LIT>" ) <EOL> @ login_required <EOL> def lab_stats ( category_name , experiment_name ) : <EOL> experiment_found = False <EOL> try : <EOL> experiment_list = weblab_api . api . list_experiments ( experiment_name , category_name ) <EOL> for exp_allowed in experiment_list : <EOL> if exp_allowed . experiment . name == experiment_name and exp_allowed . experiment . category . name == category_name : <EOL> experiment_found = True <EOL> except Exception as ex : <EOL> return { } <EOL> if not experiment_found : <EOL> return { } <EOL> stats = weblab_api . db . get_experiment_stats ( experiment_name , category_name ) <EOL> stats [ '<STR_LIT:status>' ] = '<STR_LIT>' ; <EOL> return weblab_api . jsonify ( stats = stats ) </s>
