Skip to content

Commit 3c3a1c3

Browse files
authored
Support single version subprojects URLs to serve from Django (#5690)
Support single version subprojects URLs to serve from Django
2 parents 5a19651 + 5a3a96d commit 3c3a1c3

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

readthedocs/core/urls/subdomain.py

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
serve_docs,
4747
name='docs_detail',
4848
),
49+
4950
]
5051

5152
groups = [subdomain_urls]

readthedocs/core/views/serve.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,27 @@ def inner_view( # noqa
111111
def redirect_project_slug(request, project, subproject): # pylint: disable=unused-argument
112112
"""Handle / -> /en/latest/ directs on subdomains."""
113113
urlparse_result = urlparse(request.get_full_path())
114+
115+
# When accessing docs.customdomain.org/projects/subproject/ and the
116+
# ``subproject`` is a single-version, we don't have to redirect but to serve
117+
# the index file instead.
118+
if subproject and subproject.single_version:
119+
try:
120+
# HACK: this only affects corporate site and won't be hit on the
121+
# community. This can be removed once the middleware incorporates
122+
# more data or redirects happen outside this application
123+
# See: https://github.com/rtfd/readthedocs.org/pull/5690
124+
log.warning('Serving docs for a single-version subproject instead redirecting')
125+
from readthedocsinc.core.views import serve_docs as corporate_serve_docs # noqa
126+
return corporate_serve_docs(request, project, project.slug, subproject, subproject.slug)
127+
except Exception:
128+
log.exception('Error trying to redirect a single-version subproject')
129+
114130
return HttpResponseRedirect(
115131
resolve(
116132
subproject or project,
117133
query_params=urlparse_result.query,
118-
)
134+
),
119135
)
120136

121137

0 commit comments

Comments
 (0)