Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow to embed translated dashboards #697

Merged
merged 2 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tutoraspects/patches/openedx-common-settings
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ EVENT_SINK_CLICKHOUSE_PII_MODELS = {{ EVENT_SINK_PII_MODELS }}

ASPECTS_INSTRUCTOR_DASHBOARDS = {{ ASPECTS_INSTRUCTOR_DASHBOARDS }}
SUPERSET_EXTRA_FILTERS_FORMAT = {{ ASPECTS_SUPERSET_EXTRA_FILTERS_FORMAT }}
SUPERSET_DASHBOARD_LOCALES = {{ SUPERSET_DASHBOARD_LOCALES }}
{% if ASPECTS_ENABLE_INSTRUCTOR_DASHBOARD_PLUGIN %}
try:
not OPEN_EDX_FILTERS_CONFIG
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
RUN --mount=type=cache,target=/openedx/.cache/pip,sharing=shared \
pip install "platform-plugin-aspects==v0.5.0"
pip install "platform-plugin-aspects==v0.6.0"
RUN --mount=type=cache,target=/openedx/.cache/pip,sharing=shared \
pip install "edx-event-routing-backends==v9.0.0"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
RUN --mount=type=cache,target=/openedx/.cache/pip,sharing=shared \
pip install "platform-plugin-aspects==v0.5.0"
pip install "platform-plugin-aspects==v0.6.0"
RUN --mount=type=cache,target=/openedx/.cache/pip,sharing=shared \
pip install "edx-event-routing-backends==v9.0.0"
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
}

DASHBOARD_LOCALES = {{SUPERSET_DASHBOARD_LOCALES}}
EMBEDDABLE_DASHBOARDS = {{SUPERSET_EMBEDDABLE_DASHBOARDS}}

for folder in ASSET_FOLDER_MAPPING.values():
os.makedirs(f"{BASE_DIR}/{folder}", exist_ok=True)
Expand Down Expand Up @@ -266,21 +267,32 @@ def update_dashboard_roles(roles):

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 = embeddable_uuid

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

for dashboard_slug, embeddable_uuid in EMBEDDABLE_DASHBOARDS.items():
create_embeddable_dashboard_by_slug(dashboard_slug, embeddable_uuid)

for locale in DASHBOARD_LOCALES:
for dashboard_slug, embeddable_uuid in EMBEDDABLE_DASHBOARDS.items():
slug = f"{dashboard_slug}-{locale}"
current_uuid = get_uuid5(embeddable_uuid, locale)
create_embeddable_dashboard_by_slug(slug, current_uuid)


def create_embeddable_dashboard_by_slug(dashboard_slug, embeddable_uuid):
"""Create an embeddable dashboard by slug"""
print(f"Creating embeddable dashboard {dashboard_slug}, {embeddable_uuid}")
dashboard = db.session.query(Dashboard).filter_by(slug=dashboard_slug).first()
if dashboard is None:
print(f"WARNING: Dashboard {dashboard_slug} not found")
return

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 = embeddable_uuid

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

if __name__ == "__main__":
main()