From bb8923f622824741d86f47492fd4fb3dc7be5d25 Mon Sep 17 00:00:00 2001 From: "maxime.beauchemin@airbnb.com" Date: Fri, 15 Apr 2016 21:43:13 +0000 Subject: [PATCH] Adding origin to form, making it free form --- caravel/forms.py | 10 +++++----- caravel/models.py | 7 +++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/caravel/forms.py b/caravel/forms.py index 106c3c72175a7..799d4e404de84 100644 --- a/caravel/forms.py +++ b/caravel/forms.py @@ -215,11 +215,12 @@ def __init__(self, viz): 'druid_time_origin': SelectField( 'Origin', choices=( + ('', 'default'), ('now', 'now'), - ('2016-04-10', 'even'), - ('2016-04-11', 'monday'), ), - description="Defines the anchor where time buckets start"), + description=( + "Defines the origin where time buckets start, " + "accepts natural dates as in 'now', 'sunday' or '1970-01-01'")), 'granularity': FreeFormSelectField( 'Time Granularity', default="one day", choices=self.choicify([ @@ -232,7 +233,6 @@ def __init__(self, viz): '6 hour', '1 day', '7 days', - # you could add a special string here ]), description=( "The time granularity for the visualization. Note that you " @@ -627,7 +627,7 @@ def add_to_form(attrs): time_fields = ('granularity', 'druid_time_origin') add_to_form(('granularity', 'druid_time_origin')) field_css_classes['granularity'] = ['form-control', 'select2_freeform'] - field_css_classes['druid_time_origin'] = ['form-control', 'select2'] + field_css_classes['druid_time_origin'] = ['form-control', 'select2_freeform'] add_to_form(('since', 'until')) QueryForm.fieldsets = ({ diff --git a/caravel/models.py b/caravel/models.py index 12080ad7aa5b5..9e80eb86bf0d7 100644 --- a/caravel/models.py +++ b/caravel/models.py @@ -1009,10 +1009,9 @@ def query( if not isinstance(granularity, string_types): granularity = {"type": "duration", "duration": granularity} origin = extras.get('druid_time_origin') - if origin == 'now': - granularity['origin'] = datetime.now().isoformat() - elif origin: - granularity['origin'] = origin + if origin: + dttm = utils.parse_human_datetime(origin) + granularity['origin'] = dttm.isoformat() qry = dict( datasource=self.datasource_name,