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