Skip to content

Commit

Permalink
Add cache warmup endpoint (#1063)
Browse files Browse the repository at this point in the history
* Refactor permissions in the views.py.

* Add get_viz to the slice.

* Add warm up cache endpoint.

* Resolve comments.
  • Loading branch information
bkyryliuk committed Sep 6, 2016
1 parent 49e4f70 commit e783219
Show file tree
Hide file tree
Showing 4 changed files with 195 additions and 136 deletions.
26 changes: 26 additions & 0 deletions caravel/models.py
Expand Up @@ -43,6 +43,8 @@
from sqlalchemy.sql.expression import TextAsFrom
from sqlalchemy_utils import EncryptedType

from werkzeug.datastructures import ImmutableMultiDict

import caravel
from caravel import app, db, get_session, utils, sm
from caravel.viz import viz_types
Expand Down Expand Up @@ -250,6 +252,30 @@ def slice_link(self):
return '<a href="{url}">{obj.slice_name}</a>'.format(
url=url, obj=self)

def get_viz(self, url_params_multidict=None):
"""Creates :py:class:viz.BaseViz object from the url_params_multidict.
:param werkzeug.datastructures.MultiDict url_params_multidict:
Contains the visualization params, they override the self.params
stored in the database
:return: object of the 'viz_type' type that is taken from the
url_params_multidict or self.params.
:rtype: :py:class:viz.BaseViz
"""
slice_params = json.loads(self.params) # {}
slice_params['slice_id'] = self.id
slice_params['json'] = "false"
slice_params['slice_name'] = self.slice_name
slice_params['viz_type'] = self.viz_type if self.viz_type else "table"
if url_params_multidict:
slice_params.update(url_params_multidict)
immutable_slice_params = ImmutableMultiDict(slice_params)
return viz_types[immutable_slice_params.get('viz_type')](
self.datasource,
form_data=immutable_slice_params,
slice_=self
)


def set_perm(mapper, connection, target): # noqa
if target.table_id:
Expand Down

0 comments on commit e783219

Please sign in to comment.