mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Fixed #7980 - Improved i18n framework to support locale aware formatting (dates and numbers) and form processing.
Thanks to Marc Garcia for working on this during his Google Summer of Code 2009! Additionally fixes #1061, #2203, #3940, #5526, #6449, #6231, #6693, #6783, #9366 and #10891. git-svn-id: http://code.djangoproject.com/svn/django/trunk@11964 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
		| @@ -60,6 +60,7 @@ from django.utils.text import smart_split, unescape_string_literal | ||||
| from django.utils.encoding import smart_unicode, force_unicode, smart_str | ||||
| from django.utils.translation import ugettext as _ | ||||
| from django.utils.safestring import SafeData, EscapeData, mark_safe, mark_for_escaping | ||||
| from django.utils.formats import localize | ||||
| from django.utils.html import escape | ||||
|  | ||||
| __all__ = ('Template', 'Context', 'RequestContext', 'compile_string') | ||||
| @@ -815,6 +816,7 @@ def _render_value_in_context(value, context): | ||||
|     means escaping, if required, and conversion to a unicode object. If value | ||||
|     is a string, it is expected to have already been translated. | ||||
|     """ | ||||
|     value = localize(value) | ||||
|     value = force_unicode(value) | ||||
|     if (context.autoescape and not isinstance(value, SafeData)) or isinstance(value, EscapeData): | ||||
|         return escape(value) | ||||
|   | ||||
| @@ -2,6 +2,7 @@ from django.template import Lexer, Parser, tag_re, NodeList, VariableNode, Templ | ||||
| from django.utils.encoding import force_unicode | ||||
| from django.utils.html import escape | ||||
| from django.utils.safestring import SafeData, EscapeData | ||||
| from django.utils.formats import localize | ||||
|  | ||||
| class DebugLexer(Lexer): | ||||
|     def __init__(self, template_string, origin): | ||||
| @@ -84,7 +85,9 @@ class DebugNodeList(NodeList): | ||||
| class DebugVariableNode(VariableNode): | ||||
|     def render(self, context): | ||||
|         try: | ||||
|             output = force_unicode(self.filter_expression.resolve(context)) | ||||
|             output = self.filter_expression.resolve(context) | ||||
|             output = localize(output) | ||||
|             output = force_unicode(output) | ||||
|         except TemplateSyntaxError, e: | ||||
|             if not hasattr(e, 'source'): | ||||
|                 e.source = self.source | ||||
|   | ||||
| @@ -18,6 +18,7 @@ from django.conf import settings | ||||
| from django.utils.translation import ugettext, ungettext | ||||
| from django.utils.encoding import force_unicode, iri_to_uri | ||||
| from django.utils.safestring import mark_safe, SafeData | ||||
| from django.utils.formats import date_format, number_format | ||||
|  | ||||
| register = Library() | ||||
|  | ||||
| @@ -166,14 +167,14 @@ def floatformat(text, arg=-1): | ||||
|         return input_val | ||||
|  | ||||
|     if not m and p < 0: | ||||
|         return mark_safe(u'%d' % (int(d))) | ||||
|         return mark_safe(number_format(u'%d' % (int(d)), 0)) | ||||
|  | ||||
|     if p == 0: | ||||
|         exp = Decimal(1) | ||||
|     else: | ||||
|         exp = Decimal('1.0') / (Decimal(10) ** abs(p)) | ||||
|     try: | ||||
|         return mark_safe(u'%s' % str(d.quantize(exp, ROUND_HALF_UP))) | ||||
|         return mark_safe(number_format(u'%s' % str(d.quantize(exp, ROUND_HALF_UP)), abs(p))) | ||||
|     except InvalidOperation: | ||||
|         return input_val | ||||
| floatformat.is_safe = True | ||||
| @@ -685,9 +686,12 @@ def date(value, arg=None): | ||||
|     if arg is None: | ||||
|         arg = settings.DATE_FORMAT | ||||
|     try: | ||||
|         return format(value, arg) | ||||
|         return date_format(value, arg) | ||||
|     except AttributeError: | ||||
|         return '' | ||||
|         try: | ||||
|             return format(value, arg) | ||||
|         except AttributeError: | ||||
|             return '' | ||||
| date.is_safe = False | ||||
|  | ||||
| def time(value, arg=None): | ||||
| @@ -698,9 +702,12 @@ def time(value, arg=None): | ||||
|     if arg is None: | ||||
|         arg = settings.TIME_FORMAT | ||||
|     try: | ||||
|         return time_format(value, arg) | ||||
|         return date_format(value, arg) | ||||
|     except AttributeError: | ||||
|         return '' | ||||
|         try: | ||||
|             return time_format(value, arg) | ||||
|         except AttributeError: | ||||
|             return '' | ||||
| time.is_safe = False | ||||
|  | ||||
| def timesince(value, arg=None): | ||||
|   | ||||
		Reference in New Issue
	
	Block a user