Ticket #1443: 1443_updated.diff
File 1443_updated.diff, 4.2 KB (added by , 17 years ago) |
---|
-
django/db/models/fields/__init__.py
562 562 # Casts dates into string format for entry into database. 563 563 if value is not None: 564 564 try: 565 value = value.strftime('%Y-%m-%d')565 value = "%04.d-%02.d-%02.d" % (value.year,value.month,value.day) # "%Y-%m-%d 566 566 except AttributeError: 567 567 # If value is already a string it won't have a strftime method, 568 568 # so we'll just let it pass through. … … 574 574 575 575 def flatten_data(self, follow, obj=None): 576 576 val = self._get_val_from_obj(obj) 577 return {self.attname: (val is not None and val.strftime("%Y-%m-%d") or '')}577 return {self.attname: (val is not None and ("%04.d-%02.d-%02.d" % (val.year,val.month,val.day)) or '')} 578 578 579 579 def formfield(self, **kwargs): 580 580 defaults = {'form_class': forms.DateField} -
django/core/serializers/json.py
46 46 JSONEncoder subclass that knows how to encode date/time and decimal types. 47 47 """ 48 48 49 DATE_FORMAT = "% Y-%m-%d"50 TIME_FORMAT = "% H:%M:%S"49 DATE_FORMAT = "%04.d-%02.d-%02.d" # %Y-%m-%d 50 TIME_FORMAT = "%02.d:%02.d:%02.d" # %H:%M:%S 51 51 52 52 def default(self, o): 53 53 if isinstance(o, datetime.datetime): 54 return o.strftime("%s %s" % (self.DATE_FORMAT, self.TIME_FORMAT)) 54 fmt = "%s %s" % (self.DATE_FORMAT, self.TIME_FORMAT) 55 return fmt % (o.year, o.month, o.day, o.hour, o.minute, o.second) 55 56 elif isinstance(o, datetime.date): 56 return o.strftime(self.DATE_FORMAT)57 return self.DATE_FORMAT % (o.year, o.month, o.day) 57 58 elif isinstance(o, datetime.time): 58 return o.strftime(self.TIME_FORMAT)59 return self.TIME_FORMAT % (o.hour, o.minute, o.second) 59 60 elif isinstance(o, decimal.Decimal): 60 61 return str(o) 61 62 else: -
django/core/serializers/base.py
59 59 Convert a field's value to a string. 60 60 """ 61 61 if isinstance(field, models.DateTimeField): 62 value = getattr(obj, field.name).strftime("%Y-%m-%d %H:%M:%S") 62 dt = getattr(obj, field.name) 63 value = "%04.d-%02.d-%02.d %02.d:%02.d:%02.d" % (dt.year,dt.month,dt.day,dt.hour, dt.minute, dt.second) 63 64 else: 64 65 value = field.flatten_data(follow=None, obj=obj).get(field.name, "") 65 66 return smart_unicode(value) -
django/core/validators.py
141 141 # Could use time.strptime here and catch errors, but datetime.date below 142 142 # produces much friendlier error messages. 143 143 year, month, day = map(int, date_string.split('-')) 144 # This check is needed because strftime is used when saving the date 145 # value to the database, and strftime requires that the year be >=1900. 146 if year < 1900: 147 raise ValidationError, _('Year must be 1900 or later.') 144 148 145 try: 149 146 date(year, month, day) 150 147 except ValueError, e: -
tests/regressiontests/serializers_regress/tests.py
255 255 256 256 (data_obj, 800, AutoNowDateTimeData, datetime.datetime(2006,6,16,10,42,37)), 257 257 (data_obj, 810, ModifyingSaveData, 42), 258 259 (data_obj, 900, DateTimeData, datetime.datetime(1,1,1,0,0,0)), 260 (data_obj, 901, DateData, datetime.date(2,2,2)), 258 261 ] 259 262 260 263 # Because Oracle treats the empty string as NULL, Oracle is expected to fail