diff MoinMoin/formatter/text_html.py @ 1910:5c3dffe2abf1

new function AttachFile.exists to reduce code duplication
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 25 Mar 2007 22:37:45 +0200
parents 9406e02388cf
children bb2e053067fb
line wrap: on
line diff
--- a/MoinMoin/formatter/text_html.py	Sun Mar 25 21:55:13 2007 +0200
+++ b/MoinMoin/formatter/text_html.py	Sun Mar 25 22:37:45 2007 +0200
@@ -633,8 +633,7 @@
         pagename, filename = AttachFile.absoluteName(url, self.page.page_name)
         #self.request.log("attachment_link: url %s pagename %s filename %s" % (url, pagename, filename))
         fname = wikiutil.taintfilename(filename)
-        fpath = AttachFile.getFilename(self.request, pagename, fname)
-        if not os.path.exists(fpath):
+        if not AttachFile.exists(self.request, pagename, fname):
             linktext = _('Upload new attachment "%(filename)s"')
             return wikiutil.link_tag(
                 self.request,
@@ -651,8 +650,7 @@
         _ = self.request.getText
         pagename, filename = AttachFile.absoluteName(url, self.page.page_name)
         fname = wikiutil.taintfilename(filename)
-        fpath = AttachFile.getFilename(self.request, pagename, fname)
-        if not os.path.exists(fpath):
+        if not AttachFile.exists(self.request, pagename, fname):
             linktext = _('Upload new attachment "%(filename)s"')
             return wikiutil.link_tag(
                 self.request,
@@ -673,16 +671,16 @@
         fname = fname + u".png"
         filename = filename + u".png"
         # fallback for old gif drawings (1.1 -> 1.2)
-        fpath = AttachFile.getFilename(self.request, pagename, fname)
-        if not os.path.exists(fpath):
+        exists = AttachFile.exists(self.request, pagename, fname)
+        if not exists:
             gfname = fname[:-4] + u".gif"
             gfilename = filename[:-4] + u".gif"
-            gfpath = AttachFile.getFilename(self.request, pagename, gfname)
-            if os.path.exists(gfpath):
-                fname, filename, fpath = gfname, gfilename, gfpath
+            exists = AttachFile.exists(self.request, pagename, gfname)
+            if exists:
+                fname, filename = gfname, gfilename
 
         # check whether attachment exists, possibly point to upload form
-        if not os.path.exists(fpath):
+        if not exists:
             linktext = _('Create new drawing "%(filename)s"')
             return wikiutil.link_tag(
                 self.request,