changeset 22:914915a1c47a

arnica_slides: some refactoring
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Fri, 23 May 2008 10:29:36 +0200
parents 744416ee6590
children 26d9d5f67365
files data/plugin/action/arnica_slides.py
diffstat 1 files changed, 20 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/data/plugin/action/arnica_slides.py	Fri May 23 05:37:47 2008 +0200
+++ b/data/plugin/action/arnica_slides.py	Fri May 23 10:29:36 2008 +0200
@@ -24,6 +24,11 @@
 
 action_name = __name__.split('.')[-1]
 
+def getAttachUrl(pagename, filename):
+    url = "/%(pagename)s?action=arnica_slides&do=view&target=%(filename)s" % {'pagename': pagename,
+                                                                              'filename': filename}
+    return wikiutil.escape(url)
+
 class arnica_slides(ActionBase):
     """ arnica_slides page action
 
@@ -68,13 +73,11 @@
 
         for filename in text:
             if not image_for_webnail:
-                name = "/%(pagename)s?action=arnica_slides&do=view&target=%(filename)s" % {'pagename': pagename,
-                                                                                           'filename': filename}  
-                name = wikiutil.escape(name)
+                url = getAttachUrl(pagename, filename)
             else:
-                name = AttachFile.getAttachUrl(pagename, filename, request)
+                url = AttachFile.getAttachUrl(pagename, filename, request)
 
-            if name == this_image:
+            if url == this_image:
                 txt += '<option selected value="%(name)s">%(alias)s' % {
                     "name": this_image,
                     "alias": filename.replace('tmp.', '')}
@@ -228,20 +231,14 @@
         @param idx:  index position of the image
         @param image_for_webnail:  identifier for AttchFile or arnica_slides
         """
-
-        attachment_path = AttachFile.getAttachDir(request, pagename)
-        static_path, static_url = self.get_path_url(request, pagename, attachment_path )
-
         if not image_for_webnail:
-            static_url = "/%(pagename)s?action=arnica_slides&do=view&target=" % {'pagename': pagename}  
-            static_url = wikiutil.escape(static_url)
+            static_url = getAttachUrl(pagename, "")
+        else:
+            attachment_path = AttachFile.getAttachDir(request, pagename)
+            static_path, static_url = self.get_path_url(request, pagename, attachment_path)
 
         option_webnail = self.option_list(static_url + target[idx], pagename, target, request, image_for_webnail)
 
-        #static_path, static_url = self.get_path_url(request, pagename, attachment_path)
-        #if not image_for_webnail:
-        #    static_url = "/%(pagename)s?action=arnica_slides&do=view&target=" % {'pagename': pagename}
-            
         inner_table_style = ' style="border-style:none; margin:10px;"'
 
         this_webnail_list = ''
@@ -309,7 +306,7 @@
 "this_exif_date_text": wikiutil.escape(exif_date[idx], quote=1),
 "this_exif_date_list": wikiutil.escape(','.join(exif_date), quote=1),
 
-"this_image": static_url + target[idx], # AttachFile.getAttachUrl(pagename, target[idx], request),
+"this_image": static_url + target[idx],
 "pagename": pagename,
 "tablestyle": inner_table_style,
 "option_webnails": option_webnail,
@@ -374,8 +371,7 @@
         attachment_path = AttachFile.getAttachDir(request, self.pagename)
         command = request.form.get('do', ['none'])[0]
         target = request.form.get('target', [None])[0]
-        
-        
+
         if command == 'VS':
             web = {}
             images = request.form.get('target', [''])[0]
@@ -394,16 +390,15 @@
 
            # XXX Check that all lists have same length
             idx = images.index(target)
-            attachment_path = AttachFile.getAttachDir(request, pagename)
-
-            static_path, static_url = self.get_path_url(request, pagename, attachment_path)
 
             image_for_webnail = int(request.form.get("image_for_webnail", [0])[0])
+
             if not image_for_webnail:
-               static_url = "/%(pagename)s?action=arnica_slides&do=view&target=" % {'pagename': pagename}
-               static_url = wikiutil.escape(static_url)
-               
-            web['src'] = static_url+target #AttachFile.getAttachUrl(pagename, target, request)
+                static_url = getAttachUrl(pagename, target)
+            else:
+                static_url = AttachFile.getAttachUrl(pagename, target, request)
+
+            web['src'] = static_url
             web['title'] = target
 
             request.theme.send_title(pagename,