changeset 189:5edba1f921b7

arnica: reduce code duplication, create URLs the correct way
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 18 Jul 2008 00:45:51 +0200
parents a1a6a45edaf1
children 45fcfc007160
files data/plugin/action/arnica_slides.py
diffstat 1 files changed, 17 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/data/plugin/action/arnica_slides.py	Thu Jul 17 23:54:42 2008 +0200
+++ b/data/plugin/action/arnica_slides.py	Fri Jul 18 00:45:51 2008 +0200
@@ -203,16 +203,17 @@
     @param image_for_webnail: True: use attachments, False: use cache
     """
     if not image_for_webnail:
-        url = cache.url(request, "")
+        image_url = cache.url(request, images[idx])
+        this_webnail_list = [cache.url(request, name) for name in images]
     else:
-        url = AttachFile.getAttachUrl(pagename, "", request)
+        image_url = AttachFile.getAttachUrl(pagename, images[idx], request)
+        this_webnail_list = [AttachFile.getAttachUrl(pagename, name, request) for name in images]
+
+    this_webnail_list = "".join(["%s|" % url for url in this_webnail_list])
 
     link_to_image = AttachFile.getAttachUrl(pagename, original_images[idx], request)
-
-    image_url = "%s%s" % (url, images[idx])
     option_webnail = option_list(image_url, pagename, images, original_images, request, image_for_webnail)
     inner_table_style = ' style="border-style:none; margin:10px;"'
-    this_webnail_list = "".join(["%s%s|" % (url, name) for name in images])
 
     html = """
 <div class="arnica-slides">
@@ -266,20 +267,20 @@
     return html
 
 
-def option_list(this_image, pagename, text, original_images, request, image_for_webnail):
+def option_list(this_image, pagename, filenames, original_images, request, image_for_webnail):
     """ generates the pulldown option list
 
     @param this_image: selected image on top
     @param pagename: pagename of attachments
-    @param text: list of filenames
+    @param filenames: list of filenames
     @param original_images: list of original image attachment names (thumbnails and webnails are derived from it)
     @param request: request object
     @param image_for_webnail: True: use attachments, False: use cache
     """
     # TODO: original image needs to be sent to the action and used instead of the alias
-    txt = ''
+    options = []
     i = 0
-    for filename in text:
+    for filename in filenames:
         if not image_for_webnail:
             url = cache.url(request, filename)
             prefix = 'Webnail:'
@@ -287,18 +288,14 @@
             url = AttachFile.getAttachUrl(pagename, filename, request)
             prefix = ''
 
-        if url == this_image:
-            txt += '<option selected value="%(name)s">%(prefix)s %(alias)s' % {
-                    "prefix": prefix,
-                    "name": this_image,
-                    "alias": original_images[i]}
-        else:
-            txt += '<option value="%(name)s">%(prefix)s %(alias)s' % {
-                    "prefix": prefix,
-                    "name": this_image,
-                    "alias": original_images[i]}
+        options.append('<option%s value="%(name)s">%(prefix)s %(alias)s' % {
+            "selected": (url == this_image) and ' selected' or '',
+            "name": this_image,
+            "prefix": prefix,
+            "alias": original_images[i],
+        })
         i += 1
-    return txt
+    return ''.join(options)
 
 
 class arnica_slides(ActionBase):