Skip to content

Enabling custom 404 subprojects pages #6153

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

Closed
Closed
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
14 changes: 12 additions & 2 deletions readthedocs/core/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SubdomainMiddleware(MiddlewareMixin):

"""Middleware to display docs for non-dashboard domains."""

def process_request(self, request):
def process_request(self, request, subproject_slug=None):
"""
Process requests for unhandled domains.

Expand All @@ -33,11 +33,21 @@ def process_request(self, request):
if not settings.USE_SUBDOMAIN:
return None

if subproject is None and subproject_slug:
try:
rel = ProjectRelationship.objects.get(
parent=kwargs['project'],
alias=subproject_slug,
)
subproject = rel.child
except (ProjectRelationship.DoesNotExist, KeyError):
subproject = get_object_or_404(Project, slug=subproject_slug)

full_host = host = request.get_host().lower()
path = request.get_full_path()
log_kwargs = dict(host=host, path=path)
public_domain = settings.PUBLIC_DOMAIN

if public_domain is None:
public_domain = settings.PRODUCTION_DOMAIN
if ':' in host:
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/redirects/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def project_and_path_from_request(request, path):
project = Project.objects.get(slug=project_slug)
except Project.DoesNotExist:
return None, path
return project, path
return project, path, project_slug


def language_and_version_from_path(path):
Expand Down