#3600: Newforms label translation fails
---------------------------------------------------------+------------------
Reporter: Timo |
Owner: adrian
Status: new |
Component: django.newforms
Version: SVN |
Resolution:
Keywords: newforms translation internationalization |
Stage: Accepted
Has_patch: 1 |
Needs_docs: 0
Needs_tests: 0 |
Needs_better_patch: 1
---------------------------------------------------------+------------------
Comment (by karsu):
It is good idea to put unicode to Field class!
I have tried to underestand that translation problem. I have noticed if I
create new instance from SomeForm class only at first time it defines
'base_fields'. Now if you have some "dynamic" data in form class for
example: translation, choices etc, all Fields datas will be generate to
"static". Once a new instance from SomeForm is created base_fields are
copied and their "old" data is used while generating data to create new
form fields.
Test case for ChoiceField dymanic data
{{{
from django.db import models
class City(models.Model):
name = models.CharField(maxlength=100)
form_tests = r"""
>>> from django.newforms import *
>>> def get_all_cities():
... for i in City.objects.all():
... yield (i.id, i.name)
>>> c = City.objects.create(name="Helsinki")
>>> c.save()
>>> c = City.objects.create(name="Lahti")
>>> c.save()
>>> class CityForm(Form):
... cities = ChoiceField(choices=get_all_cities())
>>> f = CityForm()
>>> print f.as_p()
<p><label for="id_cities">Cities:</label> <select name="cities"
id="id_cities">
<option value="1">Helsinki</option>
<option value="2">Lahti</option>
</select></p>
>>> c = City.objects.create(name="London")
>>> c.save()
>>> print [(city) for city in get_all_cities()]
[(1, 'Helsinki'), (2, 'Lahti'), (3, 'London')]
>>> f = CityForm()
>>> print f.as_p()
<p><label for="id_cities">Cities:</label> <select name="cities"
id="id_cities">
<option value="1">Helsinki</option>
<option value="2">Lahti</option>
<option value="3">London</option>
</select></p>
"""
__test__ = {
'form_tests': form_tests,
}
if __name__ == "__main__":
import doctest
doctest.testmod()
}}}
--
Ticket URL: <http://code.djangoproject.com/ticket/3600#comment:7>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---