More removal of poorly legible constructs to workaround Python 2.4 shortcomings.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16363 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
0e03a504bf
commit
c43d15b3b3
|
@ -6,9 +6,8 @@ Requires cx_Oracle: http://cx-oracle.sourceforge.net/
|
||||||
|
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import sys
|
|
||||||
import time
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
def _setup_environment(environ):
|
def _setup_environment(environ):
|
||||||
|
@ -341,7 +340,7 @@ WHEN (new.%(col_name)s IS NULL)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if isinstance(value, basestring):
|
if isinstance(value, basestring):
|
||||||
return datetime.datetime(*(time.strptime(value, '%H:%M:%S')[:6]))
|
return datetime.datetime.strptime(value, '%H:%M:%S')
|
||||||
|
|
||||||
# Oracle doesn't support tz-aware datetimes
|
# Oracle doesn't support tz-aware datetimes
|
||||||
if value.tzinfo is not None:
|
if value.tzinfo is not None:
|
||||||
|
|
|
@ -6,9 +6,7 @@ import copy
|
||||||
import datetime
|
import datetime
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import time
|
|
||||||
import urlparse
|
import urlparse
|
||||||
import warnings
|
|
||||||
from decimal import Decimal, DecimalException
|
from decimal import Decimal, DecimalException
|
||||||
try:
|
try:
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
|
@ -20,7 +18,6 @@ from django.core import validators
|
||||||
from django.utils import formats
|
from django.utils import formats
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.utils.encoding import smart_unicode, smart_str, force_unicode
|
from django.utils.encoding import smart_unicode, smart_str, force_unicode
|
||||||
from django.utils.functional import lazy
|
|
||||||
|
|
||||||
# Provide this import for backwards compatibility.
|
# Provide this import for backwards compatibility.
|
||||||
from django.core.validators import EMPTY_VALUES
|
from django.core.validators import EMPTY_VALUES
|
||||||
|
@ -344,7 +341,8 @@ class BaseTemporalField(Field):
|
||||||
try:
|
try:
|
||||||
datetime_str, usecs_str = value.rsplit('.', 1)
|
datetime_str, usecs_str = value.rsplit('.', 1)
|
||||||
usecs = int(usecs_str)
|
usecs = int(usecs_str)
|
||||||
return datetime.datetime(*time.strptime(datetime_str, format[:-3])[:6]+(usecs,))
|
dt = datetime.datetime.strptime(datetime_str, format[:-3])
|
||||||
|
return dt.replace(microsecond=usecs)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
continue
|
continue
|
||||||
raise ValidationError(self.error_messages['invalid'])
|
raise ValidationError(self.error_messages['invalid'])
|
||||||
|
@ -373,7 +371,7 @@ class DateField(BaseTemporalField):
|
||||||
return super(DateField, self).to_python(value)
|
return super(DateField, self).to_python(value)
|
||||||
|
|
||||||
def strptime(self, value, format):
|
def strptime(self, value, format):
|
||||||
return datetime.date(*time.strptime(value, format)[:3])
|
return datetime.datetime.strptime(value, format).date()
|
||||||
|
|
||||||
class TimeField(BaseTemporalField):
|
class TimeField(BaseTemporalField):
|
||||||
widget = TimeInput
|
widget = TimeInput
|
||||||
|
@ -394,7 +392,7 @@ class TimeField(BaseTemporalField):
|
||||||
return super(TimeField, self).to_python(value)
|
return super(TimeField, self).to_python(value)
|
||||||
|
|
||||||
def strptime(self, value, format):
|
def strptime(self, value, format):
|
||||||
return datetime.time(*time.strptime(value, format)[3:6])
|
return datetime.datetime.strptime(value, format).time()
|
||||||
|
|
||||||
class DateTimeField(BaseTemporalField):
|
class DateTimeField(BaseTemporalField):
|
||||||
widget = DateTimeInput
|
widget = DateTimeInput
|
||||||
|
|
|
@ -4,7 +4,6 @@ HTML Widget classes
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
import datetime
|
import datetime
|
||||||
import time
|
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
from urlparse import urljoin
|
from urlparse import urljoin
|
||||||
from util import flatatt
|
from util import flatatt
|
||||||
|
@ -397,7 +396,7 @@ class DateInput(Input):
|
||||||
# necessarily the format used for this widget. Attempt to convert it.
|
# necessarily the format used for this widget. Attempt to convert it.
|
||||||
try:
|
try:
|
||||||
input_format = formats.get_format('DATE_INPUT_FORMATS')[0]
|
input_format = formats.get_format('DATE_INPUT_FORMATS')[0]
|
||||||
initial = datetime.date(*time.strptime(initial, input_format)[:3])
|
initial = datetime.datetime.strptime(initial, input_format).date()
|
||||||
except (TypeError, ValueError):
|
except (TypeError, ValueError):
|
||||||
pass
|
pass
|
||||||
return super(DateInput, self)._has_changed(self._format_value(initial), data)
|
return super(DateInput, self)._has_changed(self._format_value(initial), data)
|
||||||
|
@ -429,7 +428,7 @@ class DateTimeInput(Input):
|
||||||
# necessarily the format used for this widget. Attempt to convert it.
|
# necessarily the format used for this widget. Attempt to convert it.
|
||||||
try:
|
try:
|
||||||
input_format = formats.get_format('DATETIME_INPUT_FORMATS')[0]
|
input_format = formats.get_format('DATETIME_INPUT_FORMATS')[0]
|
||||||
initial = datetime.datetime(*time.strptime(initial, input_format)[:6])
|
initial = datetime.datetime.strptime(initial, input_format)
|
||||||
except (TypeError, ValueError):
|
except (TypeError, ValueError):
|
||||||
pass
|
pass
|
||||||
return super(DateTimeInput, self)._has_changed(self._format_value(initial), data)
|
return super(DateTimeInput, self)._has_changed(self._format_value(initial), data)
|
||||||
|
@ -460,7 +459,7 @@ class TimeInput(Input):
|
||||||
# necessarily the format used for this widget. Attempt to convert it.
|
# necessarily the format used for this widget. Attempt to convert it.
|
||||||
try:
|
try:
|
||||||
input_format = formats.get_format('TIME_INPUT_FORMATS')[0]
|
input_format = formats.get_format('TIME_INPUT_FORMATS')[0]
|
||||||
initial = datetime.time(*time.strptime(initial, input_format)[3:6])
|
initial = datetime.datetime.strptime(initial, input_format).time()
|
||||||
except (TypeError, ValueError):
|
except (TypeError, ValueError):
|
||||||
pass
|
pass
|
||||||
return super(TimeInput, self)._has_changed(self._format_value(initial), data)
|
return super(TimeInput, self)._has_changed(self._format_value(initial), data)
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import time
|
|
||||||
import datetime
|
import datetime
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
|
@ -495,7 +494,7 @@ def _date_from_string(year, year_format, month, month_format, day='', day_format
|
||||||
format = delim.join((year_format, month_format, day_format))
|
format = delim.join((year_format, month_format, day_format))
|
||||||
datestr = delim.join((year, month, day))
|
datestr = delim.join((year, month, day))
|
||||||
try:
|
try:
|
||||||
return datetime.date(*time.strptime(datestr, format)[:3])
|
return datetime.datetime.strptime(datestr, format).date()
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise Http404(_(u"Invalid date string '%(datestr)s' given format '%(format)s'") % {
|
raise Http404(_(u"Invalid date string '%(datestr)s' given format '%(format)s'") % {
|
||||||
'datestr': datestr,
|
'datestr': datestr,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import datetime
|
import datetime
|
||||||
import time
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.forms import *
|
from django.forms import *
|
||||||
from django.forms.extras import SelectDateWidget
|
from django.forms.extras import SelectDateWidget
|
||||||
|
@ -379,7 +379,7 @@ class FormsExtraTestCase(unittest.TestCase, AssertFormErrorsMixin):
|
||||||
def decompress(self, value):
|
def decompress(self, value):
|
||||||
if value:
|
if value:
|
||||||
data = value.split(',')
|
data = value.split(',')
|
||||||
return [data[0], data[1], datetime.datetime(*time.strptime(data[2], "%Y-%m-%d %H:%M:%S")[0:6])]
|
return [data[0], data[1], datetime.datetime.strptime(data[2], "%Y-%m-%d %H:%M:%S")]
|
||||||
return [None, None, None]
|
return [None, None, None]
|
||||||
|
|
||||||
def format_output(self, rendered_widgets):
|
def format_output(self, rendered_widgets):
|
||||||
|
|
Loading…
Reference in New Issue