本文整理汇总了Python中wtforms.fields.SelectMultipleField方法的典型用法代码示例。如果您正苦于以下问题:Python fields.SelectMultipleField方法的具体用法?Python fields.SelectMultipleField怎么用?Python fields.SelectMultipleField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wtforms.fields
的用法示例。
在下文中一共展示了fields.SelectMultipleField方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: iter_choices
# 需要导入模块: from wtforms import fields [as 别名]
# 或者: from wtforms.fields import SelectMultipleField [as 别名]
def iter_choices(self):
localized_choices = [
(value, self._(label) if label else '', selected)
for value, label, selected
in super(SelectMultipleField, self).iter_choices()
]
for value, label, selected in sorted(localized_choices,
key=lambda c: c[1]):
yield (value, label, selected)
示例2: client_forms
# 需要导入模块: from wtforms import fields [as 别名]
# 或者: from wtforms.fields import SelectMultipleField [as 别名]
def client_forms():
if 'clientid' not in session:
return redirect(url_for('index'))
prev_submitted = Client.query.filter_by(clientid=session['clientid']).first()
if prev_submitted:
return redirect(url_for('edit_forms'))
# retrieve form defaults from db schema
client = Client()
form = ClientForm(request.form)
if request.method == 'POST':
try:
if form.validate():
print('VALIDATED')
# convert checkbox lists to json-friendly strings
for field in form:
if field.type == 'SelectMultipleField':
field.data = json.dumps(field.data)
form.populate_obj(client)
client.clientid = session['clientid']
sa.session.add(client)
sa.session.commit()
return render_template('main.html', task="form", formdone='yes', title=config.TITLE)
except Exception as e:
print('NOT VALIDATED')
print(e)
sa.session.rollback()
#clients_list = Client.query.all()
return render_template('main.html', task="form", form=form, title=config.TITLE, clientid=session['clientid'])
示例3: edit_forms
# 需要导入模块: from wtforms import fields [as 别名]
# 或者: from wtforms.fields import SelectMultipleField [as 别名]
def edit_forms():
if request.method == 'POST':
clientnote = request.form.get('clientnote', request.args.get('clientnote'))
if clientnote: # if requesting a form to edit
session['form_edit_pk'] = clientnote # set session cookie
form_obj = Client.query.get(clientnote)
form = ClientForm(obj=form_obj)
for field in form:
if field.type == 'SelectMultipleField':
field.data = json.loads(''.join(field.data))
return render_template('main.html', task="form",form=form, title=config.TITLE, clientid=form_obj.clientid)
else: # if edits were submitted
form_obj = Client.query.get(session['form_edit_pk'])
cid = form_obj.clientid # preserve before populate_obj
form = ClientForm(request.form)
if form.validate():
print('VALIDATED')
# convert checkbox lists to json-friendly strings
for field in form:
if field.type == 'SelectMultipleField':
field.data = json.dumps(field.data)
form.populate_obj(form_obj)
form_obj.clientid = cid
sa.session.commit()
return render_template('main.html', task="form", formdone='yes', title=config.TITLE)
clients = Client.query.all()
return render_template('main.html', clients=clients, task="formedit", title=config.TITLE)