P
P
Pavel2017-08-03 05:41:39
Flask
Pavel, 2017-08-03 05:41:39

How to simplify form processing?

def enabled_user():
    return User.query

class AddOperationForm(FlaskForm):
    email = QuerySelectField(query_factory=enabled_user, get_label='email')
    ident = QuerySelectField(query_factory=enabled_user, get_label='ident')
    operation = SelectField('Тип операции', coerce=int)
    amount = IntegerField('Сумма', validators=[DataRequired()])
    # submit = SubmitField('Добавить')

    def __init__(self, *args, **kwargs):
        super(AddOperationForm, self).__init__(*args, **kwargs)
        self.operation.choices = [(op.value, op.name) for op in Operation]

@blueprint.route('/', methods=['GET', 'POST'])
@login_required
def index():
    form = AddOperationForm()
    return render_template('operation/index.html', form=form)


The rendered page contains a jquery datatables dynamic table. Based on what I do not want to update the entire page, but only send an ajax request. But in this case, you need to process this request in another handler

@blueprint.route('/', methods=['POST'])
@login_required
def add_operation():
    form = AddOperationForm(request.???)


How to reuse form validation?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pcdesign, 2017-08-03
@toobinks

https://medium.com/@doobeh/posting-a-wtform-via-aj...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question