Beispiel #1
0
    def decorated_function(*args, **kwargs):
        if not DatabaseContainer.get(kwargs["shortname"]):
            abort(404)
        if BindContainer.get(kwargs["shortname"]):

            if not check_connection(DatabaseContainer.get(
                    kwargs["shortname"])):
                BindContainer.delete(kwargs["shortname"])
            else:
                return f(*args, **kwargs)

        url = url_for("blueprint.database_connect",
                      host=kwargs["host"],
                      shortname=kwargs["shortname"])
        return make_response(
            render_template("database/error.html",
                            host=kwargs["host"],
                            url=url), 200)
Beispiel #2
0
    def validate(self):
        rv = Form.validate(self)
        if not rv:
            return False

        if DatabaseContainer.get(self.shortname.data):
            self.shortname.errors.append("Shortname exists")
            return False
        return True
Beispiel #3
0
    def validate(self):
        rv = Form.validate(self)
        if not rv:
            return False

        if DatabaseContainer.get(self.shortname.data):
            self.shortname.errors.append("Shortname exists")
            return False
        if len(DatabaseContainer.get_databases(host=self.host.data,\
                                               database=self.database.data,\
                                               port=self.port.data)) > 0:
            self.database.errors.append("Database exists")
            return False
        return True
Beispiel #4
0
    def decorated_function(host, shortname, table_name=None, section=None):
        if BindContainer.get(shortname):

            if not check_connection(DatabaseContainer.get(shortname)):
                BindContainer.delete(shortname)
            else:
                if table_name == None:
                    return f(host, shortname)
                return f(host, shortname, table_name)

        url = url_for("blueprint.database_connect",
                      host=host,
                      shortname=shortname)
        return make_response(
            render_template("database/error.html", host=host, url=url), 200)
Beispiel #5
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)