Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cache warmup endpoint #1063

Merged
merged 5 commits into from
Sep 6, 2016
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions caravel/models.py
Original file line number Diff line number Diff line change
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,34 @@ 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 BaseViz object from the url_params_multidict.

Parameters
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to auto generate docs for the code we should stick with Sphinx's (the documentation framework we use) way of specifying docstrings:
http://www.sphinx-doc.org/en/stable/domains.html#info-field-lists

----------
url_params_multidict: MultiDict, contains the visualization params,
they override the self.params stored in the
database
Returns
-------
BaseViz object of the 'viz_type' type that is taken from the
url_params_multidict or self.params.

"""
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
Loading