Skip to content

Commit

Permalink
Json dumps iso date for Table view (#328)
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Apr 12, 2016
1 parent 54fb76e commit 1dd4165
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions caravel/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,20 +245,36 @@ def get_json(self):
is_cached = False
cache_timeout = self.cache_timeout
payload = {
'cache_timeout': cache_timeout,
'csv_endpoint': self.csv_endpoint,
'data': self.get_data(),
'query': self.query,
'form_data': self.form_data,
'json_endpoint': self.json_endpoint,
'csv_endpoint': self.csv_endpoint,
'query': self.query,
'standalone_endpoint': self.standalone_endpoint,
'cache_timeout': cache_timeout,
}
payload['cached_dttm'] = datetime.now().isoformat().split('.')[0]
logging.info("Caching for the next {} seconds".format(
cache_timeout))
cache.set(cache_key, payload, timeout=self.cache_timeout)
payload['is_cached'] = is_cached
return dumps(payload)
return self.json_dumps(payload)

def json_dumps(self, obj):
"""Used by get_json, can be overridden to use specific switches"""
return dumps(obj)

@property
def data(self):
content = {
'csv_endpoint': self.csv_endpoint,
'form_data': self.form_data,
'json_endpoint': self.json_endpoint,
'standalone_endpoint': self.standalone_endpoint,
'token': self.token,
'viz_name': self.viz_type,
}
return content

def get_csv(self):
df = self.get_df()
Expand All @@ -285,18 +301,6 @@ def csv_endpoint(self):
def standalone_endpoint(self):
return self.get_url(standalone="true")

@property
def data(self):
content = {
'viz_name': self.viz_type,
'json_endpoint': self.json_endpoint,
'csv_endpoint': self.csv_endpoint,
'standalone_endpoint': self.standalone_endpoint,
'token': self.token,
'form_data': self.form_data,
}
return content

@property
def json_data(self):
return dumps(self.data)
Expand Down Expand Up @@ -356,6 +360,9 @@ def get_data(self):
columns=list(df.columns),
)

def json_dumps(self, obj):
return json.dumps(obj, default=utils.json_iso_dttm_ser)


class PivotTableViz(BaseViz):

Expand Down

0 comments on commit 1dd4165

Please sign in to comment.