Ticket #14290: l10n_performance.diff
File l10n_performance.diff, 2.5 KB (added by , 14 years ago) |
---|
-
django/utils/formats.py
7 7 from django.utils.encoding import smart_str 8 8 from django.utils import dateformat, numberformat, datetime_safe 9 9 10 11 # _cached_formats is a mapping from format_type to a 1-tuple. This allows 12 # us to separate 3 distinct cases: 13 # (None,) the format_type was checked previously, but 14 # no value was found. 15 # (<format value>, ) the previously fetched value for format_type 16 # is format_value 17 # if a format_type key is not in _cached_formats, then format_type 18 # hasn't yet been fetched. 19 _cached_formats = {} 20 10 21 def get_format_modules(reverse=False): 11 22 """ 12 23 Returns an iterator over the format modules found in the project and Django … … 34 45 modules.reverse() 35 46 return modules 36 47 48 37 49 def get_format(format_type): 38 50 """ 39 51 For a specific format type, returns the format for the current … … 42 54 """ 43 55 format_type = smart_str(format_type) 44 56 if settings.USE_L10N: 45 for module in get_format_modules(): 46 try: 47 return getattr(module, format_type) 48 except AttributeError: 57 global _cached_formats 58 cached_value = _cached_formats.get(format_type, None) 59 if cached_value: 60 if cached_value[0]: 61 return cached_value[0] 62 else: 63 # format_type was previously checked, but didn't have a value 49 64 pass 65 else: 66 for module in get_format_modules(): 67 try: 68 format_value = getattr(module, format_type) 69 _cached_formats[format_type] = (format_value,) 70 return format_value 71 except AttributeError: 72 pass 73 _cached_formats[format_type] = (None,) 50 74 return getattr(settings, format_type) 51 75 52 76 def date_format(value, format=None): -
AUTHORS
276 276 knox <christobzr@gmail.com> 277 277 David Krauth 278 278 Kevin Kubasik <kevin@kubasik.net> 279 Teemu Kurppa <http://dirtyaura.org> 279 280 kurtiss@meetro.com 280 281 Denis Kuzmichyov <kuzmichyov@gmail.com> 281 282 Panos Laganakos <panos.laganakos@gmail.com>