Пример #1
0
def server_add():

    from forms import ServerForm

    apps = Application.query.all()
    form = ServerForm(request.form)
    iapps = request.form.getlist('apps')
    iapps = Application.query.filter(
        Application.id.in_(iapps)).all()

    if form.validate_on_submit():

        s = Server()
        form.apps.data = [ 
            Application.query.get_or_404(x) \
            for x in form.apps.data]
        form.populate_obj(s)
        db.session.add(s)
        db.session.commit()
        return redirect(url_for(".server"))

    return render_template("server_add.html",
        form=form,
        apps=apps,
        iapps=iapps)
Пример #2
0
def add(account):
    if request.method == 'POST':
        form = ServerForm(request.form)
        if form.validate():
            server = Server()
            form.populate_obj(server)
            server.put()
            flash(u'Server added!')
            return redirect(url_for('server.show',
                                     server_key=server.key.urlsafe()))
    else:
        form = ServerForm()

    return render_template('server/form.html', form=form, account=account)
Пример #3
0
def edit(account, server_key):
    server = get_server(server_key)
    if server is None:
        return abort(404)

    if request.method == 'POST':
        form = ServerForm(request.form)
        if form.validate():
            form.populate_obj(server)
            server.put()
            return redirect(url_for('server.show',
                server_key=server.key.urlsafe()))
    else:
        form = ServerForm(**server._to_dict())
       
    return render_template('/server/form.html', form=form,
                server_key=server.key.urlsafe(), account=account)
Пример #4
0
def new_server():
    '''
    Create new server
    '''
    form = ServerForm()
    if form.validate_on_submit():
        my_server = Server()
        form.populate_obj(my_server)
        db.session.add(my_server)
        try:
            db.session.commit()
            # User info
            flash('Server created correctly', 'success')
            return redirect(url_for('servers'))
        except:
            db.session.rollback()
            flash('Error generating server.', 'danger')

    return render_template('web/new_server.html', form=form)
Пример #5
0
def edit_server(id):
    '''
    Edit server

    :param id: Id from server
    '''
    my_server = Server.query.filter_by(id=id).first()
    form = ServerForm(obj=my_server)

    if form.validate_on_submit():
        try:
            # Update network
            form.populate_obj(my_server)
            db.session.add(my_server)
            db.session.commit()
            # User info
            flash('Saved successfully', 'success')
        except:
            db.session.rollback()
            flash('Error update network.', 'danger')

    return render_template('web/edit_server.html', form=form)
Пример #6
0
def server_edit(server_id):

    from forms import ServerForm

    s = Server.query.get_or_404(server_id)
    apps = Application.query.all()
    form = ServerForm(
        formdata=request.form, 
        obj=s)

    if form.validate_on_submit():

        form.apps.data = [ 
            Application.query.get_or_404(x) \
            for x in form.apps.data]
        form.populate_obj(s)

        db.session.commit()
        return redirect(url_for(".server"))

    return render_template("server_edit.html",
        form=form,
        apps=apps,
        s=s)