Changeset 4904
- Timestamp:
- 04/02/07 05:53:05 (2 years ago)
- Files:
-
- django/trunk/django/newforms/util.py (modified) (3 diffs)
- django/trunk/tests/regressiontests/forms/regressions.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/newforms/util.py
r4522 r4904 1 1 from django.conf import settings 2 2 from django.utils.html import escape 3 from django.utils.functional import Promise, lazy 3 4 4 5 # Converts a dictionary to a single string with key="value", XML-style with … … 7 8 8 9 def smart_unicode(s): 10 if isinstance(s, Promise): 11 # The input is something from gettext_lazy or similar. We don't want to 12 # translate it until render time, so defer the conversion. 13 return smart_unicode_lazy(s) 14 else: 15 return smart_unicode_immediate(s) 16 17 def smart_unicode_immediate(s): 9 18 if not isinstance(s, basestring): 10 19 if hasattr(s, '__unicode__'): … … 15 24 s = unicode(s, settings.DEFAULT_CHARSET) 16 25 return s 26 27 smart_unicode_lazy = lazy(smart_unicode_immediate, unicode) 17 28 18 29 class StrAndUnicode(object): django/trunk/tests/regressiontests/forms/regressions.py
r4894 r4904 11 11 >>> TestForm(auto_id=False).as_p() 12 12 u'<p>F1: <input type="text" class="special" name="f1" maxlength="10" /></p>\n<p>F2: <input type="text" class="special" name="f2" /></p>' 13 14 ####################### 15 # Tests for form i18n # 16 ####################### 17 There were some problems with form translations in #3600 18 19 >>> from django.utils.translation import gettext_lazy, activate, deactivate 20 >>> class SomeForm(Form): 21 ... username = CharField(max_length=10, label=gettext_lazy('Username')) 22 >>> f = SomeForm() 23 >>> print f.as_p() 24 <p><label for="id_username">Username:</label> <input id="id_username" type="text" name="username" maxlength="10" /></p> 25 >>> activate('de') 26 >>> print f.as_p() 27 <p><label for="id_username">Benutzername:</label> <input id="id_username" type="text" name="username" maxlength="10" /></p> 28 >>> deactivate() 13 29 """
