Пример #1
0
def database_add():
    error = False
    form = DatabaseAddForm(request.form)
    if request.method == 'POST':
        if form.validate():
            if check_connection(form.data):
                DatabaseContainer.add(form.data)
                update()
                return redirect(url_for("blueprint.dashboard"))
            else:
                error = "Unable connect to database. Maybe you provided bad data?"
        else:
            if len(form.shortname.errors) > 0:
                error = "Shortname already exists. Please specify another one."
            if len(form.database.errors) > 0:
                error = "Specifed database already exists."
            else:
                error = "Please provide correct data."
    return make_response(
        render_template('database/add.html', form=form, error=error), 200)
Пример #2
0
def database_view_operations(host, shortname):
    error = False
    c = request.args.get("c")
    act_db_properties = DatabaseContainer.get(shortname)
    form = DatabaseEditForm(request.form)
    if c is not None:
        if COMMANDS[c](host=host, shortname=shortname):
            return redirect(
                url_for("blueprint.server_view_databases", host=host))
        else:
            return redirect('/')
    if request.method == 'POST':
        if form.validate():
            if check_connection(form.data):
                DatabaseContainer.add(form.data)
                DatabaseContainer.delete([shortname])
                BindContainer.delete([shortname])
                BindContainer.add(form.shortname.data)
                update()
                return redirect(
                    url_for("blueprint.database_view_operations",
                            host=host,
                            shortname=form.shortname.data))
            else:
                error = "Unable connect to database."
        else:
            if len(form.shortname.errors) > 0:
                error = "Shortname already exists. Please specify another one."
            if len(form.database.errors) > 0:
                error = "Specifed database already exists."
            else:
                error = "Please provide correct data."
    return make_response(
        render_template('database/operations.html',
                        host=host,
                        form=form,
                        error=error,
                        act_db_properties=act_db_properties), 200)