stop wtforms from caching

38 views
Skip to first unread message

Richard Cheesmar

unread,
Jul 6, 2015, 8:08:32 AM7/6/15
to web...@googlegroups.com
I have a form which generates some selects using certain data. This is done using wtforms with python, webapp2, gae on the server and passed as a kwarg to the client. The site is multilingual using Babel translations. When I change the language on the production server the form gets called but the data doesn't change language. This works fine on the development server, but not in production.

Code:

This is attached to a handler class and does what it is supposed to

def form(self):
from product.product_data.forms import ProductForm
return ProductForm(self)


In my BaseHandler I have the following:

if hasattr(self, 'form'):
kwargs['form'] = self.form()
logging.info('get form')
logging.info(kwargs['form'].product_type())

Now the second log logging.info(kwargs['form'].product_type()) shows the correct language on the dev server but not on the production server

The form is thus:

class ProductForm(BaseForm):
"""
One big product form
"""

# ----------------PRODUCT-------------------

# Set the product types - alphabetically as either Radio buttons or selectmultiple
# which is interpreted as checkbox on client

p = realestate_product()

for k, v in p.iteritems():

try:
if v['set']:
set = get_set(v)
# Use locals() here to append product with content of k and make form variable
locals()['product_' + k] = fields.SelectField(v['label'], choices=set)
except:
if v['exclusive']:
locals()['product_' + k] = fields.SelectField(v['label'], choices=sorted(v['choices'], key=lambda tup: tup[1][1:]))
else:
locals()['product_' + k] = fields.SelectMultipleField(v['label'], choices=sorted(v['choices'], key=lambda tup: tup[1][1:]))

pass

At first I was using a webapp2.cached_property on the form method, but have since removed it as even when I called the form from a non cached method on change of language, it still didn't work.

Appreciate any feedback

Thanks

Richard Cheesmar

unread,
Jul 6, 2015, 10:26:36 AM7/6/15
to web...@googlegroups.com
ok, couldn't figure this one out, so rewrote the code to build selects in a simple def and pass as a parameter instead of form. Seems to be working. I have my suspicions regarding wtforms though, but it's a pain not knowing, but no time...
Reply all
Reply to author
Forward
0 new messages