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

Feature | Reference Homepage redirect #708

Merged
merged 3 commits into from
May 8, 2023
Merged
Changes from 2 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
6 changes: 5 additions & 1 deletion iati/custom_middleware.py
Original file line number Diff line number Diff line change
@@ -27,7 +27,12 @@ def __call__(self, request):
self.path_parts = self.remove_language_code(valid_path_parts)
self.is_download = "downloads" in self.path_parts
self.stripped_path = '/'.join(self.path_parts)
full_url = request.build_absolute_uri()
parsed_url = urllib.parse.urlparse(full_url)
domain = parsed_url.netloc

if domain == 'reference.iatistandard.org' and parsed_url.path == '':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing this out with editing my /etc/hosts, and the parsed_url.path isn't blank:

web_1       | DOMAIN: reference.iatistandard.org
web_1       | PATH: /

Also to cover our bases, I think we should include the /en/ and /fr/ paths as some people may have cached redirects to those. And then lastly I wouldn't hardcode the /en/ in the redirect, and just redirect it to /iati-standard/. The locale redirects will direct the user to the correct /en/iati-standard or /fr/iati-standard based on their browser. So all together:

        if domain == 'reference.iatistandard.org' and parsed_url.path in ['/', '/en/', '/fr/']:
            return http.HttpResponsePermanentRedirect(f'{settings.REFERENCE_REDIRECT_BASE_URL}/iati-standard/')

return http.HttpResponsePermanentRedirect(f'{settings.REFERENCE_REDIRECT_BASE_URL}/en/iati-standard/')
if self.path_is_redirect:
return http.HttpResponsePermanentRedirect(self.redirected_url)
elif not request.path_info.endswith('/') and self.path_is_not_exception:
@@ -89,7 +94,6 @@ def redirected_url(self):
if self.is_download:
return '{}{}{}'.format(settings.REFERENCE_REDIRECT_BASE_URL, redirect_match, self.stripped_path)
return '{}{}{}{}'.format(settings.REFERENCE_REDIRECT_BASE_URL, redirect_match, self.stripped_path, "/")

return self.path

@property