mirror of
https://github.com/apache/superset.git
synced 2024-09-17 11:09:47 -04:00
feat: add descriptions to report emails (#13827)
* add description to report email * add report description to slack notification * fix issues caught by linter * fix long line * remove extra line * handle missing descriptions * run python black * properly run python black
This commit is contained in:
parent
bf22487e23
commit
778bb8e540
@ -219,7 +219,12 @@ class BaseReportState:
|
|||||||
f"{self._report_schedule.name}: "
|
f"{self._report_schedule.name}: "
|
||||||
f"{self._report_schedule.dashboard.dashboard_title}"
|
f"{self._report_schedule.dashboard.dashboard_title}"
|
||||||
)
|
)
|
||||||
return NotificationContent(name=name, url=url, screenshot=screenshot_data)
|
return NotificationContent(
|
||||||
|
name=name,
|
||||||
|
url=url,
|
||||||
|
screenshot=screenshot_data,
|
||||||
|
description=self._report_schedule.description,
|
||||||
|
)
|
||||||
|
|
||||||
def _send(self, notification_content: NotificationContent) -> None:
|
def _send(self, notification_content: NotificationContent) -> None:
|
||||||
"""
|
"""
|
||||||
|
@ -22,7 +22,7 @@ from superset.reports.notifications.slack import SlackNotification
|
|||||||
|
|
||||||
|
|
||||||
def create_notification(
|
def create_notification(
|
||||||
recipient: ReportRecipients, screenshot_data: NotificationContent
|
recipient: ReportRecipients, notification_content: NotificationContent
|
||||||
) -> BaseNotification:
|
) -> BaseNotification:
|
||||||
"""
|
"""
|
||||||
Notification polymorphic factory
|
Notification polymorphic factory
|
||||||
@ -30,5 +30,5 @@ def create_notification(
|
|||||||
"""
|
"""
|
||||||
for plugin in BaseNotification.plugins:
|
for plugin in BaseNotification.plugins:
|
||||||
if plugin.type == recipient.type:
|
if plugin.type == recipient.type:
|
||||||
return plugin(recipient, screenshot_data)
|
return plugin(recipient, notification_content)
|
||||||
raise Exception("Recipient type not supported")
|
raise Exception("Recipient type not supported")
|
||||||
|
@ -27,6 +27,7 @@ class NotificationContent:
|
|||||||
url: Optional[str] = None # url to chart/dashboard for this screenshot
|
url: Optional[str] = None # url to chart/dashboard for this screenshot
|
||||||
screenshot: Optional[bytes] = None # bytes for the screenshot
|
screenshot: Optional[bytes] = None # bytes for the screenshot
|
||||||
text: Optional[str] = None
|
text: Optional[str] = None
|
||||||
|
description: Optional[str] = ""
|
||||||
|
|
||||||
|
|
||||||
class BaseNotification: # pylint: disable=too-few-public-methods
|
class BaseNotification: # pylint: disable=too-few-public-methods
|
||||||
|
@ -68,9 +68,11 @@ class EmailNotification(BaseNotification): # pylint: disable=too-few-public-met
|
|||||||
msgid = make_msgid(domain)[1:-1]
|
msgid = make_msgid(domain)[1:-1]
|
||||||
body = __(
|
body = __(
|
||||||
"""
|
"""
|
||||||
|
<p>%(description)s</p>
|
||||||
<b><a href="%(url)s">Explore in Superset</a></b><p></p>
|
<b><a href="%(url)s">Explore in Superset</a></b><p></p>
|
||||||
<img src="cid:%(msgid)s">
|
<img src="cid:%(msgid)s">
|
||||||
""",
|
""",
|
||||||
|
description=self._content.description or "",
|
||||||
url=self._content.url,
|
url=self._content.url,
|
||||||
msgid=msgid,
|
msgid=msgid,
|
||||||
)
|
)
|
||||||
|
@ -44,25 +44,31 @@ class SlackNotification(BaseNotification): # pylint: disable=too-few-public-met
|
|||||||
return json.loads(self._recipient.recipient_config_json)["target"]
|
return json.loads(self._recipient.recipient_config_json)["target"]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _error_template(name: str, text: str) -> str:
|
def _error_template(name: str, description: str, text: str) -> str:
|
||||||
return __(
|
return __(
|
||||||
"""
|
"""
|
||||||
*%(name)s*\n
|
*%(name)s*\n
|
||||||
|
%(description)s\n
|
||||||
Error: %(text)s
|
Error: %(text)s
|
||||||
""",
|
""",
|
||||||
name=name,
|
name=name,
|
||||||
|
description=description,
|
||||||
text=text,
|
text=text,
|
||||||
)
|
)
|
||||||
|
|
||||||
def _get_body(self) -> str:
|
def _get_body(self) -> str:
|
||||||
if self._content.text:
|
if self._content.text:
|
||||||
return self._error_template(self._content.name, self._content.text)
|
return self._error_template(
|
||||||
|
self._content.name, self._content.description or "", self._content.text
|
||||||
|
)
|
||||||
return __(
|
return __(
|
||||||
"""
|
"""
|
||||||
*%(name)s*\n
|
*%(name)s*\n
|
||||||
|
%(description)s\n
|
||||||
<%(url)s|Explore in Superset>
|
<%(url)s|Explore in Superset>
|
||||||
""",
|
""",
|
||||||
name=self._content.name,
|
name=self._content.name,
|
||||||
|
description=self._content.description or "",
|
||||||
url=self._content.url,
|
url=self._content.url,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user