本文整理汇总了Python中forms.GroupForm.validate_on_submit方法的典型用法代码示例。如果您正苦于以下问题:Python GroupForm.validate_on_submit方法的具体用法?Python GroupForm.validate_on_submit怎么用?Python GroupForm.validate_on_submit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.GroupForm
的用法示例。
在下文中一共展示了GroupForm.validate_on_submit方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: groups
# 需要导入模块: from forms import GroupForm [as 别名]
# 或者: from forms.GroupForm import validate_on_submit [as 别名]
def groups():
form = GroupForm()
if form.validate_on_submit():
group_id = form.id.data
if group_id:
group = models.Group.query.get(group_id)
group.name = form.name.data
else:
group = models.Group(name=form.name.data)
db.session.add(group)
db.session.commit()
flash('The group was successffully saved.', 'success')
return redirect(url_for('groups'))
groups = models.Group.query.all()
return render_template('groups.html', form=form, groups=groups)
示例2: create_group
# 需要导入模块: from forms import GroupForm [as 别名]
# 或者: from forms.GroupForm import validate_on_submit [as 别名]
def create_group():
if g.user.max_groups():
flash(gettext('How many groups do you need to be in? Only 5 for you :)'))
return redirect(url_for('index'))
form = GroupForm()
if form.validate_on_submit():
group = Group(group_name = form.group_name.data,
about_group = form.about_group.data,
public = form.public.data)
db.session.add(group)
db.session.commit()
# Create group, add creator to admin and user list.
db.session.add(group.add_admin(g.user))
db.session.add(group.add_user(g.user))
db.session.commit()
flash('Welcome to your new group! Now add some friends!')
return redirect(url_for('group', group_id = group.id))
return render_template('group_form.html',
title = 'Create Group',
form = form)
示例3: group
# 需要导入模块: from forms import GroupForm [as 别名]
# 或者: from forms.GroupForm import validate_on_submit [as 别名]
def group(id=None):
form = GroupForm()
db = startdbc()
if id is not None:
cur = db.cursor()
cur.execute("SELECT name, year, specialization_name from groups where id = %s", [id])
res = cur.fetchone()
stopdbc(db)
if res is None:
# TODO: Сюда лучше flash
abort(404)
(name_data, year_data, specialization_data) = res
# TODO: почему нужно перекодировать?
# http://stackoverflow.com/questions/5040532/python-ascii-codec-cant-decode-byte
# https://github.com/psycopg/psycopg2/blob/master/examples/encoding.py
specialization_data = unicode(specialization_data, "utf8")
name_data = unicode(name_data, "utf8")
return render_template('group.html', read=True, id=id, form=form, name_data=name_data, year_data=year_data,
specialization_data=specialization_data)
# получить специализации,
form.specializationsf.choices = get_specializations(db)
if form.validate_on_submit(): # в т.ч. request.method == 'POST':
# добавление новой группы, если успешно, то открыть её просмотр
cur = db.cursor()
cur.callproc("add_group", [form.namef.data, form.specializationsf.data, form.yearf.data])
id = cur.fetchone()[0]
stopdbc(db)
# TODO: почему url_for cant find id?
# http://127.0.0.1:5000/group/?id=10
# return redirect(url_for('group', id=id))
return redirect(url_for('group') + str(id)) # "{}".format()
else:
# показать форму для создания новой группы
stopdbc(db)
return render_template('group.html', title=u"Создание учебной группы", read=False, form=form)
示例4: create
# 需要导入模块: from forms import GroupForm [as 别名]
# 或者: from forms.GroupForm import validate_on_submit [as 别名]
def create():
create_form = GroupForm(request.form)
if create_form.validate_on_submit():
logging.debug("form validated")
logging.info("CREATE: %s", json_from_form(create_form))
new_session=mongo_db.study_sessions.StudySession()
# Get and parse gelocation data from form.
# location_data = create_form.geo_location.data.split(',')
# lat = float(location_data[0])
# lon = float(location_data[1])
# new_session.geo_location={
# 'type':'Point',
# 'coordinates':[lon, lat]}
# store department as lower case so search works
new_session.course_no=str(create_form.course_no.data)
new_session.time=create_form.datetime.data
new_session.location=create_form.where.data
new_session.description=create_form.assignment.data
if current_user.is_authenticated():
new_session.contact_info=current_user.email
new_session.name=current_user.name.first + ' ' + current_user.name.last
new_session.school=current_user.school
new_session.department=smart_search(create_form.department.data,
current_user.school)
else:
new_session.contact_info=create_form.email.data
new_session.name='Anonymous'
new_session.school=create_form.school.data
new_session.department=smart_search(create_form.department.data,
create_form.school.data)
new_session.details=create_form.details.data
new_session.save()
flash("Group Created!")
return redirect(url_for('group', group_id=new_session._id))
return render_template('create.html', username='dummy', form=create_form);