Skip to content

Commit

Permalink
Pass full_path to exact redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
ericholscher committed Aug 29, 2022
1 parent 464820f commit 270bbda
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion common
1 change: 1 addition & 0 deletions readthedocs/proxito/views/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ def get(self, request, proxito_path, template_name='404.html'):
log.bind(
project_slug=final_project.slug,
version_slug=version_slug,
filename=filename,
)

if version_slug:
Expand Down
15 changes: 7 additions & 8 deletions readthedocs/redirects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,16 @@ def get_full_path(self, filename, language=None, version_slug=None, allow_crossd
filename=filename,
)

def get_redirect_path(self, path, language=None, version_slug=None):
def get_redirect_path(self, path, full_path, language=None, version_slug=None):
method = getattr(
self,
'redirect_{type}'.format(
type=self.redirect_type,
),
)
return method(path, language=language, version_slug=version_slug)
return method(path, full_path=full_path, language=language, version_slug=version_slug)

def redirect_prefix(self, path, language=None, version_slug=None):
def redirect_prefix(self, path, full_path, language=None, version_slug=None):
if path.startswith(self.from_url):
log.debug("Redirecting...", redirect=self)
# pep8 and blank don't agree on having a space before :.
Expand All @@ -189,7 +189,7 @@ def redirect_prefix(self, path, language=None, version_slug=None):
)
return to

def redirect_page(self, path, language=None, version_slug=None):
def redirect_page(self, path, full_path, language=None, version_slug=None):
if path == self.from_url:
log.debug('Redirecting...', redirect=self)
to = self.get_full_path(
Expand All @@ -200,8 +200,7 @@ def redirect_page(self, path, language=None, version_slug=None):
)
return to

def redirect_exact(self, path, language=None, version_slug=None):
full_path = path
def redirect_exact(self, path, full_path, language=None, version_slug=None):
if language and version_slug:
# reconstruct the full path for an exact redirect
full_path = self.get_full_path(path, language, version_slug, allow_crossdomain=False)
Expand All @@ -215,7 +214,7 @@ def redirect_exact(self, path, language=None, version_slug=None):
cut_path = full_path.replace(match, self.to_url, 1)
return cut_path

def redirect_sphinx_html(self, path, language=None, version_slug=None):
def redirect_sphinx_html(self, path, full_path, language=None, version_slug=None):
for ending in ['/', '/index.html']:
if path.endswith(ending):
log.debug('Redirecting...', redirect=self)
Expand All @@ -228,7 +227,7 @@ def redirect_sphinx_html(self, path, language=None, version_slug=None):
allow_crossdomain=False,
)

def redirect_sphinx_htmldir(self, path, language=None, version_slug=None):
def redirect_sphinx_htmldir(self, path, full_path, language=None, version_slug=None):
if path.endswith('.html'):
log.debug('Redirecting...', redirect=self)
path = path[1:] # Strip leading slash.
Expand Down
2 changes: 2 additions & 0 deletions readthedocs/redirects/querysets.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ def get_redirect_path_with_status(
# can't think in a case where there can be more at this point. I'm
# leaving the loop just in case for now
for redirect in queryset.select_related('project'):
log.info('Got a redirect', normalized_path=normalized_path)
new_path = redirect.get_redirect_path(
path=normalized_path,
full_path=normalized_full_path,
language=language,
version_slug=version_slug,
)
Expand Down

0 comments on commit 270bbda

Please sign in to comment.