예제 #1
0
def add_user():
    user = User.query.filter(User.name == 'test').one_or_none()
    if not user:
        new_user = User('test', '*****@*****.**', 'password')
        print('Adding user {}'.format(new_user.name))

        db_session.add(new_user)
        db_session.commit()
    return ''
예제 #2
0
def finish_job():
    if not request.json or not 'result' in request.json:
        abort(400)
    sim_json = request.json.get('result')
    sim = Simulation.query.get(sim_json['simulation_id'])
    sim.start_time = datetime.datetime(*sim_json['start_time'][0:6])
    sim.end_time = datetime.datetime(*sim_json['end_time'][0:6])
    sim.has_error = sim_json['has_error']
    sim.is_complete = sim_json['is_complete']

    db_session.commit()
    send_active_jobs()
    return ''
예제 #3
0
def get_job(node_id=0):
    sim_val = Simulation.query.filter(Simulation.has_started == False).\
                   order_by(Simulation.simulation_id.asc()).first()
    if sim_val:
        sim_val.has_started = True
        sim_val.node_id = request.args['id']
        db_session.commit()
        return_val = sim_val.serialize()
    else:
        return_val = None

    send_active_jobs()
    return jsonify({'job': return_val})
예제 #4
0
def signup():
    form = forms.SignupForm()

    if form.validate_on_submit():
        if User.query.filter(User.name == form.username.data).count():
            flash('An account with this username already exists.', 'danger')
        elif User.query.filter(User.email == form.email.data).count():
            flash('An account with this email already exists.', 'danger')
        else:
            user = User(form.username.data, form.email.data,
                        form.password.data)
            db_session.add(user)
            db_session.commit()
            login_user(user)
            return redirect(url_for('user.questions'))
    return render_template('public/signup.html', form=form)
예제 #5
0
def add_job():
    test_user = User.query.filter(User.name == 'test').one()

    test_sub = Submission.query.filter(Submission.user_id == test_user.id).\
        filter(Submission.high_level_script_name == 'echo').\
        filter(Submission.simulation_name == 'test').first()

    if not test_sub:
        test_sub = Submission(test_user.id, 'echo', 'test', 1, 1)
        db_session.add(test_sub)
        db_session.commit()

    new_sim = Simulation(test_user.id, test_sub.sub_id)
    new_sim.input_settings_filename = ''
    new_sim.output_directory = 'test.txt'
    new_sim.random_seeding = numpy.random.randint(low=0, high=100000)
    db_session.add(new_sim)
    db_session.commit()
    send_active_jobs()
    return ''
예제 #6
0
def password_change():
    token = request.args.get('token')
    if not token:
        return redirect(url_for('public.forgot_password'))

    max_age = 24 * 60 * 60  # 24 hours in seconds
    user = User.from_token(token, 'reset', max_age=max_age)
    if not user:
        flash('The password reset link is invalid or expired.', 'danger')
        return redirect(url_for('public.forgot_password'))

    form = forms.ChangePasswordForm()
    if form.validate_on_submit():
        user.set_password(form.password.data)
        db_session.commit()

        flash('Password updated.', 'success')
        login_user(user)
        return redirect(url_for('user.questions'))
    return render_template('public/password_change.html', form=form)
예제 #7
0
def upload():
    """Create an embeddable form that will redirect to '/upload'"""
    form = forms.UploadForm()
    if form.validate_on_submit():
        new_sub = Submission(current_user.id, form.script_name.data,
                             form.simulation_name.data,
                             form.script_version.data,
                             form.simulation_version.data)
        db_session.add(new_sub)
        print(form.script_name.data, form.simulation_name.data,
              form.script_version.data, form.simulation_version.data)
        db_session.commit()

        # Add new job -- This will be replaced by adding jobs based on input file
        new_sim = Simulation(current_user.id, new_sub.sub_id)
        new_sim.input_settings_filename = ''
        new_sim.output_directory = 'test.txt'
        new_sim.random_seeding = numpy.random.randint(low=0, high=100000)
        db_session.add(new_sim)
        db_session.commit()
        send_active_jobs()
        #flash('Submission id {} added.'.format(new_sub.sub_id))
        return redirect(url_for('user.submissions'))
    return render_template('api/upload.html', form=form)