Exemplo n.º 1
0
 def wrapped(*args, **kwargs):
     try:
         return func(*args, **kwargs)
     except WebError as e:
         return weblab_api.jsonify(error=True, message=e.args[0])
     except Exception:
         if current_app.debug:
             raise
         traceback.print_exc()
         return weblab_api.jsonify(error=True, message=gettext("Error processing request"))
Exemplo n.º 2
0
 def wrapped(*args, **kwargs):
     try:
         return func(*args, **kwargs)
     except WebError as e:
         return weblab_api.jsonify(error=True, message=e.args[0])
     except Exception:
         if current_app.debug:
             raise
         traceback.print_exc()
         return weblab_api.jsonify(
             error=True, message=gettext("Error processing request"))
Exemplo n.º 3
0
def login_service():
    contents = request.get_json(force=True, silent=True)
    if contents == False or not isinstance(contents, dict):
        return weblab_api.jsonify(error = True, message = "Error reading username and password")

    username = contents.get('username', '')
    password = contents.get('password', '')

    try:
        session_id = weblab_api.api.login(username, password)
    except InvalidCredentialsError:
        return weblab_api.jsonify(error = True, message = gettext("Invalid username or password"))

    return weblab_api.jsonify(error = False, redirect = get_next_url())
Exemplo n.º 4
0
def status_global():
    if weblab_api.config.get(COORDINATOR_IMPL) != 'redis':
        return "This method is only available on Redis", 404

    experiments = get_experiments()

    return weblab_api.jsonify(experiments=experiments)
Exemplo n.º 5
0
def experiment_status(category_name, experiment_name):
    if weblab_api.config.get(COORDINATOR_IMPL) != 'redis':
        return "This method is only available on Redis", 404

    experiment_id = '{}@{}'.format(experiment_name, category_name)
    experiments = get_experiments()
    if category_name not in experiments:
        return "experiment not found", 404

    experiment = experiments[category_name].get(experiment_id)
    if experiment is None:
        return "experiment not found", 404

    return weblab_api.jsonify(experiment=experiment)
Exemplo n.º 6
0
def latest_uses(category_name, experiment_name):
    uses = []
    for use in weblab_api.api.get_latest_uses_per_lab(category_name, experiment_name):
        current_use = {
            'start_date' : use['start_date'].strftime('%Y-%m-%d %H:%M:%SZ'),
            'link' : url_for('accesses.detail', id=use['id'])
        }
        if use['country']:
            current_use['location'] = '{0} ({1})'.format(use['country'], use['origin'])
        else:
            current_use['location'] = use['origin']

        uses.append(current_use)

    return weblab_api.jsonify(uses=uses[::-1])
Exemplo n.º 7
0
def lab_config(category_name, experiment_name):
    experiment_config = {}
    try:
        experiment = weblab_api.db.get_experiment(experiment_name, category_name)
    except Exception as ex:
        pass
    else:
        if experiment is not None:
            _hook_native_experiments(experiment)
            experiment_config = experiment.client.configuration

    scripts = [
        url_for('.static', filename='js/iframeResizer.contentWindow.min.js', _external=True)
    ]
    locale = get_locale().language
    return weblab_api.jsonify(locale=locale, targetURL=url_for('json.service_url'), fileUploadURL=url_for('core_web.upload'), scripts=scripts, config=experiment_config, currentURL = weblab_api.core_server_url)
Exemplo n.º 8
0
def lab_stats(category_name, experiment_name):
    experiment_found = False
    try:
        experiment_list = weblab_api.api.list_experiments(experiment_name, category_name)


        for exp_allowed in experiment_list:
            if exp_allowed.experiment.name == experiment_name and exp_allowed.experiment.category.name == category_name:
                experiment_found = True

    except Exception as ex:
        return {}

    if not experiment_found:
        return {}

    stats = weblab_api.db.get_experiment_stats(experiment_name, category_name)
    stats['status'] = 'online';
    return weblab_api.jsonify(stats=stats)
Exemplo n.º 9
0
def labs_json():
    experiments_raw = weblab_api.api.list_experiments()
    experiments = [_get_experiment(raw_exp) for raw_exp in experiments_raw]
    return weblab_api.jsonify(experiments=experiments)
Exemplo n.º 10
0
def labs_json():
    experiments_raw = weblab_api.api.list_experiments()
    experiments = [_get_experiment(raw_exp) for raw_exp in experiments_raw]
    return weblab_api.jsonify(experiments=experiments)