changeset 5086:6910e50f3c6b

drawings: always use the same member file names within .tdraw / .adraw We do this so that renaming the drawing does not make renaming the member files necessary. We always use drawing.* for the member file names.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 12 Sep 2009 01:28:17 +0200
parents cc619e704b38
children d094bbd6c7c4
files MoinMoin/action/anywikidraw.py MoinMoin/action/twikidraw.py
diffstat 2 files changed, 17 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/anywikidraw.py	Sat Sep 12 00:23:33 2009 +0200
+++ b/MoinMoin/action/anywikidraw.py	Sat Sep 12 01:28:17 2009 +0200
@@ -51,7 +51,7 @@
         img = self.icon('attachimg')  # TODO: we need a new "drawimg" in similar grey style and size
         css = 'nonexistent'
         return self.url(1, drawing_url, css=css, title=title) + img + self.url(0)
-    kw['src'] = ci.member_url(drawing + u'.png')
+    kw['src'] = ci.member_url('drawing.png')
     return self.image(**kw)
 
 def attachment_drawing(self, url, text, **kw):
@@ -70,11 +70,11 @@
         return self.url(1, drawing_url, css=css, title=title) + img + self.url(0)
 
     title = _('Edit drawing %(filename)s (opens in new window)') % {'filename': self.text(drawing)}
-    kw['src'] = src = ci.member_url(drawing + u'.png')
+    kw['src'] = src = ci.member_url('drawing.png')
     kw['css'] = 'drawing'
 
     try:
-        mapfile = ci.get(drawing + u'.map')
+        mapfile = ci.get('drawing.map')
         map = mapfile.read()
         mapfile.close()
     except (KeyError, IOError, OSError):
@@ -125,7 +125,6 @@
         if not request.user.may.write(pagename):
             return _('You are not allowed to save a drawing on this page.')
         file_upload = request.files.get('filepath')
-        print "file_upload: %s" % file_upload
         if not file_upload:
             # This might happen when trying to upload file names
             # with non-ascii characters on Safari.
@@ -134,13 +133,12 @@
         filename = request.form['filename']
         basepath, basename = os.path.split(filename)
         basename, ext = os.path.splitext(basename)
-        basename = basename.replace('.svg', '')
 
-        ci = AttachFile.ContainerItem(request, pagename, basename + '.adraw')
+        ci = AttachFile.ContainerItem(request, pagename, target + '.adraw')
         filecontent = file_upload.stream
         content_length = None
         if ext == '.svg': # TWikiDraw POSTs this first
-            AttachFile._addLogEntry(request, 'ATTDRW', pagename, basename + '.adraw')
+            AttachFile._addLogEntry(request, 'ATTDRW', pagename, target + '.adraw')
             ci.truncate()
             filecontent = filecontent.read() # read file completely into memory
             filecontent = filecontent.replace("\r", "")
@@ -157,7 +155,7 @@
             filecontent = filecontent.read()
 
         if filecontent:
-            ci.put(basename + ext, filecontent, content_length)
+            ci.put('drawing' + ext, filecontent, content_length)
 
     def render(self):
         _ = self._
@@ -172,7 +170,7 @@
         ci = AttachFile.ContainerItem(request, pagename, target + '.adraw')
         if ci.exists():
             drawing_name = "%s.svg" % target
-            target_url = ci.member_url(target + '.svg')
+            target_url = ci.member_url('drawing.svg')
 
         html = """
     <h2> %(editdrawing)s </h2>
@@ -196,7 +194,7 @@
            <param name="DrawingHeight" value="600"/>
            <param name="DrawingURL" value="%(target_url)s"/>
            <param name="PageURL" value="%(url)s/%(pagename)s">
-           <param name="UploadURL" value="%(pagename)s?action=anywikidraw&do=save&target=%(target)s.svg"/>
+           <param name="UploadURL" value="%(pagename)s?action=anywikidraw&do=save&target=%(target)s"/>
 
            <!-- The following parameters are used to configure the drawing applet -->
            <param name="Locale" value="en"/>
--- a/MoinMoin/action/twikidraw.py	Sat Sep 12 00:23:33 2009 +0200
+++ b/MoinMoin/action/twikidraw.py	Sat Sep 12 01:28:17 2009 +0200
@@ -53,7 +53,7 @@
         img = self.icon('attachimg')  # TODO: we need a new "drawimg" in similar grey style and size
         css = 'nonexistent'
         return self.url(1, drawing_url, css=css, title=title) + img + self.url(0)
-    kw['src'] = ci.member_url(drawing + u'.png')
+    kw['src'] = ci.member_url('drawing.png')
     return self.image(**kw)
 
 def attachment_drawing(self, url, text, **kw):
@@ -72,11 +72,11 @@
         return self.url(1, drawing_url, css=css, title=title) + img + self.url(0)
 
     title = _('Edit drawing %(filename)s (opens in new window)') % {'filename': self.text(drawing)}
-    kw['src'] = src = ci.member_url(drawing + u'.png')
+    kw['src'] = src = ci.member_url('drawing.png')
     kw['css'] = 'drawing'
 
     try:
-        mapfile = ci.get(drawing + u'.map')
+        mapfile = ci.get('drawing.map')
         map = mapfile.read()
         mapfile.close()
     except (KeyError, IOError, OSError):
@@ -122,6 +122,7 @@
         _ = self._
         pagename = self.pagename
         request = self.request
+        target = self.target
         if not TextCha(request).check_answer_from_form():
             return _('TextCha: Wrong answer! Go back and try again...')
         if not request.user.may.write(pagename):
@@ -136,11 +137,11 @@
         filename = request.form['filename']
         basepath, basename = os.path.split(filename)
         basename, ext = os.path.splitext(basename)
-        ci = AttachFile.ContainerItem(request, pagename, basename + '.tdraw')
+        ci = AttachFile.ContainerItem(request, pagename, target + '.tdraw')
         filecontent = file_upload.stream
         content_length = None
         if ext == '.draw': # TWikiDraw POSTs this first
-            AttachFile._addLogEntry(request, 'ATTDRW', pagename, basename + '.tdraw')
+            AttachFile._addLogEntry(request, 'ATTDRW', pagename, target + '.tdraw')
             ci.truncate()
             filecontent = filecontent.read() # read file completely into memory
             filecontent = filecontent.replace("\r", "")
@@ -156,7 +157,7 @@
             # without reading it into memory completely:
             filecontent = filecontent.read()
 
-        ci.put(basename + ext, filecontent, content_length)
+        ci.put('drawing' + ext, filecontent, content_length)
         #return _("Thank you for your changes. Your attention to detail is appreciated.")
 
 
@@ -169,8 +170,8 @@
         now = time.time()
         htdocs = "%s%s" % (request.cfg.url_prefix_static, "/applets/TWikiDrawPlugin")
         ci = AttachFile.ContainerItem(request, pagename, target + '.tdraw')
-        drawpath = ci.member_url(target + '.draw')
-        pngpath = ci.member_url(target + '.png')
+        drawpath = ci.member_url('drawing.draw')
+        pngpath = ci.member_url('drawing.png')
         pagelink = request.href(pagename, action=action_name, ts=now)
         helplink = Page(request, "HelpOnActions/AttachFile").url(request)
         savelink = request.href(pagename, action=action_name, do='save', target=target)