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

Open menu links to external websites in a new tab #1393

Merged
merged 1 commit into from
Aug 23, 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
3 changes: 2 additions & 1 deletion course/templates/course/_course_menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ <h4>{{ group.label|parse_localization }}</h4>
{% for entry in group.items %}
{% if entry.enabled %}
<li>
<a href="{{ entry.url }}" {% if entry.blank %} target="_blank" {% endif %}>
{% is_external_menu_url entry.url as is_external_menu_url_flag %}
<a href="{{ entry.url }}" {% if is_external_menu_url_flag or entry.blank %} target="_blank" {% endif %}>
{% if entry.icon_class %}
<span class="glyphicon glyphicon-{{ entry.icon_class }}" aria-hidden="true"></span>
{% endif %}
Expand Down
9 changes: 8 additions & 1 deletion course/templatetags/course.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, List, Union
from typing import Any, Dict, List, Optional, Union

from django import template
from django.db import models
Expand Down Expand Up @@ -139,6 +139,13 @@ def tags(profile, instance):
return mark_safe(' '.join(tag.html_label for tag in tags))


@register.simple_tag
def is_external_menu_url(url: Optional[str]) -> bool:
if url and '://' in url:
return True
return False


@register.filter
def enrollment_audience(enrollment_audience_val):
# convert enrollment audience Enum value to the string description
Expand Down
1 change: 0 additions & 1 deletion external_services/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ def url(self):
}
return self.service.as_leaf_class().get_url(replace=self.menu_url, kwargs=kwargs)
if '://' in self.menu_url:
# Deprecated, but DB can have old urls
return self.menu_url
return urljoin(self.course_instance.get_absolute_url(), self.menu_url)

Expand Down
Loading