Ticket #11984: django_bug_7383_v1.patch
File django_bug_7383_v1.patch, 3.2 KB (added by , 15 years ago) |
---|
-
contrib/admin/templatetags/admin_list.py
310 310 } 311 311 else: 312 312 years = cl.query_set.dates(field_name, 'year') 313 return { 313 # this list can contain None objects so we need to remove them 314 result = { 314 315 'show': True, 315 'choices': [{ 316 'choices': [] 317 } 318 for year in years: 319 if year: 320 result['choices'].append({ 316 321 'link': link({year_field: year.year}), 317 322 'title': year.year 318 } for year in years] 319 } 323 }) 324 return result 325 320 326 date_hierarchy = register.inclusion_tag('admin/date_hierarchy.html')(date_hierarchy) 321 327 322 328 def search_form(cl): -
db/backends/mysql/base.py
134 134 sql = field_name 135 135 else: 136 136 format_str = ''.join([f for f in format[:i]] + [f for f in format_def[i:]]) 137 sql = "CAST(DATE_FORMAT(%s, '%s') AS DATETIME)" % (field_name, format_str) 137 # do not use CAST(... as DATETIME) because it will fail if you have dates like 0000-00-00 00:00:00 138 # MySQL message: "Truncated incorrect datetime value: '0000-01-01 00:00:00'" ErrorNr: 1292 139 sql = "DATE_FORMAT(%s, '%s')" % (field_name, format_str) 138 140 return sql 139 141 140 142 def drop_foreignkey_sql(self): -
db/backends/util.py
50 50 ############################################### 51 51 52 52 def typecast_date(s): 53 return s and datetime.date(*map(int, s.split('-'))) or None # returns None if s is null 53 dt = None 54 try: # this will assure that if we receive dates like '0000-00-00 00:00:00' we do not crash and return None instead 55 dt = datetime.date(*map(int, s.split('-'))) 56 except: 57 dt = None 58 return dt # returns None if s is null or had another invalid value 54 59 55 60 def typecast_time(s): # does NOT store time zone information 56 61 if not s: return None … … 84 89 seconds, microseconds = seconds.split('.') 85 90 else: 86 91 microseconds = '0' 87 return datetime.datetime(int(dates[0]), int(dates[1]), int(dates[2]), 88 int(times[0]), int(times[1]), int(seconds), int(float('.'+microseconds) * 1000000)) 92 result = None 93 try: # this will assure that if we receive dates like '0000-00-00 00:00:00' we do not crash and return None instead 94 result = datetime.datetime(int(dates[0]), int(dates[1]), int(dates[2]), 95 int(times[0]), int(times[1]), int(seconds), int(float('.'+microseconds) * 1000000)) 96 except: 97 result = None 98 return result 89 99 90 100 def typecast_boolean(s): 91 101 if s is None: return None