当前位置: 首页>>代码示例>>Python>>正文


Python SettingsForm.validate_on_submit方法代码示例

本文整理汇总了Python中forms.SettingsForm.validate_on_submit方法的典型用法代码示例。如果您正苦于以下问题:Python SettingsForm.validate_on_submit方法的具体用法?Python SettingsForm.validate_on_submit怎么用?Python SettingsForm.validate_on_submit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在forms.SettingsForm的用法示例。


在下文中一共展示了SettingsForm.validate_on_submit方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: settings

# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import validate_on_submit [as 别名]
def settings(_id):
    # Authentication
    if current_user.id != _id and not current_user.is_admin():
        flash("You are not authorised to edit user {}'s settings.".format(_id), "danger")
        return redirect(request.referrer or url_for("index"))

    # Check user exists
    _user = User.query.filter(User.id == _id).first()
    if _user is None:
        flash("User {} not found.".format(_id), "danger")
        return redirect(request.referrer or url_for("index"))

    # Validate form, if submitted; else render it.
    form = SettingsForm(_user, request.form)

    if form.validate_on_submit():
        _user.email = form.email.data
        _user.show_ads = form.show_ads.data
        db.session.add(_user)
        db.session.commit()
        return redirect(request.args.get("next") or url_for("users.user", _id=_user.id))

    return render_template("users/settings.html",
                           title="Your settings - Dotabank",
                           user=_user,
                           form=form)
开发者ID:tusharvikky,项目名称:dotabank-web,代码行数:28,代码来源:views.py

示例2: settings

# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import validate_on_submit [as 别名]
def settings():
    global config
    # we need getattr for WTF
    formdata = namedtuple('Struct', config.keys())(*config.values())
    form = SettingsForm(obj=formdata, bait_session_retain=config['bait_session_retain'])

    if form.validate_on_submit():
        # the potential updates that we want to save to config file.
        options = {'bait_session_retain': form.bait_session_retain.data,
                   'malicious_session_retain': form.malicious_session_retain.data,
                   'ignore_failed_bait_session': form.ignore_failed_bait_session.data}
        update_config(options)
    return render_template('settings.html', form=form, user=current_user)
开发者ID:nghiemnv,项目名称:beeswarm,代码行数:15,代码来源:app.py

示例3: settings

# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import validate_on_submit [as 别名]
def settings():
    bait_session_retain = send_config_request('{0} {1}'.format(Messages.GET_CONFIG_ITEM, 'bait_session_retain'))
    ignore_failed_bait_session = ast.literal_eval(send_config_request('{0} {1}'.format(Messages.GET_CONFIG_ITEM, 'ignore_failed_bait_session')))
    malicious_session_retain = send_config_request('{0} {1}'.format(Messages.GET_CONFIG_ITEM, 'malicious_session_retain'))
    form = SettingsForm(bait_session_retain=bait_session_retain, malicious_session_retain=malicious_session_retain,
                        ignore_failed_bait_session=ignore_failed_bait_session)

    if form.validate_on_submit():
        # the potential updates that we want to save to config file.
        options = {'bait_session_retain': form.bait_session_retain.data,
                   'malicious_session_retain': form.malicious_session_retain.data,
                   'ignore_failed_bait_session': form.ignore_failed_bait_session.data}
        send_config_request('{0} {1}'.format(Messages.SET_CONFIG_ITEM, json.dumps(options)))
    return render_template('settings.html', form=form, user=current_user)
开发者ID:ichakra,项目名称:beeswarm,代码行数:16,代码来源:app.py

示例4: settings

# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import validate_on_submit [as 别名]
def settings():
    global config
    form = SettingsForm(obj=MultiDict(config))

    if form.validate_on_submit():
        # the potential updates that we want to save to config file.
        options = {'honeybee_session_retain': form.honeybee_session_retain.data,
                   'malicious_session_retain': form.malicious_session_retain.data,
                   'ignore_failed_honeybees': form.ignore_failed_honeybees.data}
        update_config_file(app.config['BEEKEEPER_CONFIG'], options)
        # update the global config dict.
        config = get_config_dict(app.config['BEEKEEPER_CONFIG'])

    return render_template('settings.html', form=form, user=current_user)
开发者ID:idkwim,项目名称:beeswarm,代码行数:16,代码来源:app.py

示例5: settings

# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import validate_on_submit [as 别名]
def settings():
    form = SettingsForm()
    if form.validate_on_submit():
        pass  # TODO - Make this actually do something
    elif request.method is not 'POST':
        form.username.data = g.user.username
        form.email.data = g.user.email
        form.gender.data = g.user.gender  # FIXME - Currently doesn't fill in radio button
        form.location.data = g.user.location
        form.about.data = g.user.about
    return render_template(
        'settings.html',
        form=form
    )
开发者ID:Kalenai,项目名称:flask-blog,代码行数:16,代码来源:views.py

示例6: settings

# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import validate_on_submit [as 别名]
def settings():
    pw_form = PasswordChangeForm()
    set_form = SettingsForm()
    if 'pw_change' in request.form and pw_form.validate_on_submit():
        try:
            g.user.set_password(pw_form.new_password.data)
            db.session.commit()
            flash(u'Passwort wurde geändert.')
        except:
            flash(u'Passwort konnte nicht geändert werden.')
    if 'settings_change' in request.form and set_form.validate_on_submit():
        g.user.name = set_form.name.data
        db.session.commit()
        flash(u'Einstellungen wurde geändert.')
    return render_template('user/settings.html', pw_form=pw_form, set_form=set_form)
开发者ID:danielthiel,项目名称:FlaskFactoryBone,代码行数:17,代码来源:views.py

示例7: account_settings

# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import validate_on_submit [as 别名]
def account_settings():
    form = SettingsForm(request.form)
    if form.validate_on_submit():
        current_user.email = form.email.data
        if form.password.data:
            current_user.password = form.password.data

        flash("Settings Updated")

        db.session.add(current_user)
        db.session.commit()

    form.email.data = current_user.email

    flash_errors(form)
    return render_template('users/account_settings.html',form =form)
开发者ID:Tranquilled,项目名称:mstsversion2,代码行数:18,代码来源:views.py

示例8: settings

# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import validate_on_submit [as 别名]
def settings():
    if not g.user.can_create_ballot():
        abort(403)

    settings = db.session.query(Settings).get(g.user.id)

    if settings is None:
        settings = Settings(id=g.user.id, signature=default_signature())

    form = SettingsForm(request.form, obj=settings)

    if request.method == "POST" and form.validate_on_submit():
        form.populate_obj(settings)
        db.session.add(settings)
        db.session.commit()
        flash(u"Nastavení bylo uloženo.", "success")
        return redirect(url_for("settings"))

    return render_template('settings.html', form=form)
开发者ID:svobodni,项目名称:ballot_box,代码行数:21,代码来源:views.py

示例9: settings

# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import validate_on_submit [as 别名]
def settings():
	message_box = ""
	settings_form = SettingsForm()

	#Only validate forms if the user pressed the submit button
	if 'submit_button' in request.form and request.form['submit_button'] == 'Update':
		if settings_form.validate_on_submit():
			if request.form['old_password'].strip() != current_user.password:
				message_box = message_box_html('The old password provided is incorrect.', error=True)
			else:
				current_user.email = request.form['email'].strip()
				current_user.username = request.form['username'].strip()
				current_user.password = request.form['password'].strip()
				db.session.commit()
				message_box = message_box_html('Your account settings have been changed.')
		else:	#Set error message to the first validation error.
			message_box = get_form_error(settings_form)

	return render_template('settings.html', settings_form=settings_form, message_box=message_box)
开发者ID:BradWells,项目名称:fluidScheduler,代码行数:21,代码来源:views.py

示例10: settings

# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import validate_on_submit [as 别名]
def settings(_id):
    """
    A user's settings page.

    Access restricted to the user themselves or admins.

    :param _id: The user ID of the user whose knobs we are tweaking.
    :return: Redirect if shit went wrong.
    :return: Response
    """

    # Check the visitor is the user whose settings we're trying to poke, or an admin.
    if current_user.id != _id and not current_user.is_admin():
        flash("You are not authorised to edit user {}'s settings.".format(_id), "error")
        return redirect(request.referrer or url_for("index"))

    # Get the user object for the given user ID.
    _user = User.query.filter(User.id == _id).first()
    if _user is None:
        flash("User {} not found.".format(_id), "error")
        return redirect(request.referrer or url_for("index"))

    # Get settings form! Woop!
    form = SettingsForm(_user, request.form)

    # If the form was submitted, update the user's settings and send the visitor on their way.
    if form.validate_on_submit():
        _user.email = form.email.data
        _user.show_ads = form.show_ads.data
        db.session.add(_user)
        db.session.commit()
        return redirect(request.args.get("next") or url_for("users.user", _id=_user.id))

    # Render the settings page.
    return render_template("users/settings.html",
                           title="{} - {}".format(
                               "Your settings" if current_user.id == _id else "{}'s settings".format(_user.name),
                               app.config['SITE_NAME']),
                           user=_user,
                           form=form)
开发者ID:Arcana,项目名称:pubstomp.info,代码行数:42,代码来源:views.py

示例11: settings

# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import validate_on_submit [as 别名]
def settings():
    if g.user is None or not g.user.is_authenticated():
        return redirect(url_for('login'))
    form = SettingsForm()
    if form.validate_on_submit():
        if (md5(form.oldpass.data).hexdigest() == md5(g.user.password).hexdigest()) and (form.newpass.data == form.passagain.data != None):
            g.user.password = md5(form.newpass.data).hexdigest()
        if ((form.newlogin.data != "") and (db.session.query(User).filter(User.nickname == form.newlogin.data).first() == None) and (md5(form.logpass.data).hexdigest() == md5(g.user.password).hexdigest())):
            g.user.nickname = form.newlogin.data
        if (form.title.data != ""):
            g.user.title = form.title.data
        if (form.description.data != ""):
            g.user.about = form.description.data
        if (form.userpic.data != ""):
            g.user.style = form.userpic.data
        if (form.backgr.data != ""):
            g.user.background = form.backgr.data
        db.session.add(g.user)
        db.session.commit()
        return redirect(url_for('settings'))
 
    return render_template('settings.html',
        form = form,
        user = g.user)
开发者ID:charepushko,项目名称:microblogging,代码行数:26,代码来源:views.py

示例12: settings

# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import validate_on_submit [as 别名]
def settings():
    form = SettingsForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            pass
    return render_template('settings.html', form=form)
开发者ID:mitnk,项目名称:justablog,代码行数:8,代码来源:views.py


注:本文中的forms.SettingsForm.validate_on_submit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。