parse_dates decorator works with optional date params
This commit is contained in:
parent
f00305771b
commit
6bbdac35ec
@ -37,6 +37,7 @@ def date_parser(*pos):
|
|||||||
|
|
||||||
Each of the dates is automatically parsed into a datetime.datetime object from string.
|
Each of the dates is automatically parsed into a datetime.datetime object from string.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def parse_dates(func):
|
def parse_dates(func):
|
||||||
def wrapper_func(*args, **kwargs):
|
def wrapper_func(*args, **kwargs):
|
||||||
date_format = kwargs.get("date_format", None)
|
date_format = kwargs.get("date_format", None)
|
||||||
@ -49,9 +50,15 @@ def date_parser(*pos):
|
|||||||
date = kwargs.get(kwarg, None)
|
date = kwargs.get(kwarg, None)
|
||||||
in_args = False
|
in_args = False
|
||||||
if date is None:
|
if date is None:
|
||||||
date = args[j]
|
try:
|
||||||
|
date = args[j]
|
||||||
|
except IndexError:
|
||||||
|
pass
|
||||||
in_args = True
|
in_args = True
|
||||||
|
|
||||||
|
if date is None:
|
||||||
|
continue
|
||||||
|
|
||||||
parsed_date = _parse_date(date, date_format)
|
parsed_date = _parse_date(date, date_format)
|
||||||
if not in_args:
|
if not in_args:
|
||||||
kwargs[kwarg] = parsed_date
|
kwargs[kwarg] = parsed_date
|
||||||
|
Loading…
Reference in New Issue
Block a user