You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2019/07/15 10:25:37 UTC
[GitHub] [incubator-superset] gbrian commented on issue #6771:
[Design]Jinja2 support in Markup Viz
gbrian commented on issue #6771: [Design]Jinja2 support in Markup Viz
URL: https://github.com/apache/incubator-superset/issues/6771#issuecomment-511349169
Hi @mistercrunch this viz will be quite good for our project. It will give us lot of possibilities to create a rich Welcome dashboards for the user.
It will be great if we can use Jinja2 templates and query a datasource.
Using Jinja2 templates:
![image](https://user-images.githubusercontent.com/767180/61209929-4ff57800-a6fb-11e9-9282-1f61e0e77b96.png)
In my case I'm using existing `BaseTemplateProcessor`
`from superset.jinja_context import get_template_processor`
````
class MarkupViz(BaseViz):
"""Use html or markdown to create a free form widget"""
viz_type = "markup"
verbose_name = _("Markup")
is_timeseries = False
def query_obj(self):
return None
def get_df(self, query_obj=None):
return None
def get_code(self):
code = self.form_data.get("code", "")
processor = get_template_processor(self.datasource.database)
return processor.process_template(code)
def get_data(self, df):
markup_type = self.form_data.get("markup_type")
code = self.get_code()
if markup_type == "markdown":
code = markdown(code, extensions=['tables'])
return dict(html=code, theme_css=get_css_manifest_files("theme"))
````
Let me know if this is something good/NTH in order to create a PR.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org