mirror of
https://github.com/django/django.git
synced 2025-07-05 02:09:13 +00:00
boulder-oracle-sprint: Non-functional changes to bring the branch closer to the current state of the trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/boulder-oracle-sprint@5021 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
1d90cbd758
commit
99b7f9c185
@ -494,15 +494,12 @@ class DateField(Field):
|
|||||||
|
|
||||||
def get_db_prep_save(self, value):
|
def get_db_prep_save(self, value):
|
||||||
# Casts dates into string format for entry into database.
|
# Casts dates into string format for entry into database.
|
||||||
if settings.DATABASE_ENGINE != 'oracle':
|
if settings.DATABASE_ENGINE == 'oracle':
|
||||||
if isinstance(value, datetime.datetime):
|
|
||||||
value = value.date().strftime('%Y-%m-%d')
|
|
||||||
elif isinstance(value, datetime.date):
|
|
||||||
value = value.strftime('%Y-%m-%d')
|
|
||||||
else:
|
|
||||||
# cx_Oracle needs a conversion to datetime.datetime instead.
|
# cx_Oracle needs a conversion to datetime.datetime instead.
|
||||||
if isinstance(value, datetime.date):
|
if isinstance(value, datetime.date):
|
||||||
value = datetime.datetime.combine(value, datetime.time())
|
value = datetime.datetime.combine(value, datetime.time())
|
||||||
|
elif value is not None:
|
||||||
|
value = value.strftime('%Y-%m-%d')
|
||||||
return Field.get_db_prep_save(self, value)
|
return Field.get_db_prep_save(self, value)
|
||||||
|
|
||||||
def get_manipulator_field_objs(self):
|
def get_manipulator_field_objs(self):
|
||||||
@ -825,11 +822,14 @@ class TimeField(Field):
|
|||||||
Field.__init__(self, verbose_name, name, **kwargs)
|
Field.__init__(self, verbose_name, name, **kwargs)
|
||||||
|
|
||||||
def get_db_prep_lookup(self, lookup_type, value):
|
def get_db_prep_lookup(self, lookup_type, value):
|
||||||
def prep(value):
|
if settings.DATABASE_ENGINE == 'oracle':
|
||||||
if settings.DATABASE_ENGINE == 'oracle' and isinstance(value, datetime.time):
|
|
||||||
# Oracle requires a date in order to parse.
|
# Oracle requires a date in order to parse.
|
||||||
|
def prep(value):
|
||||||
|
if isinstance(value, datetime.time):
|
||||||
value = datetime.datetime.combine(datetime.date(1900, 1, 1), value)
|
value = datetime.datetime.combine(datetime.date(1900, 1, 1), value)
|
||||||
return str(value)
|
return str(value)
|
||||||
|
else:
|
||||||
|
prep = str
|
||||||
if lookup_type == 'range':
|
if lookup_type == 'range':
|
||||||
value = [prep(v) for v in value]
|
value = [prep(v) for v in value]
|
||||||
else:
|
else:
|
||||||
@ -849,15 +849,13 @@ class TimeField(Field):
|
|||||||
if value is not None:
|
if value is not None:
|
||||||
# MySQL will throw a warning if microseconds are given, because it
|
# MySQL will throw a warning if microseconds are given, because it
|
||||||
# doesn't support microseconds.
|
# doesn't support microseconds.
|
||||||
if settings.DATABASE_ENGINE == 'mysql' and hasattr(value, 'microsecond'):
|
if settings.DATABASE_ENGINE in ('mysql', 'oracle') and hasattr(value, 'microsecond'):
|
||||||
value = value.replace(microsecond=0)
|
|
||||||
value = str(value)
|
|
||||||
elif settings.DATABASE_ENGINE == 'oracle':
|
|
||||||
if hasattr(value, 'microsecond'):
|
|
||||||
value = value.replace(microsecond=0)
|
value = value.replace(microsecond=0)
|
||||||
|
if settings.DATABASE_ENGINE == 'oracle':
|
||||||
# cx_Oracle expects a datetime.datetime to persist into TIMESTAMP field.
|
# cx_Oracle expects a datetime.datetime to persist into TIMESTAMP field.
|
||||||
|
if isinstance(value, datetime.time):
|
||||||
value = datetime.datetime(1900, 1, 1, value.hour, value.minute, value.second)
|
value = datetime.datetime(1900, 1, 1, value.hour, value.minute, value.second)
|
||||||
else:
|
elif isinstance(value, basestring):
|
||||||
value = datetime.datetime(*(time.strptime(value, '%H:%M:%S')[:6]))
|
value = datetime.datetime(*(time.strptime(value, '%H:%M:%S')[:6]))
|
||||||
else:
|
else:
|
||||||
value = str(value)
|
value = str(value)
|
||||||
|
@ -5,7 +5,9 @@ from django.db.models import signals
|
|||||||
from django.dispatch import dispatcher
|
from django.dispatch import dispatcher
|
||||||
from django.utils.datastructures import SortedDict
|
from django.utils.datastructures import SortedDict
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
import datetime, operator, re
|
import datetime
|
||||||
|
import operator
|
||||||
|
import re
|
||||||
|
|
||||||
# For Python 2.3
|
# For Python 2.3
|
||||||
if not hasattr(__builtins__, 'set'):
|
if not hasattr(__builtins__, 'set'):
|
||||||
|
@ -46,7 +46,7 @@ class LocalTimezone(tzinfo):
|
|||||||
return time.tzname[self._isdst(dt)]
|
return time.tzname[self._isdst(dt)]
|
||||||
|
|
||||||
def _isdst(self, dt):
|
def _isdst(self, dt):
|
||||||
tt = (dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, 0, 0, -1)
|
tt = (dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.weekday(), 0, -1)
|
||||||
stamp = time.mktime(tt)
|
stamp = time.mktime(tt)
|
||||||
tt = time.localtime(stamp)
|
tt = time.localtime(stamp)
|
||||||
return tt.tm_isdst > 0
|
return tt.tm_isdst > 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user