Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support single version subprojects URLs to serve from Django #5690

Merged
merged 5 commits into from
Jun 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions readthedocs/core/urls/subdomain.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
serve_docs,
name='docs_detail',
),

]

groups = [subdomain_urls]
Expand Down
18 changes: 17 additions & 1 deletion readthedocs/core/views/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,27 @@ def inner_view( # noqa
def redirect_project_slug(request, project, subproject): # pylint: disable=unused-argument
"""Handle / -> /en/latest/ directs on subdomains."""
urlparse_result = urlparse(request.get_full_path())

# When accessing docs.customdomain.org/projects/subproject/ and the
# ``subproject`` is a single-version, we don't have to redirect but to serve
# the index file instead.
if subproject and subproject.single_version:
try:
# HACK: this only affects corporate site and won't be hit on the
# community. This can be removed once the middleware incorporates
# more data or redirects happen outside this application
# See: https://github.com/rtfd/readthedocs.org/pull/5690
log.warning('Serving docs for a single-version subproject instead redirecting')
from readthedocsinc.core.views import serve_docs as corporate_serve_docs # noqa
return corporate_serve_docs(request, project, project.slug, subproject, subproject.slug)
except Exception:
log.exception('Error trying to redirect a single-version subproject')

return HttpResponseRedirect(
resolve(
subproject or project,
query_params=urlparse_result.query,
)
),
)


Expand Down