From d33d9f9c552a54b3e81c2700d64edaad2bb748de Mon Sep 17 00:00:00 2001 From: Corey Oordt Date: Wed, 8 Aug 2012 11:20:07 -0400 Subject: [PATCH] Fixed a bug in the compatibility layer --- categories/editor/utils.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/categories/editor/utils.py b/categories/editor/utils.py index 1200569..b8d7e78 100644 --- a/categories/editor/utils.py +++ b/categories/editor/utils.py @@ -7,7 +7,10 @@ from django.forms.forms import pretty_name from django.db import models from django.db.models.related import RelatedObject from django.utils.encoding import force_unicode, smart_unicode, smart_str -from django.utils import formats +from django.utils.translation import get_date_formats +from django.utils.text import capfirst +from django.utils import dateformat +from django.utils.html import escape def lookup_field(name, obj, model_admin=None): @@ -99,10 +102,23 @@ def display_for_field(value, field): elif value is None: return EMPTY_CHANGELIST_VALUE elif isinstance(field, models.DateField) or isinstance(field, models.TimeField): - return formats.localize(value) + if value: + (date_format, datetime_format, time_format) = get_date_formats() + if isinstance(field, models.DateTimeField): + return capfirst(dateformat.format(value, datetime_format)) + elif isinstance(field, models.TimeField): + return capfirst(dateformat.time_format(value, time_format)) + else: + return capfirst(dateformat.format(value, date_format)) + else: + return EMPTY_CHANGELIST_VALUE + elif isinstance(field, models.DecimalField): - return formats.number_format(value, field.decimal_places) + if value is not None: + return ('%%.%sf' % field.decimal_places) % value + else: + return EMPTY_CHANGELIST_VALUE elif isinstance(field, models.FloatField): - return formats.number_format(value) + return escape(value) else: return smart_unicode(value)