Skip to content

Commit

Permalink
Merge pull request #946 from openedx/cag/course-dashboard-link
Browse files Browse the repository at this point in the history
feat: add jinja filter to render a link to a dashboard
  • Loading branch information
Cristhian Garcia authored Sep 20, 2024
2 parents 282ba9b + 7671ecd commit 9041887
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 6 deletions.
1 change: 1 addition & 0 deletions requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ openedx-atlas
transifex-python
tutor>=15
ruamel.yaml
shandy-sqlfmt[jinjafmt]==0.21.2
30 changes: 28 additions & 2 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ asttokens==2.4.1
# via transifex-python
bcrypt==4.2.0
# via -r requirements/base.in
black==24.8.0
# via shandy-sqlfmt
cachetools==5.5.0
# via google-auth
certifi==2024.8.30
Expand All @@ -21,6 +23,8 @@ charset-normalizer==3.3.2
click==8.1.7
# via
# -r requirements/base.in
# black
# shandy-sqlfmt
# transifex-python
# tutor
future==1.0.0
Expand All @@ -36,23 +40,35 @@ importlib-resources==6.4.5
# -r requirements/base.in
# tutor
jinja2==3.1.4
# via tutor
# via
# shandy-sqlfmt
# tutor
kubernetes==30.1.0
# via tutor
markupsafe==2.1.5
# via jinja2
mypy==1.11.2
# via tutor
mypy-extensions==1.0.0
# via mypy
# via
# black
# mypy
oauthlib==3.2.2
# via
# kubernetes
# requests-oauthlib
openedx-atlas==0.6.2
# via -r requirements/base.in
packaging==24.1
# via black
parsimonious==0.10.0
# via pyseeyou
pathspec==0.12.1
# via black
platformdirs==4.3.6
# via
# black
# shandy-sqlfmt
pyasn1==0.6.1
# via
# pyasn1-modules
Expand Down Expand Up @@ -84,19 +100,29 @@ ruamel-yaml==0.18.6
# via -r requirements/base.in
ruamel-yaml-clib==0.2.8
# via ruamel-yaml
shandy-sqlfmt[jinjafmt]==0.21.2
# via -r requirements/base.in
six==1.16.0
# via
# asttokens
# kubernetes
# python-dateutil
tomli==2.0.1
# via
# black
# mypy
# shandy-sqlfmt
toolz==0.12.1
# via pyseeyou
tqdm==4.66.5
# via shandy-sqlfmt
transifex-python==3.5.0
# via -r requirements/base.in
tutor==18.1.3
# via -r requirements/base.in
typing-extensions==4.12.2
# via
# black
# mypy
# tutor
urllib3==2.2.3
Expand Down
1 change: 0 additions & 1 deletion requirements/dev.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ black
pyinstaller
pylint
twine
shandy-sqlfmt[jinjafmt]==0.21.2
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
RUN --mount=type=cache,target=/openedx/.cache/pip,sharing=shared \
pip install "platform-plugin-aspects==v0.11.0"
pip install "platform-plugin-aspects==v0.11.1"

RUN --mount=type=cache,target=/openedx/.cache/pip,sharing=shared \
pip install "edx-event-routing-backends>=9.3.0,<9.4"
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
RUN --mount=type=cache,target=/openedx/.cache/pip,sharing=shared \
pip install "platform-plugin-aspects==v0.11.0"
pip install "platform-plugin-aspects==v0.11.1"

RUN --mount=type=cache,target=/openedx/.cache/pip,sharing=shared \
pip install "edx-event-routing-backends>=9.3.0,<9.4"
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{{patch("clickhouse-server-config")}}

<logger>
<level>information</level>
<level>debug</level>
<console>1</console>
</logger>
</clickhouse>
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,30 @@ def translate_column_bool(column_name):
"""


SQL_LINK_FORMAT = """
concat('<a href="{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ SUPERSET_HOST }}/superset/dashboard/{dashboard_slug}/?native_filters=(NATIVE_FILTER-{filter_id}:(__cache:(label:''',
{column},
''',validateStatus:!f,value:!(''',
{column},
''')),extraFormData:(filters:!((col:{column},op:IN,val:!(''',
{column},
''')))),filterState:(label:''',
{column},
''',validateStatus:!f,value:!(''',
{column},
''')),id:NATIVE_FILTER-{filter_id},ownState:()))">',
{column},
'</a>'
)
"""
def get_filtered_dashboard_link(dashboard_slug, column_name, filter_id):
"""
Creates a link to a dashboard with filters preloaded given a dashboard-slug, a column_name and a filter_id
"""
lang = security_manager.get_preferences(g.user.username)

hlink = SQL_LINK_FORMAT.format(dashboard_slug=f"{dashboard_slug}-{lang}", column=column_name, filter_id=filter_id)

return hlink

{{patch("superset-jinja-filters")}}
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def can_view_courses_wrapper(*args, **kwargs):
'can_view_courses': can_view_courses_wrapper,
'translate_column': translate_column,
'translate_column_bool': translate_column_bool,
'get_filtered_dashboard_link': get_filtered_dashboard_link,
{% for filter in SUPERSET_EXTRA_JINJA_FILTERS %}'{{ filter }}': {{filter}},{% endfor %}
}

Expand Down

0 comments on commit 9041887

Please sign in to comment.