librelist archives

« back to archive

Best way to use Wtforms and MongoDB in Flask

Best way to use Wtforms and MongoDB in Flask

From:
lynadge
Date:
2012-06-08 @ 21:45
Hi,

what is the best way, how i can use Wtforms and MongoDB together with 
Flask.

For Wtforms i use flask-wtforms. Works perfect for my needs.

For MongoDB i use flask-pymongo, works also fine for my needs.

But, how can i bring it together? I tried flask-mongoengine, what has 
wtforms support. Sadly it is not well documented i think and there is no 
fun using it.

Is there a good and simple way to create ONE model for MongoDB and use 
it also as a form. Like in Django with Model and ModelForm.

I thought i found a way by creating a form with wtforms and add some 
methods to insert, update and delete but why i should reinvent the 
wheel, there are some good wheels ... but how can i put them together to 
a nice car? ;)

I hope you can read my bad english and can help me to solve this 
problem.

Regards, lynadge

Re: [flask] Best way to use Wtforms and MongoDB in Flask

From:
伍五
Date:
2012-06-09 @ 01:29
You should try Flask-MongoAlchemy
You can find the example from the github :
https://github.com/cobrateam/flask-mongoalchemy/
Its about MongoAlcehmy and WTForm, And then you just need write class of
python to use MongoDB

If you still want to use pymongo , After that you will know how to push
pymongo and wtforms together~

2012/6/9 lynadge <lynadge@barfooz.de>

> Hi,
>
> what is the best way, how i can use Wtforms and MongoDB together with
> Flask.
>
> For Wtforms i use flask-wtforms. Works perfect for my needs.
>
> For MongoDB i use flask-pymongo, works also fine for my needs.
>
> But, how can i bring it together? I tried flask-mongoengine, what has
> wtforms support. Sadly it is not well documented i think and there is no
> fun using it.
>
> Is there a good and simple way to create ONE model for MongoDB and use
> it also as a form. Like in Django with Model and ModelForm.
>
> I thought i found a way by creating a form with wtforms and add some
> methods to insert, update and delete but why i should reinvent the
> wheel, there are some good wheels ... but how can i put them together to
> a nice car? ;)
>
> I hope you can read my bad english and can help me to solve this
> problem.
>
> Regards, lynadge
>

Re: [flask] Best way to use Wtforms and MongoDB in Flask

From:
lynadge
Date:
2012-06-11 @ 07:52
Hey, thanks for your reply.

I think the way mongoAlchemy walks is not a DRY way. In the Example it 
looks like i touch the fields also two times. :/

Am 09.06.2012 02:29, schrieb 伍五:
> You should try Flask-MongoAlchemy
> You can find the example from the github
> :https://github.com/cobrateam/flask-mongoalchemy/ [1]
> Its about MongoAlcehmy and WTForm, And then you just need write class
> of python to use MongoDB
>
> If you still want to use pymongo , After that you will know how to
> push pymongo and wtforms together~
>
> 2012/6/9 lynadge <lynadge@barfooz.de [2]>
>
>> Hi,
>>
>> what is the best way, how i can use Wtforms and MongoDB together
>> with
>> Flask.
>>
>> For Wtforms i use flask-wtforms. Works perfect for my needs.
>>
>> For MongoDB i use flask-pymongo, works also fine for my needs.
>>
>> But, how can i bring it together? I tried flask-mongoengine, what
>> has
>> wtforms support. Sadly it is not well documented i think and there
>> is no
>> fun using it.
>>
>> Is there a good and simple way to create ONE model for MongoDB and
>> use
>> it also as a form. Like in Django with Model and ModelForm.
>>
>> I thought i found a way by creating a form with wtforms and add
>> some
>> methods to insert, update and delete but why i should reinvent the
>> wheel, there are some good wheels ... but how can i put them
>> together to
>> a nice car? ;)
>>
>> I hope you can read my bad english and can help me to solve this
>> problem.
>>
>> Regards, lynadge
>
>
>
> Links:
> ------
> [1] https://github.com/cobrateam/flask-mongoalchemy/
> [2] mailto:lynadge@barfooz.de

Re: [flask] Best way to use Wtforms and MongoDB in Flask

From:
Simon Sapin
Date:
2012-06-10 @ 02:51
Le 08/06/2012 23:45, lynadge a écrit :
> For Wtforms i use flask-wtforms. Works perfect for my needs.
>
> For MongoDB i use flask-pymongo, works also fine for my needs.
>
> But, how can i bring it together?

Apparently PyMongo works with dictionaries.

Once you have a validated Form object from WTForms, its 'data' attribute 
is a dict. You can either pass it directly to (Flask-)PyMongo or use 
some_other_dict.update(my_form.data)

This is all well-documented API in WTForms:

http://packages.python.org/WTForms/forms.html#the-form-class

Regards,
-- 
Simon Sapin

Re: [flask] Best way to use Wtforms and MongoDB in Flask

From:
lynadge
Date:
2012-06-17 @ 08:58
Hi,

for adding form content to mongodb it works perfect.

But when i try to make a edit form, it raise a TypeError. It is a 
similar problem like in this thread: 
http://groups.google.com/group/wtforms/browse_thread/thread/c5380381cdc8d304

The Problem lies in the DatetimeField. A spontaneous workaround is by 
using a TextField but i think, when there exist a DatetimeField why 
shouldn't i use it?..

Is there any approach for this scenario?

Am 10.06.2012 03:51, schrieb Simon Sapin:
> Le 08/06/2012 23:45, lynadge a écrit :
>> For Wtforms i use flask-wtforms. Works perfect for my needs.
>>
>> For MongoDB i use flask-pymongo, works also fine for my needs.
>>
>> But, how can i bring it together?
>
> Apparently PyMongo works with dictionaries.
>
> Once you have a validated Form object from WTForms, its 'data' 
> attribute
> is a dict. You can either pass it directly to (Flask-)PyMongo or use
> some_other_dict.update(my_form.data)
>
> This is all well-documented API in WTForms:
>
> http://packages.python.org/WTForms/forms.html#the-form-class
>
> Regards,

Re: [flask] Best way to use Wtforms and MongoDB in Flask

From:
lynadge
Date:
2012-06-17 @ 12:25
Hi,

for adding form content to mongodb it works perfect.

But when i try to make a edit form, it raise a TypeError. It is a
similar problem like in this thread:
http://groups.google.com/group/wtforms/browse_thread/thread/c5380381cdc8d304

The Problem lies in the DatetimeField. A spontaneous workaround is by
using a TextField but i think, when there exist a DatetimeField why
shouldn't i use it?..

Is there any approach for this scenario?

Am 10.06.2012 03:51, schrieb Simon Sapin:
> Le 08/06/2012 23:45, lynadge a écrit :
>> For Wtforms i use flask-wtforms. Works perfect for my needs.
>>
>> For MongoDB i use flask-pymongo, works also fine for my needs.
>>
>> But, how can i bring it together?
>
> Apparently PyMongo works with dictionaries.
>
> Once you have a validated Form object from WTForms, its 'data' 
> attribute
> is a dict. You can either pass it directly to (Flask-)PyMongo or use
> some_other_dict.update(my_form.data)
>
> This is all well-documented API in WTForms:
>
> http://packages.python.org/WTForms/forms.html#the-form-class
>
> Regards,

Re: [flask] Best way to use Wtforms and MongoDB in Flask

From:
lynadge
Date:
2012-06-22 @ 21:36
Ok, i solved this problem with a simple TextField. Not the best 
workaround but it works for me...

Now i have a problem with wtforms. In my form i have a BooleanField and 
i want to edit the Document/Object in my form. When i get the saved 
Document/Object from mongoDB the booleanfield is set to 'False'. So, if 
i put it in the form wtforms will set the BooleanField to 'True' but 
thats wrong and it should be 'False'. If i delete the one entry in 
MongoDB wtforms will set the BooleanField to false...but that is not the 
solution i want to...

Has Anyone an idea for this problem?

regards, lynadge

Am 10.06.2012 03:51, schrieb Simon Sapin:
> Le 08/06/2012 23:45, lynadge a écrit :
>> For Wtforms i use flask-wtforms. Works perfect for my needs.
>>
>> For MongoDB i use flask-pymongo, works also fine for my needs.
>>
>> But, how can i bring it together?
>
> Apparently PyMongo works with dictionaries.
>
> Once you have a validated Form object from WTForms, its 'data' 
> attribute
> is a dict. You can either pass it directly to (Flask-)PyMongo or use
> some_other_dict.update(my_form.data)
>
> This is all well-documented API in WTForms:
>
> http://packages.python.org/WTForms/forms.html#the-form-class
>
> Regards,

Re: [flask] Best way to use Wtforms and MongoDB in Flask

From:
lynadge
Date:
2012-06-11 @ 07:54
I will try it in the next few days. The idea looks very awesome and 
simple. :)

Am 10.06.2012 03:51, schrieb Simon Sapin:
> Le 08/06/2012 23:45, lynadge a écrit :
>> For Wtforms i use flask-wtforms. Works perfect for my needs.
>>
>> For MongoDB i use flask-pymongo, works also fine for my needs.
>>
>> But, how can i bring it together?
>
> Apparently PyMongo works with dictionaries.
>
> Once you have a validated Form object from WTForms, its 'data' 
> attribute
> is a dict. You can either pass it directly to (Flask-)PyMongo or use
> some_other_dict.update(my_form.data)
>
> This is all well-documented API in WTForms:
>
> http://packages.python.org/WTForms/forms.html#the-form-class
>
> Regards,

Re: [flask] Best way to use Wtforms and MongoDB in Flask

From:
azwar akbar
Date:
2012-06-11 @ 08:23
Hi lnadge, can you tell me your progress using WTForm with Flask + pyMongo?
I also use Flask + pyMongo and will use WTForm soon, so I need the advice.

Thank you.

On Mon, Jun 11, 2012 at 2:54 PM, lynadge <lynadge@barfooz.de> wrote:

> I will try it in the next few days. The idea looks very awesome and
> simple. :)
>
> Am 10.06.2012 03:51, schrieb Simon Sapin:
> > Le 08/06/2012 23:45, lynadge a écrit :
> >> For Wtforms i use flask-wtforms. Works perfect for my needs.
> >>
> >> For MongoDB i use flask-pymongo, works also fine for my needs.
> >>
> >> But, how can i bring it together?
> >
> > Apparently PyMongo works with dictionaries.
> >
> > Once you have a validated Form object from WTForms, its 'data'
> > attribute
> > is a dict. You can either pass it directly to (Flask-)PyMongo or use
> > some_other_dict.update(my_form.data)
> >
> > This is all well-documented API in WTForms:
> >
> > http://packages.python.org/WTForms/forms.html#the-form-class
> >
> > Regards,
>
>


-- 


regards,
Azwar Akbar

Re: [flask] Best way to use Wtforms and MongoDB in Flask

From:
lynadge
Date:
2012-06-11 @ 09:15
Hi, i work on an flask skeleton for my needs. I hope i get it ready at 
the end of the next weekend.

The current status you can find here: 
https://github.com/haengebruegge/flaskeleton

Am 11.06.2012 09:23, schrieb azwar akbar:
> Hi lnadge, can you tell me your progress using WTForm with Flask +
> pyMongo?
> I also use Flask + pyMongo and will use WTForm soon, so I need the
> advice.
>
> Thank you.
>
> On Mon, Jun 11, 2012 at 2:54 PM, lynadge <lynadge@barfooz.de [2]>
> wrote:
>
>> I will try it in the next few days. The idea looks very awesome and
>> simple. :)
>>
>> Am 10.06.2012 03:51, schrieb Simon Sapin:
>>
>>> Le 08/06/2012 23:45, lynadge a écrit :
>> >> For Wtforms i use flask-wtforms. Works perfect for my needs.
>> >>
>> >> For MongoDB i use flask-pymongo, works also fine for my needs.
>> >>
>> >> But, how can i bring it together?
>> >
>> > Apparently PyMongo works with dictionaries.
>> >
>> > Once you have a validated Form object from WTForms, its 'data'
>> > attribute
>> > is a dict. You can either pass it directly to (Flask-)PyMongo or
>> use
>> > some_other_dict.update(my_form.data)
>> >
>> > This is all well-documented API in WTForms:
>> >
>> > http://packages.python.org/WTForms/forms.html#the-form-class [1]
>> >
>> > Regards,

Re: [flask] Best way to use Wtforms and MongoDB in Flask

From:
azwar akbar
Date:
2012-06-11 @ 09:46
Hi, looked like very interesting... :-)
Thanks for your share...

Vielen dank.

On Mon, Jun 11, 2012 at 4:15 PM, lynadge <lynadge@barfooz.de> wrote:

> Hi, i work on an flask skeleton for my needs. I hope i get it ready at
> the end of the next weekend.
>
> The current status you can find here:
> https://github.com/haengebruegge/flaskeleton
>
> Am 11.06.2012 09:23, schrieb azwar akbar:
> > Hi lnadge, can you tell me your progress using WTForm with Flask +
> > pyMongo?
> > I also use Flask + pyMongo and will use WTForm soon, so I need the
> > advice.
> >
> > Thank you.
> >
> > On Mon, Jun 11, 2012 at 2:54 PM, lynadge <lynadge@barfooz.de [2]>
> > wrote:
> >
> >> I will try it in the next few days. The idea looks very awesome and
> >> simple. :)
> >>
> >> Am 10.06.2012 03:51, schrieb Simon Sapin:
> >>
> >>> Le 08/06/2012 23:45, lynadge a écrit :
> >> >> For Wtforms i use flask-wtforms. Works perfect for my needs.
> >> >>
> >> >> For MongoDB i use flask-pymongo, works also fine for my needs.
> >> >>
> >> >> But, how can i bring it together?
> >> >
> >> > Apparently PyMongo works with dictionaries.
> >> >
> >> > Once you have a validated Form object from WTForms, its 'data'
> >> > attribute
> >> > is a dict. You can either pass it directly to (Flask-)PyMongo or
> >> use
> >> > some_other_dict.update(my_form.data)
> >> >
> >> > This is all well-documented API in WTForms:
> >> >
> >> > http://packages.python.org/WTForms/forms.html#the-form-class [1]
> >> >
> >> > Regards,
>
>


-- 


regards,
Azwar Akbar

Re: [flask] Best way to use Wtforms and MongoDB in Flask

From:
lynadge
Date:
2012-06-11 @ 09:49
Thanks and no problem. ;)

Am 11.06.2012 10:46, schrieb azwar akbar:
> Hi, looked like very interesting... :-)
> Thanks for your share...
>
> Vielen dank.
>
> On Mon, Jun 11, 2012 at 4:15 PM, lynadge <lynadge@barfooz.de [4]>
> wrote:
>
>> Hi, i work on an flask skeleton for my needs. I hope i get it ready
>> at
>> the end of the next weekend.
>>
>> The current status you can find here:
>> https://github.com/haengebruegge/flaskeleton [1]
>>
>> Am 11.06.2012 09:23, schrieb azwar akbar:
>>
>>> Hi lnadge, can you tell me your progress using WTForm with Flask +
>> > pyMongo?
>> > I also use Flask + pyMongo and will use WTForm soon, so I need
>> the
>> > advice.
>> >
>> > Thank you.
>> >
>> > On Mon, Jun 11, 2012 at 2:54 PM, lynadge <lynadge@barfooz.de [2]
>> [2]>
>>
>>> wrote:
>> >
>> >> I will try it in the next few days. The idea looks very awesome
>> and
>> >> simple. :)
>> >>
>> >> Am 10.06.2012 03:51, schrieb Simon Sapin:
>> >>
>> >>> Le 08/06/2012 23:45, lynadge a écrit :
>> >> >> For Wtforms i use flask-wtforms. Works perfect for my needs.
>> >> >>
>> >> >> For MongoDB i use flask-pymongo, works also fine for my
>> needs.
>> >> >>
>> >> >> But, how can i bring it together?
>> >> >
>> >> > Apparently PyMongo works with dictionaries.
>> >> >
>> >> > Once you have a validated Form object from WTForms, its 'data'
>> >> > attribute
>> >> > is a dict. You can either pass it directly to (Flask-)PyMongo
>> or
>> >> use
>> >> > some_other_dict.update(my_form.data)
>> >> >
>> >> > This is all well-documented API in WTForms:
>> >> >
>> >> > http://packages.python.org/WTForms/forms.html#the-form-class
>> [3] [1]
>> >> >
>> >> > Regards,