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 get_viz method to the slice. #1062

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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):
"""Creates BaseViz object from the url_params_multidict.

Parameters
----------
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
viz_type = url_params_multidict.get("viz_type", self.viz_type)
slice_params['viz_type'] = viz_type if viz_type else "table"
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