|
5 | 5 | import structlog |
6 | 6 | from django.conf import settings |
7 | 7 | from django.http import Http404, HttpResponse, HttpResponseRedirect |
8 | | -from django.shortcuts import render |
| 8 | +from django.shortcuts import get_object_or_404, render |
9 | 9 | from django.urls import resolve as url_resolve |
10 | 10 | from django.utils.decorators import method_decorator |
11 | 11 | from django.views import View |
|
36 | 36 |
|
37 | 37 |
|
38 | 38 | class ServePageRedirect(CDNCacheControlMixin, ServeRedirectMixin, ServeDocsMixin, View): |
| 39 | + def get(self, request, subproject_slug=None, filename=""): |
39 | 40 |
|
40 | | - def get(self, |
41 | | - request, |
42 | | - project_slug=None, |
43 | | - subproject_slug=None, |
44 | | - version_slug=None, |
45 | | - filename='', |
46 | | - ): # noqa |
| 41 | + unresolved_domain = request.unresolved_domain |
| 42 | + project = unresolved_domain.project |
47 | 43 |
|
48 | | - version_slug = self.get_version_from_host(request, version_slug) |
49 | | - final_project, lang_slug, version_slug, filename = _get_project_data_from_request( # noqa |
50 | | - request, |
51 | | - project_slug=project_slug, |
52 | | - subproject_slug=subproject_slug, |
53 | | - lang_slug=None, |
54 | | - version_slug=version_slug, |
55 | | - filename=filename, |
56 | | - ) |
| 44 | + # Use the project from the domain, or use the subproject slug. |
| 45 | + if subproject_slug: |
| 46 | + project = get_object_or_404( |
| 47 | + project.subprojects, alias=subproject_slug |
| 48 | + ).child |
57 | 49 |
|
58 | | - if self._is_cache_enabled(final_project): |
| 50 | + # Get the default version from the current project, |
| 51 | + # or the version from the external domain. |
| 52 | + if unresolved_domain.is_from_external_domain: |
| 53 | + version_slug = unresolved_domain.external_version_slug |
| 54 | + else: |
| 55 | + version_slug = project.get_default_version() |
| 56 | + |
| 57 | + if self._is_cache_enabled(project): |
59 | 58 | # All requests from this view can be cached. |
60 | 59 | # This is since the final URL will check for authz. |
61 | 60 | self.cache_request = True |
62 | 61 |
|
63 | | - is_external = request.unresolved_domain.is_from_external_domain |
| 62 | + # TODO: find a better way to pass this to the middleware. |
| 63 | + request.path_project_slug = project.slug |
64 | 64 |
|
65 | 65 | return self.system_redirect( |
66 | 66 | request=request, |
67 | | - final_project=final_project, |
| 67 | + final_project=project, |
68 | 68 | version_slug=version_slug, |
69 | 69 | filename=filename, |
70 | | - is_external_version=is_external, |
| 70 | + is_external_version=unresolved_domain.is_from_external_domain, |
71 | 71 | ) |
72 | 72 |
|
73 | 73 |
|
|
0 commit comments