本文整理汇总了Python中forms.SettingsForm.validate方法的典型用法代码示例。如果您正苦于以下问题:Python SettingsForm.validate方法的具体用法?Python SettingsForm.validate怎么用?Python SettingsForm.validate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.SettingsForm
的用法示例。
在下文中一共展示了SettingsForm.validate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import validate [as 别名]
def post(self):
if self.group != '1':
self.render("404.html", username=self.username, group=self.group)
arguments = {
"page_size": self.get_argument("pagesize"),
"status_name": self.get_argument("statusname"),
"group_name": self.get_argument("groupname"),
"type_name": self.get_argument("typename"),
}
settings = get_settings(self.session)
form = SettingsForm(self.request.arguments)
update_error = settings_update_validation(self.session)
if form.validate():
if update_error == "":
update_settings(self.session, settings, arguments)
self.redirect("/admin/settings")
else:
self.render(
"/admin/settings.html",
username = self.username,
group = self.group,
settings = settings,
form = form,
db_error = update_error
)
else:
self.render(
"/admin/settings.html",
username = self.username,
group = self.group,
settings = settings,
form = form,
db_error = None
)
示例2: user_settings
# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import validate [as 别名]
def user_settings():
"""User settings"""
user = session["user"]
form = SettingsForm(email=user.email)
if request.method == "POST" and form.validate():
user_changed = False
if request.form["email"] and request.form["email"] != user.email:
user.email = request.form["email"]
user_changed = True
flash("Email address saved!")
if request.form["password"]:
user.set_password(request.form["password"])
user_changed = True
user.save()
flash("Your password was successfully changed!")
if user_changed:
user.save()
return redirect(url_for("page"))
return render_template("settings.html", form=form)
示例3: settings
# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import validate [as 别名]
def settings():
form = SettingsForm(request.form)
if request.method == "POST":
form = SettingsForm(request.form)
if form.validate():
uchanged = False
pchanged = False
user = current_user
profile = user.profile
if user.username != form.username.data:
user.username = form.username.data
if user.modify_chance <= 0:
form.username.errors.append(u"您修改用户名的机会已经用完,无法再修改用户名!")
return render_template("settings.html", form=form)
if User.query.filter(User.username == form.username.data).first():
form.username.errors.append(u"该用户名已被使用!")
return render_template("settings.html", form=form)
uchanged = True
user.modify_chance -= 1
if user.modify_chance <= 0:
user.modify_chance = 0
form.username.extra_class = "disable"
# if user.nickname != form.nickname.data:
# user.nickname = form.nickname.data
# uchanged =True
if (
profile.city != form.city.data
or profile.province != form.province.data
or profile.birthday != form.birthday.data
or profile.blog != form.blog.data
or profile.descp != form.descp.data
or profile.signature != form.signature.data
or profile.realname != form.realname.data
or profile.idcard != form.idcard.data
):
profile.city = form.city.data
profile.province = form.province.data
profile.birthday = form.birthday.data
profile.blog = form.blog.data
profile.descp = form.descp.data
profile.signature = form.signature.data
profile.realname = form.realname.data
profile.idcard = form.idcard.data
pchanged = True
if uchanged:
db.session.add(user)
if pchanged:
db.session.add(profile)
if uchanged or pchanged:
db.session.commit()
if uchanged:
mcache_set(str(user.id), user)
login_user(user, remember=True)
# return redirect("/")
else:
flash(u"个人资料设置成功!")
return render_template("settings.html", form=form)
form = settings_from_user(current_user)
return render_template("settings.html", form=form)