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