本文整理汇总了Python中forms.ProfileForm.validate方法的典型用法代码示例。如果您正苦于以下问题:Python ProfileForm.validate方法的具体用法?Python ProfileForm.validate怎么用?Python ProfileForm.validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.ProfileForm
的用法示例。
在下文中一共展示了ProfileForm.validate方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import validate [as 别名]
def post(self):
user = tusers.get_current_user()
if user:
form = ProfileForm(self.request.POST)
if (form.validate()):
user.full_name = form.name.data
user.current_institution = form.institution.data
user.public_profile = form.public.data
user.phone = form.phone.data
user.put()
if form.email.data:
user.change_email(form.email.data)
if form.email_code.data:
user.verify_email(form.email_code.data)
self.redirect('/update_profile')
else:
template_values = {
'user' : user,
'logout' : tusers.create_logout_url('/'),
'form' : form
}
template = JINJA_ENVIRONMENT.get_template('view/update_profile.html')
self.response.write(template.render(template_values))
else:
self.redirect(tusers.create_login_url(self.request.uri))
示例2: profile_add
# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import validate [as 别名]
def profile_add():
form = ProfileForm(request.form)
if request.method == 'GET':
return render_template('profile_add.html',form=form)
if form.validate() and request.method == 'POST':
first_name = request.form['first_name']
last_name = request.form['last_name']
age = request.form['age']
file = request.files['image']
username = request.form['username']
sex = request.form['sex']
filename = file.filename
file.save(os.path.join('app/static/uploads', filename))
# write the information to the database
newprofile = Myprofile(first_name=first_name,
last_name=last_name,
age=age,
sex=sex,
username=username,
image='/static/uploads/'+filename)
db.session.add(newprofile)
db.session.commit()
return "{} {} was added to the database".format(request.form['first_name'],
request.form['last_name'])
return render_template('profile_add.html',form=form)
示例3: profile
# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import validate [as 别名]
def profile():
form = ProfileForm(request.form)
if request.method == 'POST' and form.validate():
#need to set up salalchemy and reset the redirect to a
#different url_fo()
return redirect(url_for('profile'))
return render_template('profile.html', form=form)
示例4: profile
# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import validate [as 别名]
def profile():
form = ProfileForm()
if request.method == 'POST':
form = ProfileForm(request.form)
if form.validate():
current_user.set_password(form.new_password.data)
current_user.save()
flash({'type':'success', 'text':'Password updated'})
return redirect('/')
return render_template("/auth/profile.html", **locals())
示例5: profile
# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import validate [as 别名]
def profile():
user = Student.query.get(g.user.username)
if request.method == 'GET':
return render_template('student/profile.html',user=user)
form = ProfileForm(request.form)
if form.validate():
form.save()
flash(u"资料成功更新!")
user = Student.query.get(g.user.username)
render_template('student/profile.html',user=user)
for fieldName, errorMessages in form.errors.iteritems():
for err in errorMessages:
flash(err)
return render_template('student/profile.html',user=user)
示例6: profileedit
# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import validate [as 别名]
def profileedit():
form = ProfileForm()
if request.method == 'POST':
if form.validate() == False:
flash('All fields are required.')
return render_template('profileedit.html', form=form)
else:
profile = Profile(form.picture,form.home_address,form.gender,form.first_name ,form.middle_name,form.last_name,form.weapon_of_choice ,form.height,form.weight,form.build,form.complexion,form.hair_colour ,form.eye_colour ,form.ethnicity ,form.scars ,form.work_address ,form.work_contact_no,form.job_title ,form.mother_first_name ,form.mother_maiden_name,form.mother_surname,form.mother_address,form.mother_nationality,form.father_first_name,form.father_surname ,form.father_address,form.father_nationality,form.date_create)
db.session.add(profile)
db.session.commit()
return 'Form posted.'
elif request.method == 'GET':
return render_template('profileedit.html', form=form)
示例7: profile
# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import validate [as 别名]
def profile(profile_id=None):
msg = ''
p = get_user()
if profile_id:
p = User.query.get(profile_id)
form = ProfileForm(request.form)
if request.method == 'POST':
if not form.validate():
return render_template('profile.html', user=get_user(), profile=p, form=form, msg=msg)
else:
u = get_user()
u.display_name = form.display_name.data
u.email = form.email.data
db.session.commit()
msg = "profile upadted!"
return render_template('profile.html', user=get_user(), profile=p, form=form, msg=msg)
示例8: create_user
# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import validate [as 别名]
def create_user(user_id=None):
"""
Create or edit a user.
"""
form = ProfileForm()
if request.method == 'POST':
if form.validate():
if user_id != None:
# Edit a user
user = User.query.filter(User.id == user_id).first()
form.populate_obj(user)
if form.password.data != "":
user.set_password(form.password.data)
db.session.commit()
flash('User "' + user.firstname + '" successfully updated.', 'success')
else:
# Create a new user
role_user = Role.query.filter(Role.name == "user").first()
user = User(firstname=form.firstname.data,
lastname=form.lastname.data,
email=form.email.data,
pwdhash=generate_password_hash(form.password.data))
user.roles.extend([role_user])
db.session.add(user)
try:
db.session.commit()
except IntegrityError:
flash('Email already used.', 'warning')
return redirect(redirect_url())
flash('User "' + user.firstname + '" successfully created.', 'success')
return redirect("/admin/edit_user/"+str(user.id)+"/")
else:
return render_template('profile.html', form=form)
if request.method == 'GET':
if user_id != None:
user = User.query.filter(User.id == user_id).first()
form = ProfileForm(obj=user)
message = "Edit the user <i>" + user.firstname + "</i>"
else:
form = ProfileForm()
message="Add a new user"
return render_template('/admin/create_user.html', form=form, message=message)
示例9: info
# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import validate [as 别名]
def info():
user_id = g.current_login_id
user_profile = g.db.query(UserProfile).filter(UserProfile.user_id==user_id).one()
if request.method == "POST":
form = ProfileForm(request.form)
if form.validate():
try:
user_profile.company_name = form.company_name.data
user_profile.contact_name = form.contact.data
user_profile.mobile = form.mobile.data
user_profile.company_addr = form.addr.data
g.db.flush()
success = u"修改用户资料成功"
except Exception, e:
log.error(e.message)
g.db.rollback()
errors = [u"未知异常",]
else:
errors = [v[0] for k, v in form.errors.iteritems()]
示例10: profile
# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import validate [as 别名]
def profile():
if login() is True: return redirect(url_for('start.index'))
customer = Customer.query.get(session['customer_id'])
profileform = ProfileForm()
# upate profile
if request.form:
form = ProfileForm(request.form)
if request.method == 'POST' and form.validate():
update = Customer(
form.first_name.data,
form.last_name.data,
form.email.data,
form.password.data
)
if db.session.commit(update):
flash("Profile updates succesfully")
return render_template('customer/profile.html', customer=customer,
profileform=profileform)
示例11: profile
# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import validate [as 别名]
def profile():
text = db_queries.get_page_content('profile')
if request.method == 'POST':
#if the submit button was hit, loads the information into the form
form = ProfileForm(request.form)
if form.validate():
#sends the user to the profile/edit profile page with updated information
# if is_profile_changed(form):
# #user profile has been changed, update the database
db_posts.update_profile(form, current_user.primary_email)
text = db_queries.get_page_content('profile')
profile = db_queries.get_profile(current_user.primary_email)
return render_template("my_profile.html", text=text, profile=profile, form=form, leftProfileContent=profile)
else:
profile = db_queries.get_profile(current_user.primary_email)
return render_template("my_profile.html", text=text, profile=profile, form=form, leftProfileContent=profile)
#sends the user to the profile/edit profile page for GET methods
profile = db_queries.get_profile(current_user.primary_email)
form = ProfileForm(obj=profile)
return render_template("my_profile.html", text=text, profile=profile, form=form, leftProfileContent=profile)
示例12: profile
# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import validate [as 别名]
def profile():
"""
Edit the profile of the currently logged user.
"""
user = User.query.filter(User.email == g.user.email).first()
form = ProfileForm()
if request.method == 'POST':
if form.validate():
form.populate_obj(user)
if form.password.data != "":
user.set_password(form.password.data)
db.session.commit()
flash('User "' + user.firstname + '" successfully updated.', 'success')
return redirect(url_for('profile'))
else:
return render_template('profile.html', form=form)
if request.method == 'GET':
form = ProfileForm(obj=user)
return render_template('profile.html', user=user, form=form)
示例13: profile
# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import validate [as 别名]
def profile():
form = ProfileForm()
if request.method == 'POST':
if form.validate() == False:
return render_template('profile.html', form=form)
else:
user = db.session.query(User).filter_by(email=session['email']).first()
if form.firstname.data:
user.firstname = form.firstname.data
if form.lastname.data:
user.lastname = form.lastname.data
if form.password.data:
user.set_password(form.password.data)
db.session.commit()
return redirect(url_for('contacts'))
elif request.method == 'GET':
return render_template('profile.html', form=form)
示例14: profile
# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import validate [as 别名]
def profile(user_id, page=1):
user = User.query.get(user_id)
if not user:
return redirect(url_for('Common.index'))
pagination = Article.query.filter_by(deleted=False, author=user).order_by(Article.id.desc())\
.paginate(page, per_page=10, error_out=True)
form = ProfileForm(request.form)
if request.method == 'POST' and form.validate():
profile = json.loads(user.verbose) if user.verbose else dict()
profile['mail'] = form.mail.data
profile['homepage'] = form.homepage.data
profile['brief'] = form.brief.data
user.verbose = json.dumps(profile)
f = request.files['avatar']
if f:
try:
filename = save_file(f)
user.avatar = filename
except:
pass
user.save()
profile = json.loads(user.verbose) if user.verbose else None
kwargs = dict(
user=user,
profile_form=form,
profile=profile,
pagination=pagination,
)
return render_template('user/profile.html', **kwargs)