#NEWLINE# def get_time_interval( get , ctx , encode = True , days_ago = 30 ) : #NEWLINE# #INDENT# ' Shortcut function that returns a time interval from the ``get``\n        dictionary, and stores it in the ``ctx`` dictionary.\n        The ``days_ago`` is a number of days from now, in case\n        when the ``get`` does not contain any information. ' #NEWLINE# if ( 'date_from' in get ) : #NEWLINE# #INDENT# date_from = date_from_str ( get [ 'date_from' ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# date_from = ( date . today ( ) - timedelta ( days = days_ago ) ) #NEWLINE# #UNINDENT# if ( 'date_to' in get ) : #NEWLINE# #INDENT# date_to = date_from_str ( get [ 'date_to' ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# date_to = ( date . today ( ) + timedelta ( days = 1 ) ) #NEWLINE# #UNINDENT# if encode : #NEWLINE# #INDENT# date_from_enc = date_from . strftime ( '%m/%d/%Y' ) #NEWLINE# date_to_enc = date_to . strftime ( '%m/%d/%Y' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# date_from_enc = date_from #NEWLINE# date_to_enc = date_to #NEWLINE# #UNINDENT# ctx [ 'date_from' ] = date_from_enc #NEWLINE# ctx [ 'date_to' ] = date_to_enc #NEWLINE# return ( date_from , ctx )