question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Design]Jinja2 support in Markup Viz

See original GitHub issue

Make sure these boxes are checked before submitting your issue - thank you!

  • I have checked the superset logs for python stacktraces and included it here as text if there are any.
  • I have reproduced the issue with at least the latest released version of superset.
  • I have checked the issue tracker for the same issue and I haven’t found one similar.

Superset version

0.28.1

Expected results

Jinja2 Templating in Markup Viz

Actual results

image

Steps to reproduce

def query_obj(self):
    return None

def get_df(self, query_obj=None):
    return None

def get_data(self, df):
    markup_type = self.form_data.get('markup_type')
    code = self.form_data.get('code', '')
    if markup_type == 'markdown':
        code = markdown(code)
        return dict(html=code, theme_css=get_css_manifest_files('theme'))
    else:
        print(template_processor.context["current_username"]())
        return dict(
            html=jinja2.Environment().from_string(code).render(template_processor=template_processor),
            theme_css=get_css_manifest_files('theme')
        )`

The question here is, how safe is this? template_processor is object of jinja_context.BaseTemplateProcessor

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
gbriancommented, Jul 15, 2019

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

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.

0reactions
zufolo441commented, May 28, 2020

Thanks to your advices I was able to enable templating in markup chart. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

apache/superset - [Design]Jinja2 support in Markup Viz - GitHub
[Design]Jinja2 support in Markup Viz #6771 ... class MarkupViz(BaseViz): """Use html or markdown to create a free form widget""" viz_type = "markup" ...
Read more >
[GitHub] [incubator-superset] gbrian commented ... - The Mail Archive
gbrian commented on issue #6771: [Design]Jinja2 support in Markup Viz URL: https://github.com/apache/incubator-superset/issues/6771#issuecomment-511355378 ...
Read more >
Jinja Documentation (3.0.x) » Template Designer ...
The context dictionary by the application with markupsafe.Markup. The template, with the |safe filter. If a string that you marked safe is ...
Read more >
Understanding Jinja - Salt Project Documentation
Jinja supports a secure, sandboxed template execution environment that Salt takes ... as useful (viz. you likely want to use yaml_encode or yaml_dquote...
Read more >
How to use the jinja2.utils.Markup function in Jinja2 - Snyk
To help you get started, we've selected a few jinja2.utils.Markup examples, based on popular ways it is used in public projects.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found