Ticket #6783: django-DecimalField-prep_locale.2.patch
File django-DecimalField-prep_locale.2.patch, 1.5 KB (added by , 17 years ago) |
---|
-
django/db/models/fields/__init__.py
6 6 except ImportError: 7 7 from django.utils import _decimal as decimal # for Python 2.3 8 8 9 from locale import getlocale, setlocale, LC_NUMERIC 10 9 11 from django.db import get_creation_module 10 12 from django.db.models import signals 11 13 from django.dispatch import dispatcher … … 684 686 return u"%.*f" % (self.decimal_places, value) 685 687 686 688 def get_db_prep_save(self, value): 689 self._prep_locale() 687 690 if value is not None: 688 691 value = self._format(value) 692 self._prep_restorelocale() 689 693 return super(DecimalField, self).get_db_prep_save(value) 690 694 691 695 def get_db_prep_lookup(self, lookup_type, value): 696 self._prep_locale() 692 697 if lookup_type == 'range': 693 698 value = [self._format(v) for v in value] 694 699 else: 695 700 value = self._format(value) 701 self._prep_restorelocale() 696 702 return super(DecimalField, self).get_db_prep_lookup(lookup_type, value) 697 703 704 def _prep_locale(self): 705 self._prep_current_locale = getlocale()[0] 706 setlocale(LC_NUMERIC, 'en_US') 707 708 def _prep_restorelocale(self): 709 setlocale(LC_NUMERIC, self._prep_current_locale) 710 698 711 def get_manipulator_field_objs(self): 699 712 return [curry(oldforms.DecimalField, max_digits=self.max_digits, decimal_places=self.decimal_places)] 700 713