14
14
from django .core .exceptions import ValidationError
15
15
from django .db .models import SubfieldBase
16
16
from django .db .models .fields import DateTimeField , CharField
17
- from django .utils .six import callable , with_metaclass
17
+ from django .utils .six import with_metaclass
18
18
from django .utils .timezone import get_default_timezone
19
19
from django .utils .translation import ugettext_lazy as _
20
20
@@ -76,11 +76,11 @@ def formfield(self, **kwargs):
76
76
# --------------------------------------------------------------------------
77
77
def check (self , ** kwargs ): # pragma: no cover
78
78
errors = super (TimeZoneField , self ).check (** kwargs )
79
- errors .extend (self ._check_timezone_max_length_attribute (** kwargs ))
80
- errors .extend (self ._check_choices_attribute (** kwargs ))
79
+ errors .extend (self ._check_timezone_max_length_attribute ())
80
+ errors .extend (self ._check_choices_attribute ())
81
81
return errors
82
82
83
- def _check_timezone_max_length_attribute (self , ** kwargs ): # pragma: no cover
83
+ def _check_timezone_max_length_attribute (self ): # pragma: no cover
84
84
"""Custom check() method that verifies that the `max_length` attribute
85
85
covers all possible pytz timezone lengths.
86
86
@@ -113,7 +113,7 @@ def _check_timezone_max_length_attribute(self, **kwargs): # pragma: no cover
113
113
# When no error, return an empty list
114
114
return []
115
115
116
- def _check_choices_attribute (self , ** kwargs ): # pragma: no cover
116
+ def _check_choices_attribute (self ): # pragma: no cover
117
117
if self .choices :
118
118
warning_params = {
119
119
'msg' : (
@@ -129,7 +129,7 @@ def _check_choices_attribute(self, **kwargs): # pragma: no cover
129
129
if isinstance (option_value , (list , tuple )):
130
130
# This is an optgroup, so look inside the group for
131
131
# options.
132
- for optgroup_key , optgroup_value in option_value :
132
+ for optgroup_key in map ( lambda x : x [ 0 ], option_value ) :
133
133
if optgroup_key not in pytz .all_timezones :
134
134
# Make sure we don't raise this error on empty
135
135
# values
@@ -191,7 +191,7 @@ def pre_save(self, model_instance, add):
191
191
tz = get_default_timezone ()
192
192
193
193
if self .populate_from :
194
- if callable (self .populate_from ):
194
+ if hasattr (self .populate_from , '__call__' ):
195
195
# LinkedTZDateTimeField(
196
196
# populate_from=lambda instance: instance.field.timezone
197
197
# )
@@ -210,7 +210,10 @@ def pre_save(self, model_instance, add):
210
210
datetime_as_timezone = value .astimezone (tz )
211
211
value = tz .normalize (
212
212
tz .localize (
213
- datetime .combine (date = datetime_as_timezone .date (), time = datetime_as_timezone .time ())
213
+ datetime .combine (
214
+ date = datetime_as_timezone .date (),
215
+ time = datetime_as_timezone .time ()
216
+ )
214
217
)
215
218
)
216
219
0 commit comments