Created
April 3, 2013 15:53
-
-
Save gerardo/5302466 to your computer and use it in GitHub Desktop.
fetch_resource method for xhtml2pdf
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
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