Skip to content

Commit

Permalink
Adding origin to form, making it free form
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] authored and mistercrunch committed Apr 15, 2016
1 parent 6e9bde7 commit bb8923f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
10 changes: 5 additions & 5 deletions caravel/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand All @@ -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 "
Expand Down Expand Up @@ -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 = ({
Expand Down
7 changes: 3 additions & 4 deletions caravel/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit bb8923f

Please sign in to comment.