mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
Adding backwards compatable check to add ago to since if it doesn't exist (#6269)
This commit is contained in:
committed by
Grace Guo
parent
7fe8e8aff2
commit
c7f8abc6c5
@@ -923,6 +923,8 @@ def get_since_until(form_data):
|
||||
time_range = form_data['time_range']
|
||||
if separator in time_range:
|
||||
since, until = time_range.split(separator, 1)
|
||||
if since and since not in common_time_frames:
|
||||
since = add_ago_to_since(since)
|
||||
since = parse_human_datetime(since)
|
||||
until = parse_human_datetime(until)
|
||||
elif time_range in common_time_frames:
|
||||
@@ -940,16 +942,29 @@ def get_since_until(form_data):
|
||||
else:
|
||||
since = form_data.get('since', '')
|
||||
if since:
|
||||
since_words = since.split(' ')
|
||||
grains = ['days', 'years', 'hours', 'day', 'year', 'weeks']
|
||||
if len(since_words) == 2 and since_words[1] in grains:
|
||||
since += ' ago'
|
||||
since = add_ago_to_since(since)
|
||||
since = parse_human_datetime(since)
|
||||
until = parse_human_datetime(form_data.get('until', 'now'))
|
||||
|
||||
return since, until
|
||||
|
||||
|
||||
def add_ago_to_since(since):
|
||||
"""
|
||||
Backwards compatibility hack. Without this slices with since: 7 days will
|
||||
be treated as 7 days in the future.
|
||||
|
||||
:param str since:
|
||||
:returns: Since with ago added if necessary
|
||||
:rtype: str
|
||||
"""
|
||||
since_words = since.split(' ')
|
||||
grains = ['days', 'years', 'hours', 'day', 'year', 'weeks']
|
||||
if (len(since_words) == 2 and since_words[1] in grains):
|
||||
since += ' ago'
|
||||
return since
|
||||
|
||||
|
||||
def convert_legacy_filters_into_adhoc(fd):
|
||||
mapping = {'having': 'having_filters', 'where': 'filters'}
|
||||
|
||||
|
||||
@@ -1036,12 +1036,11 @@ class Superset(BaseSupersetView):
|
||||
# special treat for since/until and time_range parameter:
|
||||
# we need to breakdown time_range into since/until so request parameters
|
||||
# has precedence over slice parameters for time fields.
|
||||
if 'time_range' in form_data:
|
||||
form_data['since'], separator, form_data['until'] = \
|
||||
form_data['time_range'].partition(' : ')
|
||||
if 'time_range' in slice_form_data:
|
||||
slice_form_data['since'], separator, slice_form_data['until'] = \
|
||||
slice_form_data['time_range'].partition(' : ')
|
||||
if 'since' in form_data or 'until' in form_data:
|
||||
form_data['since'], form_data['until'] = \
|
||||
utils.get_since_until(form_data)
|
||||
slice_form_data['since'], slice_form_data['until'] = \
|
||||
utils.get_since_until(slice_form_data)
|
||||
slice_form_data.update(form_data)
|
||||
form_data = slice_form_data
|
||||
|
||||
|
||||
Reference in New Issue
Block a user