本文整理匯總了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)