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

Add support for non-local resources #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 5 additions & 3 deletions easy_pdf/rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ def fetch_resources(uri, rel):
"""
Retrieves embeddable resource from given ``uri``.

For now only local resources (images, fonts) are supported.

:param str uri: path or url to image or font resource
:returns: path to local resource file.
:rtype: str
:raises: :exc:`~easy_pdf.exceptions.UnsupportedMediaPathException`
"""
if settings.STATIC_URL and uri.startswith(settings.STATIC_URL):
# For protocol relative, http and https URLs, we need to short circuit to skip
# path checking at the end of function
if uri.startswith('//') or uri.startswith('http://') or uri.startswith('https://'):
return uri
elif settings.STATIC_URL and uri.startswith(settings.STATIC_URL):
path = os.path.join(settings.STATIC_ROOT, uri.replace(settings.STATIC_URL, ""))
elif settings.MEDIA_URL and uri.startswith(settings.MEDIA_URL):
path = os.path.join(settings.MEDIA_ROOT, uri.replace(settings.MEDIA_URL, ""))
Expand Down