-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use absolute URL for PDF files when rendering
Make relative PDF files correctly displayed on sites that cached our HTML output (e.g. vjudge.net) Also refactor `get_submission_file_url` into utility functions
- Loading branch information
1 parent
faadb0b
commit 48b12e1
Showing
4 changed files
with
31 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import urllib.parse | ||
|
||
from django.conf import settings | ||
from django.core.exceptions import ValidationError | ||
from django.core.validators import URLValidator | ||
|
||
URL_VALIDATOR = URLValidator(schemes=['http', 'https']) | ||
|
||
|
||
def get_absolute_url(url, host): | ||
try: | ||
URL_VALIDATOR(url) | ||
return url | ||
except ValidationError: | ||
return urllib.parse.urljoin(host, url) | ||
|
||
|
||
def get_absolute_submission_file_url(source): | ||
return get_absolute_url(source, settings.SITE_FULL_URL) | ||
|
||
|
||
def get_absolute_pdf_url(pdf_url): | ||
return get_absolute_url(pdf_url, settings.SITE_FULL_URL) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters