Code

Ticket #8543: internationalized_order_and_delete_labels_for_formsets.diff

File internationalized_order_and_delete_labels_for_formsets.diff, 5.6 KB (added by versae, 6 years ago)

Patch file and regression test.

Line 
1Index: django/conf/locale/es/LC_MESSAGES/django.po
2===================================================================
3--- django/conf/locale/es/LC_MESSAGES/django.po (revisión: 8547)
4+++ django/conf/locale/es/LC_MESSAGES/django.po (copia de trabajo)
5@@ -3942,6 +3942,11 @@
6 msgid "Enter a valid IPv4 address."
7 msgstr "Introduzca una dirección IPv4 válida."
8 
9+#: forms/formsets.py:242
10+#: forms/formsets.py:244
11+msgid "Order"
12+msgstr "Orden"
13+
14 #: forms/models.py:514
15 msgid "Select a valid choice. That choice is not one of the available choices."
16 msgstr "Escoja una opción válida. Esa opción no está entre las disponibles."
17Index: django/conf/locale/es/LC_MESSAGES/django.mo
18===================================================================
19No se puede mostrar: el archivo está marcado como binario.
20svn:mime-type = application/octet-stream
21Index: django/forms/formsets.py
22===================================================================
23--- django/forms/formsets.py    (revisión: 8534)
24+++ django/forms/formsets.py    (copia de trabajo)
25@@ -1,6 +1,7 @@
26 from forms import Form
27 from django.utils.encoding import StrAndUnicode
28 from django.utils.safestring import mark_safe
29+from django.utils.translation import ugettext_lazy as _
30 from fields import IntegerField, BooleanField
31 from widgets import Media, HiddenInput
32 from util import ErrorList, ValidationError
33@@ -238,11 +239,11 @@
34         if self.can_order:
35             # Only pre-fill the ordering field for initial forms.
36             if index < self._initial_form_count:
37-                form.fields[ORDERING_FIELD_NAME] = IntegerField(label='Order', initial=index+1, required=False)
38+                form.fields[ORDERING_FIELD_NAME] = IntegerField(label=_(u'Order'), initial=index+1, required=False)
39             else:
40-                form.fields[ORDERING_FIELD_NAME] = IntegerField(label='Order', required=False)
41+                form.fields[ORDERING_FIELD_NAME] = IntegerField(label=_(u'Order'), required=False)
42         if self.can_delete:
43-            form.fields[DELETION_FIELD_NAME] = BooleanField(label='Delete', required=False)
44+            form.fields[DELETION_FIELD_NAME] = BooleanField(label=_(u'Delete'), required=False)
45 
46     def add_prefix(self, index):
47         return '%s-%s' % (self.prefix, index)
48Index: tests/regressiontests/forms/formsets.py
49===================================================================
50--- tests/regressiontests/forms/formsets.py     (revisión: 8534)
51+++ tests/regressiontests/forms/formsets.py     (copia de trabajo)
52@@ -432,6 +432,57 @@
53 [{'votes': 900, 'DELETE': True, 'ORDER': 2, 'choice': u'Fergie'}]
54 
55 
56+# FormSets with ordering + deletion and internationalization ##################
57+
58+>>> from django.utils.translation import activate, deactivate
59+>>> ChoiceFormSet = formset_factory(Choice, can_order=True, can_delete=True)
60+
61+>>> initial = [
62+...     {'choice': u'Calexico', 'votes': 100},
63+...     {'choice': u'Fergie', 'votes': 900},
64+...     {'choice': u'The Decemberists', 'votes': 500},
65+... ]
66+>>> formset = ChoiceFormSet(initial=initial, auto_id=False, prefix='choices')
67+>>> for form in formset.forms:
68+...    print form.as_ul()
69+<li>Choice: <input type="text" name="choices-0-choice" value="Calexico" /></li>
70+<li>Votes: <input type="text" name="choices-0-votes" value="100" /></li>
71+<li>Order: <input type="text" name="choices-0-ORDER" value="1" /></li>
72+<li>Delete: <input type="checkbox" name="choices-0-DELETE" /></li>
73+<li>Choice: <input type="text" name="choices-1-choice" value="Fergie" /></li>
74+<li>Votes: <input type="text" name="choices-1-votes" value="900" /></li>
75+<li>Order: <input type="text" name="choices-1-ORDER" value="2" /></li>
76+<li>Delete: <input type="checkbox" name="choices-1-DELETE" /></li>
77+<li>Choice: <input type="text" name="choices-2-choice" value="The Decemberists" /></li>
78+<li>Votes: <input type="text" name="choices-2-votes" value="500" /></li>
79+<li>Order: <input type="text" name="choices-2-ORDER" value="3" /></li>
80+<li>Delete: <input type="checkbox" name="choices-2-DELETE" /></li>
81+<li>Choice: <input type="text" name="choices-3-choice" /></li>
82+<li>Votes: <input type="text" name="choices-3-votes" /></li>
83+<li>Order: <input type="text" name="choices-3-ORDER" /></li>
84+<li>Delete: <input type="checkbox" name="choices-3-DELETE" /></li>
85+
86+>>> activate('es')
87+>>> for form in formset.forms:
88+...    print form.as_ul()
89+<li>Choice: <input type="text" name="choices-0-choice" value="Calexico" /></li>
90+<li>Votes: <input type="text" name="choices-0-votes" value="100" /></li>
91+<li>Orden: <input type="text" name="choices-0-ORDER" value="1" /></li>
92+<li>Eliminar: <input type="checkbox" name="choices-0-DELETE" /></li>
93+<li>Choice: <input type="text" name="choices-1-choice" value="Fergie" /></li>
94+<li>Votes: <input type="text" name="choices-1-votes" value="900" /></li>
95+<li>Orden: <input type="text" name="choices-1-ORDER" value="2" /></li>
96+<li>Eliminar: <input type="checkbox" name="choices-1-DELETE" /></li>
97+<li>Choice: <input type="text" name="choices-2-choice" value="The Decemberists" /></li>
98+<li>Votes: <input type="text" name="choices-2-votes" value="500" /></li>
99+<li>Orden: <input type="text" name="choices-2-ORDER" value="3" /></li>
100+<li>Eliminar: <input type="checkbox" name="choices-2-DELETE" /></li>
101+<li>Choice: <input type="text" name="choices-3-choice" /></li>
102+<li>Votes: <input type="text" name="choices-3-votes" /></li>
103+<li>Orden: <input type="text" name="choices-3-ORDER" /></li>
104+<li>Eliminar: <input type="checkbox" name="choices-3-DELETE" /></li>
105+>>> deactivate()
106+
107 # FormSet clean hook ##########################################################
108 
109 FormSets have a hook for doing extra validation that shouldn't be tied to any