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...

On Monday, July 6, 2015 at 3:10:02 PM UTC+3, Richard Cheesmar wrote:
>
> 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
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-appengine.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-appengine/c91e4d99-2bf3-454a-ad00-b796c905713b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to