コード例 #1
0
def create_conf():
    form = ConfigurationForm(request.form)
    if request.method == 'POST' and form.validate():
        try:
            configuration = Configuration()
            form.populate_obj(configuration)
            db.session.add(configuration)
            db.session.commit()
            return redirect(url_for('conf', id=configuration.id))
        except Exception as error:
            flash("Error creating configuration.", category="danger")
            app.logger.error("Error creating configuration {}\n{}".format(
                error, traceback.format_exc()))
    return render_template('forms/model.jinja',
                           form=form,
                           action=url_for('create_conf'),
                           section='other')
コード例 #2
0
def edit_conf(id):
    conf = Configuration.query.get(id)
    form = ConfigurationForm(obj=conf)
    if request.method == 'POST':
        try:
            form = ConfigurationForm(request.form, obj=conf)
            if form.validate():
                form.populate_obj(conf)
                db.session.commit()
                flash("Stillingum var breytt", category='success')
                return redirect(url_for("conf", id=conf.id))
        except Exception as error:
            app.logger.error('Error updating a configuration : {}\n{}'.format(
                error, traceback.format_exc()))
    return render_template('forms/model.jinja',
                           form=form,
                           type='edit',
                           action=url_for('edit_conf', id=id),
                           section='other')
コード例 #3
0
ファイル: views.py プロジェクト: VaclavDedik/triager
def settings():
    form = ConfigurationForm(obj=config)

    if form.validate_on_submit():
        # auth__admin is special, because it needs to be hashed before being
        # passed to the config and saved
        auth__admin = form.auth__admin.data
        form.auth__admin.data = None
        form.populate_obj(config)
        if auth__admin:
            config.auth__admin = hash_pwd(auth__admin)

        config.save()
        flash("Settings successfully updated")
        return redirect(url_for("settings"))

    # No need to present a hash digest to the user :)
    form.auth__admin.data = None

    return render_template("settings.html", form=form)
コード例 #4
0
def settings():
    form = ConfigurationForm(obj=config)

    if form.validate_on_submit():
        # auth__admin is special, because it needs to be hashed before being
        # passed to the config and saved
        auth__admin = form.auth__admin.data
        form.auth__admin.data = None
        form.populate_obj(config)
        if auth__admin:
            config.auth__admin = hash_pwd(auth__admin)

        config.save()
        flash("Settings successfully updated")
        return redirect(url_for("settings"))

    # No need to present a hash digest to the user :)
    form.auth__admin.data = None

    return render_template("settings.html", form=form)