Exemplo n.º 1
0
def home():
    user_details = get_user_details()

    if not is_user_registered(user_details[0]):
        return redirect(url_for('userManagement.sign_up'))

    form = Computation()
    user_id = get_user_id(user_details[0])
    if form.validate_on_submit():  # this block of code is executed when browser sent POST request(user submitted form)
        try:
            DirectoryAndFileWriter.create_experiment(form, str(user_id))
            flash(current_app.config['EXPERIMENT_SUBMITTED'], "info")
            return redirect('/home')
        except NewComputationRequestSubmitError:
            flash(current_app.config['EXPERIMENT_SUBMISSION_FAILED'], "error")
            return redirect('/home')

    try:
        help_cookie = request.cookies["help"]
    except KeyError:
        help_cookie = "enabled"

    if is_user_registered(user_details[0]) and is_user_confirmed(user_details[0]):
        return render_template('home.html', form=form, username=get_user_username(user_details[0]), help=help_cookie, is_admin=is_user_admin(user_details[0]),
                               pages=DirectoryAndFileReader.get_pagination_controls_count(user_id),
                               comps=DirectoryAndFileReader.get_subset_of_computations_for_one_page(
                                   get_user_id(user_details[0]), 0, 'date', -1, {}))
    elif is_user_registered(user_details[0]) and not is_user_confirmed(user_details[0]):
        return redirect(url_for('userManagement.unconfirmed'))
Exemplo n.º 2
0
def delete_computations(page, sort_option, sort_order):
    user_details = get_user_details()
    user_id = get_user_id(user_details[0])

    if not is_user_registered(user_details[0]):
        return redirect(url_for('userManagement.sign_up'))

    elif is_user_registered(user_details[0]) and not is_user_confirmed(user_details[0]):
        return redirect(url_for('userManagement.unconfirmed'))

    DirectoryAndFileWriter.delete_computations(request.json, str(user_id))
    return jsonify(comps=DirectoryAndFileReader.get_subset_of_computations_for_one_page(user_id, int(page), sort_option, int(sort_order), request.json['filter_values']),
                   pages=len(DirectoryAndFileReader.get_pagination_controls_count(computations=DirectoryAndFileReader.get_computations(user_id, sort_option, int(sort_order), request.json['filter_values']))))
Exemplo n.º 3
0
def sign_up():
    r_form = RegistrationForm(request.form)
    user_details = get_user_details()

    if r_form.validate_on_submit():
        # user_details = DirectoryAndFileReader.get_user_details()
        user = User(username=r_form.username.data, email=r_form.email.data, eppn=user_details[0], role_id=2)
        db.session.add(user)
        db.session.commit()
        DirectoryAndFileWriter.create_user_directory(get_user_id(user_details[0]))
        # send_email(user.email, 'Confirm Your Account', 'mail/confirm', user=user, token=token)
        return redirect(url_for('userManagement.unconfirmed'))

    return render_template('sign_up.html', r_form=r_form, username=user_details[1], email=user_details[2])
Exemplo n.º 4
0
def view_experiment(user_id, comp_guid):
    user_details = get_user_details()

    if not is_user_registered(user_details[0]):
        return redirect(url_for('userManagement.sign_up'))

    elif is_user_registered(user_details[0]) and not is_user_confirmed(user_details[0]):
        return redirect(url_for('userManagement.unconfirmed'))

    if not DirectoryAndFileReader.check_if_computation_exist(user_id, comp_guid):
        return render_template("unavailable.html", message="Requested computation results don't exist. Make sure the url is correct", icon="info.png")
    if not DirectoryAndFileReader.check_for_computation_results(user_id, comp_guid, DirectoryAndFileReader.get_computation_status(user_id, comp_guid)):
        return render_template("unavailable.html", message="Requested results cannot be displayed, because server has not finished the computation. Try again later", icon="gears.gif")
    DirectoryAndFileWriter.get_model_data(user_id, comp_guid)
    return render_template("view_experiment.html", username=user_details[1], is_admin=is_user_admin(user_details[0]),
                           best_results=DirectoryAndFileReader.get_best_solutions_of_computation(user_id, comp_guid),
                           computation_details=DirectoryAndFileReader.get_computation_parameters(user_id, comp_guid))
Exemplo n.º 5
0
def delete_computations(page, sort_option, sort_order):
    user_details = get_user_details()
    user_id = get_user_id(user_details[0])

    if not is_user_registered(user_details[0]):
        return redirect(url_for('userManagement.sign_up'))

    elif is_user_registered(
            user_details[0]) and not is_user_confirmed(user_details[0]):
        return redirect(url_for('userManagement.unconfirmed'))

    DirectoryAndFileWriter.delete_computations(request.json, str(user_id))
    return jsonify(
        comps=DirectoryAndFileReader.get_subset_of_computations_for_one_page(
            user_id, int(page), sort_option, int(sort_order),
            request.json['filter_values']),
        pages=len(
            DirectoryAndFileReader.get_pagination_controls_count(
                computations=DirectoryAndFileReader.get_computations(
                    user_id, sort_option, int(sort_order),
                    request.json['filter_values']))))
Exemplo n.º 6
0
def home():
    user_details = get_user_details()

    if not is_user_registered(user_details[0]):
        return redirect(url_for('userManagement.sign_up'))

    form = Computation()
    user_id = get_user_id(user_details[0])
    if form.validate_on_submit(
    ):  # this block of code is executed when browser sent POST request(user submitted form)
        try:
            DirectoryAndFileWriter.create_experiment(form, str(user_id))
            flash(current_app.config['EXPERIMENT_SUBMITTED'], "info")
            return redirect('/home')
        except NewComputationRequestSubmitError:
            flash(current_app.config['EXPERIMENT_SUBMISSION_FAILED'], "error")
            return redirect('/home')

    try:
        help_cookie = request.cookies["help"]
    except KeyError:
        help_cookie = "enabled"

    if is_user_registered(user_details[0]) and is_user_confirmed(
            user_details[0]):
        return render_template(
            'home.html',
            form=form,
            username=get_user_username(user_details[0]),
            help=help_cookie,
            is_admin=is_user_admin(user_details[0]),
            pages=DirectoryAndFileReader.get_pagination_controls_count(
                user_id),
            comps=DirectoryAndFileReader.
            get_subset_of_computations_for_one_page(
                get_user_id(user_details[0]), 0, 'date', -1, {}))
    elif is_user_registered(
            user_details[0]) and not is_user_confirmed(user_details[0]):
        return redirect(url_for('userManagement.unconfirmed'))
Exemplo n.º 7
0
def view_experiment(user_id, comp_guid):
    user_details = get_user_details()

    if not is_user_registered(user_details[0]):
        return redirect(url_for('userManagement.sign_up'))

    elif is_user_registered(
            user_details[0]) and not is_user_confirmed(user_details[0]):
        return redirect(url_for('userManagement.unconfirmed'))

    if not DirectoryAndFileReader.check_if_computation_exist(
            user_id, comp_guid):
        return render_template(
            "unavailable.html",
            message=
            "Requested computation results don't exist. Make sure the url is correct",
            icon="info.png",
            username=get_user_username(user_details[0]))
    if not DirectoryAndFileReader.check_for_computation_results(
            user_id, comp_guid,
            DirectoryAndFileReader.get_computation_status(user_id, comp_guid)):
        return render_template(
            "unavailable.html",
            message=
            "Requested results cannot be displayed, because server has not finished the computation. Try again later",
            icon="info.png",
            username=get_user_username(user_details[0]))
    DirectoryAndFileWriter.move_model_and_experiment_data_to_upload_dir(
        user_id, comp_guid)
    return render_template(
        "view_experiment.html",
        username=get_user_username(user_details[0]),
        comp_guid=comp_guid,
        is_admin=is_user_admin(user_details[0]),
        best_results=DirectoryAndFileReader.get_best_solutions_of_computation(
            user_id, comp_guid),
        computation_details=DirectoryAndFileReader.get_computation_parameters(
            user_id, comp_guid))
Exemplo n.º 8
0
def sign_up():
    user_details = get_user_details()

    if is_user_registered(user_details[0]) and is_user_confirmed(user_details[0]):
        return redirect('/home')

    if is_user_registered(user_details[0]) and not is_user_confirmed(user_details[0]):
        return redirect(url_for('userManagement.unconfirmed'))

    r_form = RegistrationForm(request.form)
    if request.method == "GET":
        r_form.username.data = user_details[1]
        r_form.email.data = user_details[2]

    if r_form.validate_on_submit():
        user = User(username=r_form.username.data, email=r_form.email.data, eppn=user_details[0], role_id=2)
        db.session.add(user)
        db.session.commit()
        DirectoryAndFileWriter.create_user_directory(get_user_id(user_details[0]))
        send_email(current_app.config['ADMIN_MAIL_ADDRESS'], 'New user has registered', 'mail/new_user', user=user, comment=r_form.comment.data)
        return redirect(url_for('userManagement.unconfirmed'))

    return render_template('sign_up.html', r_form=r_form)