Re: [google-appengine] Re: choice internationalization
You must translate the value you received in the POST request to the unicode value before you construct a form based on the POST/form content. You can use the _CHOICES_FORMATION variable. # these strings are in utf-8 - use it in the Model definition _CHOICES_FORMATION = ( 'Administração', 'Design Gráfico', 'Jornalismo', 'Marketing', 'Outras', ) class MyChoice(object): def __init__(self,val,usecode='latin_1'): self.val = unicode(val,usecode) self.valstr = self.val.encode('ascii','ignore') def __str__(self): return self.valstr def __unicode__(self): return self.val # use these for the Django form _CHOICES_FORMATION_FORM = tuple( [MyChoice(s,'utf-8') for s in _CHOICES_FORMATION] ) in your post handler def post(self): # translate the value for 'formation' to the right unicode string s = self.request.POST['formation'] self.request.POST['formation'] = [unicode(i) for i in _CHOICES_FORMATION_FORM if str(i)==s][0] 2011/2/18 Robert Kluin robert.kl...@gmail.com: Looks like on your model definition you've specified 'choices' for formation, and 'Administrao' is not one of the choices. Robert On Thu, Feb 17, 2011 at 20:42, Josir josi...@gmail.com wrote: I'm back on my choice internationalization problem. The solution given by djdjadji worked partially. Now the form is displayed but when I try to post data, I got a validation form error: Property formation is u'Administrao'; must be one of (, , 'Jornalismo', 'Marketing', 'Marketing', 'Psicologia', 'Publicidade', 'Radialismo', 'Cinema', 'Outras') Is this a Django 0.96 form error ? Is this solved if I upgrade Django to 1.2 ? Or: does somebody have any tip ? Thanks in advance, Josir Gomes On 26 jan, 15:05, djidjadji djidja...@gmail.com wrote: Then you have to build a class with a __str__() and a __unicode__() method. The __unicode__() method should return the string that is displayed in the combobox and the __str__() returns the value that is put in the field of the form at the time of submit. class MyChoice(object): def __init__(self,val): self.val = unicode(val,'latin_1') self.valstr = self.val.encode('ascii','ignore') def __str__(self): return self.valstr def __unicode__(self): return self.val _CHOICES_FORMATION = ( MyChoice('Administração'), MyChoice('Design Gráfico'), MyChoice('Jornalismo'), MyChoice('Marketing'), MyChoice('Outras'), ) 2011/1/26 Josir josi...@gmail.com: I got an error: File /home/josir/sist/google_appengine/google/appengine/ext/db/ djangoforms.py, line 170, in get_form_field choices.append((str(choice), unicode(choice))) UnicodeEncodeError: 'ascii' codec can't encode characters in position 10-13: ordinal not in range(128) What I understand is function get_form_field try to convert choice to a python string str(choice), where choice is each item of _CHOICES_FORMATION Any ideas on how to fix it ? Josir -- You received this message because you are subscribed to the Google Groups Google App Engine group. To post to this group, send email to google-appengine@googlegroups.com. To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.
[google-appengine] Re: choice internationalization
I'm back on my choice internationalization problem. The solution given by djdjadji worked partially. Now the form is displayed but when I try to post data, I got a validation form error: Property formation is u'Administrao'; must be one of (, , 'Jornalismo', 'Marketing', 'Marketing', 'Psicologia', 'Publicidade', 'Radialismo', 'Cinema', 'Outras') Is this a Django 0.96 form error ? Is this solved if I upgrade Django to 1.2 ? Or: does somebody have any tip ? Thanks in advance, Josir Gomes On 26 jan, 15:05, djidjadji djidja...@gmail.com wrote: Then you have to build a class with a __str__() and a __unicode__() method. The __unicode__() method should return the string that is displayed in the combobox and the __str__() returns the value that is put in the field of the form at the time of submit. class MyChoice(object): def __init__(self,val): self.val = unicode(val,'latin_1') self.valstr = self.val.encode('ascii','ignore') def __str__(self): return self.valstr def __unicode__(self): return self.val _CHOICES_FORMATION = ( MyChoice('Administração'), MyChoice('Design Gráfico'), MyChoice('Jornalismo'), MyChoice('Marketing'), MyChoice('Outras'), ) 2011/1/26 Josir josi...@gmail.com: I got an error: File /home/josir/sist/google_appengine/google/appengine/ext/db/ djangoforms.py, line 170, in get_form_field choices.append((str(choice), unicode(choice))) UnicodeEncodeError: 'ascii' codec can't encode characters in position 10-13: ordinal not in range(128) What I understand is function get_form_field try to convert choice to a python string str(choice), where choice is each item of _CHOICES_FORMATION Any ideas on how to fix it ? Josir -- You received this message because you are subscribed to the Google Groups Google App Engine group. To post to this group, send email to google-appengine@googlegroups.com. To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.
Re: [google-appengine] Re: choice internationalization
Looks like on your model definition you've specified 'choices' for formation, and 'Administrao' is not one of the choices. Robert On Thu, Feb 17, 2011 at 20:42, Josir josi...@gmail.com wrote: I'm back on my choice internationalization problem. The solution given by djdjadji worked partially. Now the form is displayed but when I try to post data, I got a validation form error: Property formation is u'Administrao'; must be one of (, , 'Jornalismo', 'Marketing', 'Marketing', 'Psicologia', 'Publicidade', 'Radialismo', 'Cinema', 'Outras') Is this a Django 0.96 form error ? Is this solved if I upgrade Django to 1.2 ? Or: does somebody have any tip ? Thanks in advance, Josir Gomes On 26 jan, 15:05, djidjadji djidja...@gmail.com wrote: Then you have to build a class with a __str__() and a __unicode__() method. The __unicode__() method should return the string that is displayed in the combobox and the __str__() returns the value that is put in the field of the form at the time of submit. class MyChoice(object): def __init__(self,val): self.val = unicode(val,'latin_1') self.valstr = self.val.encode('ascii','ignore') def __str__(self): return self.valstr def __unicode__(self): return self.val _CHOICES_FORMATION = ( MyChoice('Administração'), MyChoice('Design Gráfico'), MyChoice('Jornalismo'), MyChoice('Marketing'), MyChoice('Outras'), ) 2011/1/26 Josir josi...@gmail.com: I got an error: File /home/josir/sist/google_appengine/google/appengine/ext/db/ djangoforms.py, line 170, in get_form_field choices.append((str(choice), unicode(choice))) UnicodeEncodeError: 'ascii' codec can't encode characters in position 10-13: ordinal not in range(128) What I understand is function get_form_field try to convert choice to a python string str(choice), where choice is each item of _CHOICES_FORMATION Any ideas on how to fix it ? Josir -- You received this message because you are subscribed to the Google Groups Google App Engine group. To post to this group, send email to google-appengine@googlegroups.com. To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en. -- You received this message because you are subscribed to the Google Groups Google App Engine group. To post to this group, send email to google-appengine@googlegroups.com. To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.
[google-appengine] Re: choice internationalization
Thanks for replying dj. But it didn't work. When I use this code: #!/usr/bin/env python # -*- coding: utf-8 -*- # coding=utf-8 from google.appengine.ext import db _CHOICES_FORMATION = ( unicode('Administração','latin_1'), unicode('Design Gráfico','latin_1'), unicode('Marketing','latin_1'), unicode('Outras','latin_1'), ) I got an error: File /home/josir/sist/google_appengine/google/appengine/ext/db/ djangoforms.py, line 170, in get_form_field choices.append((str(choice), unicode(choice))) UnicodeEncodeError: 'ascii' codec can't encode characters in position 10-13: ordinal not in range(128) What I understand is function get_form_field try to convert choice to a python string str(choice), where choice is each item of _CHOICES_FORMATION Any ideas on how to fix it ? Josir On Jan 18, 7:01 pm, djidjadji djidja...@gmail.com wrote: In the unicode() call you must specify the encoding used, to decode the string to a unicode one. Or pass it a unicode string. example unicode(s,'utf-8') The Django code uses the default encoding string ascii. Or make a list of objects with a __unicode__() method that returns the unicode version of the string. You could build your choices list with unicode strings _CHOICES_FORMATION = ( unicode('Administração','latin_1'), unicode('Design Gráfico','latin_1'), unicode('Jornalismo','latin_1'), unicode('Marketing','latin_1'), unicode('Outras','latin_1'), ) Or use the encoding name that is used to edit the file. 2011/1/18Josirjosi...@gmail.com: Thanks for replying Zeynel. I've read this article before but I could not understand how can it help me because it does not have any citation on Django or GA. Usually, in pure Python/Django, I use the u' notation and forms and templates understand that the string is unicode. But on GA, it's not working. Do you have any specific suggestion/tip on the above code ? JosirGomes On Jan 18, 2:23 am, Zeynel azeyn...@gmail.com wrote: Can this be helpful to youhttp://www.stereoplex.com/blog/python-unicode-and-unicodedecodeerror On Jan 17, 10:53 pm,Josirjosi...@gmail.com wrote: Hi folks, I have the following code: _CHOICES_FORMATION = ( 'Administração', 'Design Gráfico', 'Jornalismo', 'Marketing', 'Outras', ) class Contact(db.Model): name = db.StringProperty(verbose_name='Nome', required=True) email = db.EmailProperty(verbose_name='E-mail', required=True) phone = db.StringProperty(verbose_name='Telefone') formation = db.StringProperty( verbose_name=u'Formação', choices=_CHOICES_FORMATION, default=_CHOICES_FORMATION[0]) When I try to run it, I got File /home/josir/sist/google_appengine/google/appengine/ext/db/ djangoforms.py, line 170, in get_form_field choices.append((str(choice), unicode(choice))) UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 10: ordinal not in range(128) To fix it, I tried: 1) u'Administração', 2) insert the header: #!/usr/bin/env python # -*- coding: utf-8 -*- # coding=utf-8 But both solution didn't work. How can I use latin (portuguese) characters on choice field ? Thanks in advance, Josir. -- You received this message because you are subscribed to the Google Groups Google App Engine group. To post to this group, send email to google-appengine@googlegroups.com. To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.
Re: [google-appengine] Re: choice internationalization
Then you have to build a class with a __str__() and a __unicode__() method. The __unicode__() method should return the string that is displayed in the combobox and the __str__() returns the value that is put in the field of the form at the time of submit. class MyChoice(object): def __init__(self,val): self.val = unicode(val,'latin_1') self.valstr = self.val.encode('ascii','ignore') def __str__(self): return self.valstr def __unicode__(self): return self.val _CHOICES_FORMATION = ( MyChoice('Administração'), MyChoice('Design Gráfico'), MyChoice('Jornalismo'), MyChoice('Marketing'), MyChoice('Outras'), ) 2011/1/26 Josir josi...@gmail.com: I got an error: File /home/josir/sist/google_appengine/google/appengine/ext/db/ djangoforms.py, line 170, in get_form_field choices.append((str(choice), unicode(choice))) UnicodeEncodeError: 'ascii' codec can't encode characters in position 10-13: ordinal not in range(128) What I understand is function get_form_field try to convert choice to a python string str(choice), where choice is each item of _CHOICES_FORMATION Any ideas on how to fix it ? Josir -- You received this message because you are subscribed to the Google Groups Google App Engine group. To post to this group, send email to google-appengine@googlegroups.com. To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.
[google-appengine] Re: choice internationalization
Thanks for replying Zeynel. I've read this article before but I could not understand how can it help me because it does not have any citation on Django or GA. Usually, in pure Python/Django, I use the u' notation and forms and templates understand that the string is unicode. But on GA, it's not working. Do you have any specific suggestion/tip on the above code ? Josir Gomes On Jan 18, 2:23 am, Zeynel azeyn...@gmail.com wrote: Can this be helpful to youhttp://www.stereoplex.com/blog/python-unicode-and-unicodedecodeerror On Jan 17, 10:53 pm, Josir josi...@gmail.com wrote: Hi folks, I have the following code: _CHOICES_FORMATION = ( 'Administração', 'Design Gráfico', 'Jornalismo', 'Marketing', 'Outras', ) class Contact(db.Model): name = db.StringProperty(verbose_name='Nome', required=True) email = db.EmailProperty(verbose_name='E-mail', required=True) phone = db.StringProperty(verbose_name='Telefone') formation = db.StringProperty( verbose_name=u'Formação', choices=_CHOICES_FORMATION, default=_CHOICES_FORMATION[0]) When I try to run it, I got File /home/josir/sist/google_appengine/google/appengine/ext/db/ djangoforms.py, line 170, in get_form_field choices.append((str(choice), unicode(choice))) UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 10: ordinal not in range(128) To fix it, I tried: 1) u'Administração', 2) insert the header: #!/usr/bin/env python # -*- coding: utf-8 -*- # coding=utf-8 But both solution didn't work. How can I use latin (portuguese) characters on choice field ? Thanks in advance, Josir. -- You received this message because you are subscribed to the Google Groups Google App Engine group. To post to this group, send email to google-appengine@googlegroups.com. To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.
Re: [google-appengine] Re: choice internationalization
In the unicode() call you must specify the encoding used, to decode the string to a unicode one. Or pass it a unicode string. example unicode(s,'utf-8') The Django code uses the default encoding string ascii. Or make a list of objects with a __unicode__() method that returns the unicode version of the string. You could build your choices list with unicode strings _CHOICES_FORMATION = ( unicode('Administração','latin_1'), unicode('Design Gráfico','latin_1'), unicode('Jornalismo','latin_1'), unicode('Marketing','latin_1'), unicode('Outras','latin_1'), ) Or use the encoding name that is used to edit the file. 2011/1/18 Josir josi...@gmail.com: Thanks for replying Zeynel. I've read this article before but I could not understand how can it help me because it does not have any citation on Django or GA. Usually, in pure Python/Django, I use the u' notation and forms and templates understand that the string is unicode. But on GA, it's not working. Do you have any specific suggestion/tip on the above code ? Josir Gomes On Jan 18, 2:23 am, Zeynel azeyn...@gmail.com wrote: Can this be helpful to youhttp://www.stereoplex.com/blog/python-unicode-and-unicodedecodeerror On Jan 17, 10:53 pm, Josir josi...@gmail.com wrote: Hi folks, I have the following code: _CHOICES_FORMATION = ( 'Administração', 'Design Gráfico', 'Jornalismo', 'Marketing', 'Outras', ) class Contact(db.Model): name = db.StringProperty(verbose_name='Nome', required=True) email = db.EmailProperty(verbose_name='E-mail', required=True) phone = db.StringProperty(verbose_name='Telefone') formation = db.StringProperty( verbose_name=u'Formação', choices=_CHOICES_FORMATION, default=_CHOICES_FORMATION[0]) When I try to run it, I got File /home/josir/sist/google_appengine/google/appengine/ext/db/ djangoforms.py, line 170, in get_form_field choices.append((str(choice), unicode(choice))) UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 10: ordinal not in range(128) To fix it, I tried: 1) u'Administração', 2) insert the header: #!/usr/bin/env python # -*- coding: utf-8 -*- # coding=utf-8 But both solution didn't work. How can I use latin (portuguese) characters on choice field ? Thanks in advance, Josir. -- You received this message because you are subscribed to the Google Groups Google App Engine group. To post to this group, send email to google-appengine@googlegroups.com. To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.
[google-appengine] Re: choice internationalization
Can this be helpful to you http://www.stereoplex.com/blog/python-unicode-and-unicodedecodeerror On Jan 17, 10:53 pm, Josir josi...@gmail.com wrote: Hi folks, I have the following code: _CHOICES_FORMATION = ( 'Administração', 'Design Gráfico', 'Jornalismo', 'Marketing', 'Outras', ) class Contact(db.Model): name = db.StringProperty(verbose_name='Nome', required=True) email = db.EmailProperty(verbose_name='E-mail', required=True) phone = db.StringProperty(verbose_name='Telefone') formation = db.StringProperty( verbose_name=u'Formação', choices=_CHOICES_FORMATION, default=_CHOICES_FORMATION[0]) When I try to run it, I got File /home/josir/sist/google_appengine/google/appengine/ext/db/ djangoforms.py, line 170, in get_form_field choices.append((str(choice), unicode(choice))) UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 10: ordinal not in range(128) To fix it, I tried: 1) u'Administração', 2) insert the header: #!/usr/bin/env python # -*- coding: utf-8 -*- # coding=utf-8 But both solution didn't work. How can I use latin (portuguese) characters on choice field ? Thanks in advance, Josir. -- You received this message because you are subscribed to the Google Groups Google App Engine group. To post to this group, send email to google-appengine@googlegroups.com. To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.