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

Added ability to support remote URIs #13

Merged
merged 1 commit into from
Feb 28, 2014
Merged
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 django_xhtml2pdf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def fetch_resources(uri, rel):
path = os.path.join(d, uri.replace(settings.STATIC_URL, ""))
if os.path.exists(path):
break
elif uri.startswith("http://") or uri.startswith("https://"):
path = uri
else:
raise UnsupportedMediaPathException(
'media urls must start with %s or %s' % (
Expand All @@ -47,17 +49,17 @@ def generate_pdf_template_object(template_object, file_object, context):
return file_object

#===============================================================================
# Main
# Main
#===============================================================================

def generate_pdf(template_name, file_object=None, context=None): # pragma: no cover
"""
Uses the xhtml2pdf library to render a PDF to the passed file_object, from the
given template name.

This returns the passed-in file object, filled with the actual PDF data.
In case the passed in file object is none, it will return a StringIO instance.

"""
if not file_object:
file_object = StringIO.StringIO()
Expand Down