Skip to content

Commit f8ddd38

Browse files
authored
Fixed beta content paths breaking version alert replacement regex (#2008) (#2009)
1 parent 4d7f5ad commit f8ddd38

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

libraries/mixins.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class VersionAlertMixin:
2929
"""Mixin to selectively add a version alert to the context"""
3030

3131
def get_context_data(self, **kwargs):
32+
# todo: add units tests for this mixin, for standard paths and betas
3233
context = super().get_context_data(**kwargs)
3334
url_name = self.request.resolver_match.url_name
3435
if url_name in {"libraries", "releases-most-recent"}:
@@ -39,10 +40,22 @@ def get_context_data(self, **kwargs):
3940
alert_visible = not current_version_kwargs.get("content_path").startswith(
4041
LATEST_RELEASE_URL_PATH_STR
4142
)
43+
# TODO: this hack is here because the BoostVersionMixin only handles the
44+
# libraries format (boost-1-90-0-beta-1) for betas, while this path uses
45+
# 1_90_beta1 so we need to retrieve and set the selected_version
46+
# specifically for this use, db slug = "boost-1-90-0-beta1"
47+
# path_slug = 1_90_beta1
48+
path_slug = current_version_kwargs.get("content_path").split("/")[0]
49+
if path_slug == LATEST_RELEASE_URL_PATH_STR:
50+
context["selected_version"] = Version.objects.most_recent()
51+
else:
52+
version_slug = f"boost-{path_slug.replace('_', '-')}"
53+
context["selected_version"] = Version.objects.get(slug=version_slug)
54+
# end of hack
4255
current_version_kwargs.update(
4356
{
4457
"content_path": re.sub(
45-
r"([_0-9]+|master|develop)/(\S+)",
58+
r"([_0-9a-zA-Z]+|master|develop)/(\S+)",
4659
rf"{LATEST_RELEASE_URL_PATH_STR}/\2",
4760
current_version_kwargs.get("content_path"),
4861
)

0 commit comments

Comments
 (0)