librelist archives

« back to archive

Understand piece of code

Understand piece of code

From:
Julien Debaru
Date:
2013-07-31 @ 20:08
Hi everybody,

I'm learning Flask (And Python in same time), and i don't understand a 
piece of code.
Code is here :
     MyForm = model_form(MyModel, Form)
     model = MyModel.get(id)
     form = MyForm(request.form, model)

I don't understand how it's possible to put "request.form" and "model" 
in MyForm. How it works ? If anybody can explain me, i'd be grateful.

Thanks.

Re: [flask] Understand piece of code

From:
Andy Dirnberger
Date:
2013-07-31 @ 21:10
Hi,

I suspect that model_form creates and returns a new type, which is then
referenced by MyForm.

form = MyForm(request.form, model) would then call Form.__init__, providing
it both request.form and an instance of MyModel.

Best,
A


On Wed, Jul 31, 2013 at 4:08 PM, Julien Debaru <jdebaru@gmail.com> wrote:

> Hi everybody,
>
> I'm learning Flask (And Python in same time), and i don't understand a
> piece of code.
> Code is here :
>      MyForm = model_form(MyModel, Form)
>      model = MyModel.get(id)
>      form = MyForm(request.form, model)
>
> I don't understand how it's possible to put "request.form" and "model"
> in MyForm. How it works ? If anybody can explain me, i'd be grateful.
>
> Thanks.
>

Re: [flask] Understand piece of code

From:
Andy Dirnberger
Date:
2013-07-31 @ 21:15
I suspect that this is the model_form you're using:


https://bitbucket.org/simplecodes/wtforms/src/8a0ae49a66587dadb5a87c1ee0c69cfe9518c1c7/wtforms/ext/sqlalchemy/orm.py?at=default#cl-252

A


On Wed, Jul 31, 2013 at 5:10 PM, Andy Dirnberger <dirn@dirnonline.com>wrote:

> Hi,
>
> I suspect that model_form creates and returns a new type, which is then
> referenced by MyForm.
>
> form = MyForm(request.form, model) would then call Form.__init__,
> providing it both request.form and an instance of MyModel.
>
> Best,
> A
>
>
> On Wed, Jul 31, 2013 at 4:08 PM, Julien Debaru <jdebaru@gmail.com> wrote:
>
>> Hi everybody,
>>
>> I'm learning Flask (And Python in same time), and i don't understand a
>> piece of code.
>> Code is here :
>>      MyForm = model_form(MyModel, Form)
>>      model = MyModel.get(id)
>>      form = MyForm(request.form, model)
>>
>> I don't understand how it's possible to put "request.form" and "model"
>> in MyForm. How it works ? If anybody can explain me, i'd be grateful.
>>
>> Thanks.
>>
>
>