You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2018/11/06 00:30:06 UTC

[GitHub] graceguo-supercat closed pull request #6269: Fixing time range since with no "ago"

graceguo-supercat closed pull request #6269: Fixing time range since with no "ago"
URL: https://github.com/apache/incubator-superset/pull/6269
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/superset/utils/core.py b/superset/utils/core.py
index a15f382533..cecd0824a1 100644
--- a/superset/utils/core.py
+++ b/superset/utils/core.py
@@ -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'}
 
diff --git a/superset/views/core.py b/superset/views/core.py
index 2af85148c2..a16bceb4c2 100755
--- a/superset/views/core.py
+++ b/superset/views/core.py
@@ -1036,12 +1036,11 @@ def get_form_data(self, slice_id=None, use_slice_data=False):
             # 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
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org