Python wtforms.fields.SelectMultipleField() Examples

The following are 3 code examples of wtforms.fields.SelectMultipleField(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module wtforms.fields , or try the search function .
Example #1
Source File: fields.py    From udata with GNU Affero General Public License v3.0 5 votes vote down vote up
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) 
Example #2
Source File: server.py    From isdi with MIT License 5 votes vote down vote up
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']) 
Example #3
Source File: server.py    From isdi with MIT License 5 votes vote down vote up
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)