changeset 5106:fecbfc7f341d

twikidraw/anywikidraw: reduce code duplication, make code more similar
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 13 Sep 2009 17:47:59 +0200
parents 3feeab009683
children 26379ee2aa74
files MoinMoin/action/anywikidraw.py MoinMoin/action/twikidraw.py
diffstat 2 files changed, 6 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/anywikidraw.py	Sun Sep 13 16:49:42 2009 +0200
+++ b/MoinMoin/action/anywikidraw.py	Sun Sep 13 17:47:59 2009 +0200
@@ -25,26 +25,7 @@
 action_name = __name__.split('.')[-1]
 
 
-def gedit_drawing(self, url, text, **kw):
-    # This is called for displaying a drawing image by gui editor.
-    _ = self.request.getText
-    # TODO: this 'text' argument is kind of superfluous, replace by using alt=... kw arg
-    # ToDo: make this clickable for the gui editor
-    if 'alt' not in kw or not kw['alt']:
-        kw['alt'] = text
-    # we force the title here, needed later for html>wiki converter
-    kw['title'] = "drawing:%s" % wikiutil.quoteWikinameURL(url)
-    pagename, drawing = AttachFile.absoluteName(url, self.page.page_name)
-    containername = wikiutil.taintfilename(drawing)
-    drawing_url = AttachFile.getAttachUrl(pagename, containername, self.request)
-    ci = AttachFile.ContainerItem(self.request, pagename, containername)
-    if not ci.exists():
-        title = _('Create new drawing "%(filename)s (opens in new window)"') % {'filename': containername}
-        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.png')
-    return self.image(**kw)
+from MoinMoin.action.twikidraw import gedit_drawing
 
 
 def attachment_drawing(self, url, text, **kw):
--- a/MoinMoin/action/twikidraw.py	Sun Sep 13 16:49:42 2009 +0200
+++ b/MoinMoin/action/twikidraw.py	Sun Sep 13 17:47:59 2009 +0200
@@ -40,7 +40,7 @@
     drawing_url = AttachFile.getAttachUrl(pagename, containername, self.request)
     ci = AttachFile.ContainerItem(self.request, pagename, containername)
     if not ci.exists():
-        title = _('Create new drawing "%(filename)s (opens in new window)"') % {'filename': drawing}
+        title = _('Create new drawing "%(filename)s (opens in new window)"') % {'filename': self.text(containername)}
         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)
@@ -58,12 +58,12 @@
     drawing_url = AttachFile.getAttachUrl(pagename, containername, self.request, do='modify')
     ci = AttachFile.ContainerItem(self.request, pagename, containername)
     if not ci.exists():
-        title = _('Create new drawing "%(filename)s (opens in new window)"') % {'filename': drawing}
+        title = _('Create new drawing "%(filename)s (opens in new window)"') % {'filename': self.text(containername)}
         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)
 
-    title = _('Edit drawing %(filename)s (opens in new window)') % {'filename': self.text(drawing)}
+    title = _('Edit drawing %(filename)s (opens in new window)') % {'filename': self.text(containername)}
     kw['src'] = src = ci.member_url('drawing.png')
     kw['css'] = 'drawing'
 
@@ -84,13 +84,13 @@
             wikiutil.escape(drawing_url, 1), title, title))
         # unxml, because 4.01 concrete will not validate />
         map = map.replace(u'/>', u'>')
-        title = _('Clickable drawing: %(filename)s') % {'filename': self.text(drawing)}
+        title = _('Clickable drawing: %(filename)s') % {'filename': self.text(containername)}
         if 'title' not in kw:
             kw['title'] = title
         if 'alt' not in kw:
             kw['alt'] = kw['title']
         kw['usemap'] = '#'+mapid
-        return map + self.image(**kw)
+        return self.url(1, drawing_url) + map + self.image(**kw) + self.url(0)
     else:
         if 'title' not in kw:
             kw['title'] = title