changeset 558:626e6880e69a

macro.pdf2img: absoluteName for attachments
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Thu, 10 Mar 2011 13:37:56 +0100
parents 8421731685d4
children 7fa7120dfcc6
files data/plugin/macro/pdf2img.py
diffstat 1 files changed, 9 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/data/plugin/macro/pdf2img.py	Thu Mar 10 12:58:22 2011 +0100
+++ b/data/plugin/macro/pdf2img.py	Thu Mar 10 13:37:56 2011 +0100
@@ -105,10 +105,11 @@
     # only for posix implemented
     if os.name == 'posix':
         if attachment:
-            if not AttachFile.exists(request, pagename, attachment):
+            page_name, filename = AttachFile.absoluteName(attachment, pagename)
+            if not AttachFile.exists(request, page_name, filename):
                 return "attachment: %s does not exists" % attachment
-            url = AttachFile.getAttachUrl(pagename, attachment, request)
-            identifier = last_modified(request, pagename, attachment)
+            url = AttachFile.getAttachUrl(page_name, filename, request)
+            identifier = last_modified(request, page_name, filename)
         else:
             if not url_exists(url):
                 return "url: %s does not exists" % url
@@ -117,8 +118,10 @@
 
         key = get_img_key(request, url, pageno, identifier, format)
         if not cache.exists(request, key):
-            if attachment and attachment.lower().endswith('.pdf') and AttachFile.exists(request, pagename, attachment):
-                pdf_file = os.path.join(AttachFile.getAttachDir(request, pagename), attachment).encode(config.charset)
+            if attachment:
+                page_name, filename = AttachFile.absoluteName(attachment, pagename)
+                if filename and filename.lower().endswith('.pdf') and AttachFile.exists(request, page_name, filename):
+                    pdf_file = os.path.join(AttachFile.getAttachDir(request, page_name), filename).encode(config.charset)
             elif url:
                 #TODO: a mimetype check is needed beforehand 
                 pdf_file = fetch_pdf_item(request, url)
@@ -156,7 +159,7 @@
             else:
                 html_object = request.formatter.image(src=cache.url(request, key), alt="", width=width)
             if attachment:
-                url = AttachFile.getAttachUrl(pagename, attachment, request, addts=0, do='get')
+                url = AttachFile.getAttachUrl(page_name, filename, request, addts=0, do='get')
                 return '<B>%s Image from:</B> "<a href=%s>%s</a>"<hr>%s<br>' % (format.upper(), url, attachment, html_object)
             else:
                 return '<B>%s Image from:</B> "<a href=%s>%s</a>"<hr>%s<br>' % (format.upper(), url, url, html_object)