当前位置: 首页>>代码示例>>Python>>正文


Python fields.SelectMultipleField方法代码示例

本文整理汇总了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) 
开发者ID:opendatateam,项目名称:udata,代码行数:11,代码来源:fields.py

示例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']) 
开发者ID:stopipv,项目名称:isdi,代码行数:34,代码来源:server.py

示例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) 
开发者ID:stopipv,项目名称:isdi,代码行数:31,代码来源:server.py


注:本文中的wtforms.fields.SelectMultipleField方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。