def _message_template(self, table: str = "") -> str: url = (modify_url_query(self._content.url, standalone="0") if self._content.url is not None else "") return __( """*%(name)s* %(description)s <%(url)s|Explore in Superset> %(table)s """, name=self._content.name, description=self._content.description or "", url=url, table=table, )
def test_convert_dashboard_link() -> None: test_url = modify_url_query(EXPLORE_DASHBOARD_LINK, standalone="0") assert test_url == "http://localhost:9000/superset/dashboard/3/?standalone=0"
def test_convert_chart_link() -> None: test_url = modify_url_query(EXPLORE_CHART_LINK, standalone="0") assert ( test_url == "http://localhost:9000/explore/?form_data=%7B%22slice_id%22%3A%2076%7D&standalone=0&force=false" )
def _get_content(self) -> EmailContent: if self._content.text: return EmailContent(body=self._error_template(self._content.text)) # Get the domain from the 'From' address .. # and make a message id without the < > in the end csv_data = None domain = self._get_smtp_domain() images = {} if self._content.screenshots: images = { make_msgid(domain)[1:-1]: screenshot for screenshot in self._content.screenshots } # Strip any malicious HTML from the description description = bleach.clean(self._content.description or "") # Strip malicious HTML from embedded data, allowing only table elements if self._content.embedded_data is not None: df = self._content.embedded_data html_table = bleach.clean( df.to_html(na_rep="", index=True), tags=TABLE_TAGS, attributes=TABLE_ATTRIBUTES, ) else: html_table = "" call_to_action = __("Explore in Superset") url = (modify_url_query(self._content.url, standalone="0") if self._content.url is not None else "") img_tags = [] for msgid in images.keys(): img_tags.append(f"""<div class="image"> <img width="1000px" src="cid:{msgid}"> </div> """) img_tag = "".join(img_tags) body = textwrap.dedent(f""" <html> <head> <style type="text/css"> table, th, td {{ border-collapse: collapse; border-color: rgb(200, 212, 227); color: rgb(42, 63, 95); padding: 4px 8px; }} .image{{ margin-bottom: 18px; }} </style> </head> <body> <p>{description}</p> <b><a href="{url}">{call_to_action}</a></b><p></p> {html_table} {img_tag} </body> </html> """) if self._content.csv: csv_data = { __("%(name)s.csv", name=self._content.name): self._content.csv } return EmailContent(body=body, images=images, data=csv_data)