11from __future__ import absolute_import
22from __future__ import unicode_literals
33
4+ import django
45from django .utils import six
5-
6- from rest_framework .settings import api_settings
7- import rest_framework .filters
8- import django_filters
96from django_filters .filters import *
107
118from . import fields
129
13- def subsitute_iso8601 (date_type ):
14- from rest_framework import ISO_8601
15-
16- if date_type == 'datetime' :
17- strptime_iso8601 = '%Y-%m-%dT%H:%M:%S.%f'
18- formats = api_settings .DATETIME_INPUT_FORMATS
19- elif date_type == 'date' :
20- strptime_iso8601 = '%Y-%m-%d'
21- formats = api_settings .DATE_INPUT_FORMATS
22- elif date_type == 'time' :
23- strptime_iso8601 = '%H:%M:%S.%f'
24- formats = api_settings .TIME_INPUT_FORMATS
25-
26- new_formats = []
27- for f in formats :
28- if f == ISO_8601 :
29- new_formats .append (strptime_iso8601 )
30- else :
31- new_formats .append (f )
32- return new_formats
33-
34-
35- # In order to support ISO-8601 -- which is the default output for
36- # DRF -- we need to set up custom date/time input formats.
37- TIME_INPUT_FORMATS = subsitute_iso8601 ('time' )
38- DATE_INPUT_FORMATS = subsitute_iso8601 ('date' )
39- DATETIME_INPUT_FORMATS = subsitute_iso8601 ('datetime' )
40-
4110
4211class RelatedFilter (ModelChoiceFilter ):
4312 def __init__ (self , filterset , * args , ** kwargs ):
@@ -50,7 +19,7 @@ def setup_filterset(self):
5019 # This is a recursive relation, defined via a string, so we need
5120 # to create and import the class here.
5221 items = self .filterset .split ('.' )
53- cls = str (items [- 1 ]) # Ensure not unicode on py2.x
22+ cls = str (items [- 1 ]) # Ensure not unicode on py2.x
5423 mod = __import__ ('.' .join (items [:- 1 ]), fromlist = [cls ])
5524 self .filterset = getattr (mod , cls )
5625
@@ -65,22 +34,9 @@ class AllLookupsFilter(Filter):
6534# Fixed-up versions of some of the default filters
6635###################################################
6736
68- class DateFilter (django_filters .DateFilter ):
69- def __init__ (self , * args , ** kwargs ):
70- super (DateFilter , self ).__init__ (* args , ** kwargs )
71- self .extra .update ({'input_formats' : DATE_INPUT_FORMATS })
72-
73-
74- class DateTimeFilter (django_filters .DateTimeFilter ):
75- def __init__ (self , * args , ** kwargs ):
76- super (DateTimeFilter , self ).__init__ (* args , ** kwargs )
77- self .extra .update ({'input_formats' : DATETIME_INPUT_FORMATS })
78-
79-
80- class TimeFilter (django_filters .DateTimeFilter ):
81- def __init__ (self , * args , ** kwargs ):
82- super (TimeFilter , self ).__init__ (* args , ** kwargs )
83- self .extra .update ({'input_formats' : TIME_INPUT_FORMATS })
37+ class TimeFilter (TimeFilter ):
38+ if django .VERSION < (1 , 6 ):
39+ field_class = fields .Django14TimeField
8440
8541
8642class InSetNumberFilter (NumberFilter ):
0 commit comments