Skip to content

Instantly share code, notes, and snippets.

@gerardo
Created April 3, 2013 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gerardo/5302466 to your computer and use it in GitHub Desktop.
Save gerardo/5302466 to your computer and use it in GitHub Desktop.
fetch_resource method for xhtml2pdf
def fetch_resources(uri, rel):
"""
Callback to allow xhtml2pdf/reportlab to retrieve
Images,Stylesheets, etc.
`uri` is the href attribute from the html link element.
`rel` gives a relative path, but it's not used here.
"""
if uri.startswith(settings.MEDIA_URL):
path = os.path.join(settings.MEDIA_ROOT,
uri.replace(settings.MEDIA_URL, ""))
elif uri.startswith(settings.STATIC_URL):
path = os.path.join(settings.STATIC_ROOT,
uri.replace(settings.STATIC_URL, ""))
else:
path = os.path.join(settings.STATIC_ROOT,
uri.replace(settings.STATIC_URL, ""))
if not os.path.isfile(path):
path = os.path.join(settings.MEDIA_ROOT,
uri.replace(settings.MEDIA_URL, ""))
return path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment