Skip to content

Instantly share code, notes, and snippets.

@thiagoferreiraw
Last active September 1, 2021 13:23
Show Gist options
  • Save thiagoferreiraw/56ba6f92de0951179867f5289585dfba to your computer and use it in GitHub Desktop.
Save thiagoferreiraw/56ba6f92de0951179867f5289585dfba to your computer and use it in GitHub Desktop.
Medium - Metabase + Django - 3
class EmbeddedReportResource(PaginatorMixin, APIResource):
preparer = EMBEDDED_REPORT_LIST_PREPARER
paginate = True
page_size = 40
@property
def base_query(self):
return (
EmbeddedReport.objects.filter(active=True)
.select_related("engine")
.order_by("name")
)
def prepare(self, data):
result = super().prepare(data)
if self.endpoint == "detail":
result["url"] = data.get_report_url_for_business(self.business)
return result
@permissions(needs=("embedded-report-list",))
def list(self):
return self.base_query
@permissions(needs=("embedded-report-list",))
def detail(self, pk):
return self.get_or_error(self.base_query, EMBEDDED_REPORT_NOT_FOUND, pk=pk)
{
"id": "8e725505",
"name": "Dashboard - Order stats",
"engine": "metabase",
"reference_type": "dashboard",
"reference_type_display": "Dashboard",
"url": "https://metabase.yourdomain.com/embed/dashboard/eyJ0eXAJ9.eyJjZSI6eyJkYXNoYm9hcmQiOjIxfSwicGFyYW1zIjp7Im9yZ2FuaXphdGlvbl9pZCI6MX0sImV4cCI6MTYzMDUwMTg4M30.qWysgBj47H4ZhH_kfM8iInpkkJM6QpmHNivlX0EvvTs#bordered=false&titled=false"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment