|
19 | 19 | InvalidExternalVersionError,
|
20 | 20 | InvalidPathForVersionedProjectError,
|
21 | 21 | TranslationNotFoundError,
|
| 22 | + TranslationWithoutVersionError, |
22 | 23 | VersionNotFoundError,
|
23 | 24 | unresolver,
|
24 | 25 | )
|
@@ -357,6 +358,25 @@ def get_using_unresolver(self, request):
|
357 | 358 | # TODO: find a better way to pass this to the middleware.
|
358 | 359 | request.path_project_slug = exc.project.slug
|
359 | 360 | raise Http404
|
| 361 | + except TranslationWithoutVersionError as exc: |
| 362 | + project = exc.project |
| 363 | + # TODO: find a better way to pass this to the middleware. |
| 364 | + request.path_project_slug = project.slug |
| 365 | + |
| 366 | + if unresolved_domain.is_from_external_domain: |
| 367 | + version_slug = unresolved_domain.external_version_slug |
| 368 | + else: |
| 369 | + version_slug = None |
| 370 | + # Redirect to the default version of the current translation. |
| 371 | + # This is `/en -> /en/latest/` or |
| 372 | + # `/projects/subproject/en/ -> /projects/subproject/en/latest/`. |
| 373 | + return self.system_redirect( |
| 374 | + request=request, |
| 375 | + final_project=project, |
| 376 | + version_slug=version_slug, |
| 377 | + filename="", |
| 378 | + is_external_version=unresolved_domain.is_from_external_domain, |
| 379 | + ) |
360 | 380 | except InvalidPathForVersionedProjectError as exc:
|
361 | 381 | project = exc.project
|
362 | 382 | if unresolved_domain.is_from_external_domain:
|
@@ -745,7 +765,9 @@ def get_using_unresolver(self, request, path):
|
745 | 765 |
|
746 | 766 | project = None
|
747 | 767 | version = None
|
748 |
| - filename = None |
| 768 | + # If we weren't able to resolve a filename, |
| 769 | + # then the path is the filename. |
| 770 | + filename = path |
749 | 771 | lang_slug = None
|
750 | 772 | version_slug = None
|
751 | 773 | # Try to map the current path to a project/version/filename.
|
@@ -778,6 +800,10 @@ def get_using_unresolver(self, request, path):
|
778 | 800 | version_slug = exc.version_slug
|
779 | 801 | filename = exc.filename
|
780 | 802 | contextualized_404_class = ProjectTranslationHttp404
|
| 803 | + except TranslationWithoutVersionError as exc: |
| 804 | + project = exc.project |
| 805 | + lang_slug = exc.language |
| 806 | + # TODO: Use a contextualized 404 |
781 | 807 | except InvalidExternalVersionError as exc:
|
782 | 808 | project = exc.project
|
783 | 809 | # TODO: Use a contextualized 404
|
|
0 commit comments