Skip to content

Commit

Permalink
refactor: define SUPERSET_EMBEDDABLE_DASHBOARDS setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2012 committed Oct 13, 2023
1 parent e5c1880 commit dc98040
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 27 deletions.
7 changes: 0 additions & 7 deletions tutoraspects/patches/openedx-common-settings
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,3 @@ EVENT_SINK_CLICKHOUSE_BACKEND_CONFIG = {
"database": "{{ ASPECTS_EVENT_SINK_DATABASE }}",
"timeout_secs": {{ ASPECTS_EVENT_SINK_CLICKHOUSE_TIMEOUT_SECS }}
}
SUPERSET_DASHBOARDS = {
{% for dashboard, body in SUPERSET_DASHBOARDS.items() %}"{{ dashboard }}": {
"uuid": "{{ body.uuid }}",
"slug": "{{ body.slug }}",
"title": "{{ body.title }}",
},{% endfor %}
}
15 changes: 3 additions & 12 deletions tutoraspects/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,19 +256,10 @@
},
),
(
"SUPERSET_DASHBOARDS",
"SUPERSET_EMBEDDABLE_DASHBOARDS",
{
"instructor_dashboard": {
"uuid": "1d6bf904-f53f-47fd-b1c9-6cd7e284d286",
"title": "Instructor Dashboard",
"slug": "instructor-dashboard",
},
"operator_dashboard": {
"uuid": "02c0121c-40e9-4d8a-b86a-6b996a1cc6fe",
"title": "Operator Dashboard",
"slug": "operator-dashboard",
},
},
"instructor-dashboard": "1d6bf904-f53f-47fd-b1c9-6cd7e284d286",
}
),
("SUPERSET_ADMIN_EMAIL", "[email protected]"),
("SUPERSET_OWNERS", []),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def create_assets():

import_assets()
update_dashboard_roles(roles)
update_embeddable_uuids()


def get_uuid5(base_uuid, name):
Expand Down Expand Up @@ -238,16 +239,24 @@ def update_dashboard_roles(roles):
dashboard.owners = owners
db.session.commit()


def update_embeddable_uuids():
"""Update the uuids of the embeddable dashboards"""
for dashboard_slug, embeddable_uuid in {{SUPERSET_EMBEDDABLE_DASHBOARDS}}.items():
dashboard = db.session.query(Dashboard).filter_by(slug=dashboard_slug).first()
if dashboard is None:
print(f"WARNING: Dashboard {dashboard_slug} not found")
continue

embedded_dashboard = db.session.query(EmbeddedDashboard).filter_by(dashboard_id=dashboard.id).first()
if embedded_dashboard is None:
embedded_dashboard = EmbeddedDashboard()
embedded_dashboard.dashboard_id = dashboard.id
embedded_dashboard.uuid = dashboard_uuid
embedded_dashboard.uuid = embeddable_uuid

db.session.add(embedded_dashboard)
db.session.commit()


def get_translation(text, language):
"""Get a translation for a text in a language"""
default_text = f"{text} - {language}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ _file_name: Instructor_Dashboard.yaml
_roles:
- {{ SUPERSET_ROLES_MAPPING.instructor }}
css: ''
dashboard_title: {{ SUPERSET_DASHBOARDS.instructor_dashboard.title }}
dashboard_title: Instructor Dashboard
description: null
metadata:
chart_configuration:
Expand Down Expand Up @@ -908,6 +908,6 @@ position:
parents:
- ROOT_ID
type: TABS
slug: {{ SUPERSET_DASHBOARDS.instructor_dashboard.slug }}
uuid: {{ SUPERSET_DASHBOARDS.instructor_dashboard.uuid }}
slug: instructor-dashboard
uuid: 1d6bf904-f53f-47fd-b1c9-6cd7e284d286
version: 1.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ _file_name: Operator_Dashboard.yaml
_roles:
- {{ SUPERSET_ROLES_MAPPING.operator }}
css: ''
dashboard_title: {{ SUPERSET_DASHBOARDS.operator_dashboard.title }}
dashboard_title: Operator Dashboard
description: null
metadata:
chart_configuration:
Expand Down Expand Up @@ -728,6 +728,6 @@ position:
- ROOT_ID
- GRID_ID
type: TABS
slug: {{ SUPERSET_DASHBOARDS.operator_dashboard.slug }}
uuid: {{ SUPERSET_DASHBOARDS.operator_dashboard.uuid }}
slug: operator-dashboard
uuid: 02c0121c-40e9-4d8a-b86a-6b996a1cc6fe
version: 1.0.0

0 comments on commit dc98040

Please sign in to comment.