Closed tomekkorbak closed 8 years ago
Its cool! But now function _get_lookup_parameter
excessive and complicated code :(
make_dt_aware(datetime.datetime.combine(
filter_params[self.lookup_kwarg_lte], datetime.time.max
))
vs
func(params):
if/else
get by key
What is excessive? The alternative to the if-else clause is code duplication for two get-by-key
s.
One other option is to provide datetime.time.(max|min)
as an argument to _get_lookup_parameter
, though it's not perfect encapsulation-wise. Feel free to choose this way if you consider it better.
There was a bug in
queryset
method. When only one of the fieldsfield__lte
andfield__gte
is populated and the other is left blank, the blank one was filtered out of thefiltered_params
dictionary in line 59 and raisedKeyError
in either line 55 or line 68.This commit fixes the bug by using
gte
andlte
lookups rather thanrange
and checkingif self.lookup_kwarg_(gte|lte) in filter_params
. Also,queryset
method was refactored and the logic of acquiring filtering parameters for Django ORM was extracted to private methods with separate responsibilities.