|
14 | 14 | )
|
15 | 15 | from django.shortcuts import redirect
|
16 | 16 | from django.template.loader import render_to_string
|
| 17 | +from django.urls import reverse |
17 | 18 | from django.views import View
|
18 | 19 | from django.views.generic import TemplateView
|
19 | 20 | from requests.compat import chardet
|
20 | 21 |
|
21 | 22 | from libraries.constants import LATEST_RELEASE_URL_PATH_STR
|
| 23 | +from libraries.utils import legacy_path_transform |
22 | 24 | from versions.models import Version
|
23 | 25 |
|
24 | 26 | from .asciidoc import convert_adoc_to_html
|
@@ -111,6 +113,14 @@ def build_path(self):
|
111 | 113 | Builds the path from URL kwargs
|
112 | 114 | """
|
113 | 115 | content_path = self.kwargs.get("content_path")
|
| 116 | + updated_legacy_path = legacy_path_transform(content_path) |
| 117 | + if updated_legacy_path != content_path: |
| 118 | + return redirect( |
| 119 | + reverse( |
| 120 | + self.request.resolver_match.view_name, |
| 121 | + kwargs={"content_path": updated_legacy_path}, |
| 122 | + ) |
| 123 | + ) |
114 | 124 |
|
115 | 125 | print(self.markdown_local)
|
116 | 126 | if self.markdown_local:
|
@@ -208,6 +218,14 @@ def get(self, request, *args, **kwargs):
|
208 | 218 | See the *_static_config.json files for URL mappings to specific S3 keys.
|
209 | 219 | """
|
210 | 220 | content_path = self.kwargs.get("content_path")
|
| 221 | + updated_legacy_path = legacy_path_transform(content_path) |
| 222 | + if updated_legacy_path != content_path: |
| 223 | + return redirect( |
| 224 | + reverse( |
| 225 | + self.request.resolver_match.view_name, |
| 226 | + kwargs={"content_path": updated_legacy_path}, |
| 227 | + ) |
| 228 | + ) |
211 | 229 |
|
212 | 230 | # For some reason, if a user cancels a social signup (cancelling a GitHub
|
213 | 231 | # signup, for example), the redirect URL comes through this view, so we
|
@@ -513,6 +531,14 @@ class ImageView(View):
|
513 | 531 | def get(self, request, *args, **kwargs):
|
514 | 532 | # TODO: Add caching logic
|
515 | 533 | content_path = self.kwargs.get("content_path")
|
| 534 | + updated_legacy_path = legacy_path_transform(content_path) |
| 535 | + if updated_legacy_path != content_path: |
| 536 | + return redirect( |
| 537 | + reverse( |
| 538 | + self.request.resolver_match.view_name, |
| 539 | + kwargs={"content_path": updated_legacy_path}, |
| 540 | + ) |
| 541 | + ) |
516 | 542 |
|
517 | 543 | client = get_s3_client()
|
518 | 544 | try:
|
|
0 commit comments