changeset 227:a16b7c703fd3

flag image_for_webnail mode refactored: the image becomes duplicated as webnail in the cache arena.
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Mon, 01 Sep 2008 20:51:04 +0200
parents 9faa8f0e9f86
children 4507998dcfbc
files data/plugin/action/arnica_slides.py data/plugin/parser/text_x_arnica.py
diffstat 2 files changed, 43 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/data/plugin/action/arnica_slides.py	Mon Sep 01 18:57:06 2008 +0200
+++ b/data/plugin/action/arnica_slides.py	Mon Sep 01 20:51:04 2008 +0200
@@ -196,7 +196,7 @@
     }
     return html
 
-def html_slideform(request, pagename, alias, exif_date, images, original_images, idx, image_for_webnail):
+def html_slideform(request, pagename, alias, exif_date, images, original_images, idx):
     """ html code for the slideform
 
     @param request: request object
@@ -206,19 +206,15 @@
     @param images: list of webnail image IDs (either cache keys or attachment names)
     @param original_images: list of original image attachment names (thumbnails and webnails are derived from it)
     @param idx: index position of the image
-    @param image_for_webnail: True: use attachments, False: use cache
+
     """
-    if not image_for_webnail:
-        image_url = cache.url(request, images[idx])
-        this_webnail_list = [cache.url(request, name) for name in images]
-    else:
-        image_url = AttachFile.getAttachUrl(pagename, images[idx], request)
-        this_webnail_list = [AttachFile.getAttachUrl(pagename, name, request) for name in images]
+    image_url = cache.url(request, images[idx])
+    this_webnail_list = [cache.url(request, name) 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)
-    option_webnail = option_list(image_url, pagename, images, original_images, request, image_for_webnail)
+    option_webnail = option_list(image_url, pagename, images, original_images, request)
     inner_table_style = ' style="border-style:none; margin:10px;"'
 
     html = """
@@ -272,7 +268,7 @@
     }
     return html
 
-def option_list(this_image, pagename, filenames, original_images, request, image_for_webnail):
+def option_list(this_image, pagename, filenames, original_images, request):
     """ generates the pulldown option list
 
     @param this_image: selected image on top
@@ -280,18 +276,13 @@
     @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
     options = []
     i = 0
     for filename in filenames:
-        if not image_for_webnail:
-            url = cache.url(request, filename)
-            prefix = 'Webnail:'
-        else:
-            url = AttachFile.getAttachUrl(pagename, filename, request)
-            prefix = ''
+        url = cache.url(request, filename)
+        prefix = 'Webnail:'
 
         options.append('<option%(selected)s value="%(name)s">%(prefix)s %(alias)s' % {
             "selected": (url == this_image) and ' selected' or '',
@@ -348,7 +339,6 @@
 
         all_description = request.form.get('alias', [''])[0]
         all_exif_date = request.form.get('exif_date', [''])[0]
-        image_for_webnail = request.form.get("image_for_webnail", [0])[0] == u'True'
 
         if not (target and images and all_description and all_exif_date):
             msg = _("Missing required parameters!")
@@ -378,11 +368,8 @@
             return
 
         web = {}
-        if not image_for_webnail:
-            web['src'] = cache.url(request, target)
-        else:
-            web['src'] = AttachFile.getAttachUrl(pagename, target, request)
 
+        web['src'] = cache.url(request, target)
         web['title'] = target
 
         mimetype = "text/html"
@@ -394,7 +381,7 @@
                                  html_head=html_js(request, idx))
 
         request.write(request.formatter.startContent("content"))
-        html = html_slideform(request, pagename, all_description, all_exif_date, images, original_images, idx, image_for_webnail)
+        html = html_slideform(request, pagename, all_description, all_exif_date, images, original_images, idx)
         request.write(request.formatter.rawHTML(html))
         request.write(request.formatter.endContent())
         request.write(request.theme.send_footer(pagename))
--- a/data/plugin/parser/text_x_arnica.py	Mon Sep 01 18:57:06 2008 +0200
+++ b/data/plugin/parser/text_x_arnica.py	Mon Sep 01 20:51:04 2008 +0200
@@ -226,7 +226,6 @@
         <input type="hidden" name="images" value="%(images)s">
         <input type="hidden" name="original_images" value="%(original_images)s">
         <input type="hidden" name="exif_date" value="%(exif_date)s">
-        <input type="hidden" name="image_for_webnail" value="%(image_for_webnail)s">
         <input type="image" value="submit" title="slide show" src="%(htdocs)s/arnica/img/arnica_load_slide_show.png">
     </div>
 </form>
@@ -239,7 +238,6 @@
             "style": self.td_style,
             "thumbnail_width": self.thumbnail_width,
             "description": packLine([self.description[idx]] + self.description),
-            "image_for_webnail": self.image_for_webnail,
             "exif_date": packLine([self.exif_date[idx]] + self.exif_date),
             "target": self.webnail_image[idx],
             "original_images": packLine([self.high_resolution_image[idx]] + self.high_resolution_image),
@@ -298,7 +296,6 @@
              <input type="hidden" name="images" value="%(images)s">
              <input type="hidden" name="original_images" value="%(original_images)s">
              <input type="hidden" name="exif_date" value="%(exif_date)s">
-             <input type="hidden" name="image_for_webnail" value="%(image_for_webnail)s">
              <input type="image" value="submit" title="slide show" src="%(thumbnail)s">
         </div>
     </form>
@@ -314,7 +311,6 @@
             "pagename": self.pagename,
             "description": packLine([self.description[idx]] + self.description),
             "exif_date": packLine([self.exif_date[idx]] + self.exif_date),
-            "image_for_webnail": self.image_for_webnail,
             "target": self.webnail_image[idx],
             "original_images": packLine([self.high_resolution_image[idx]] + self.high_resolution_image),
             "images": packLine([self.webnail_image[idx]] + self.webnail_image),
@@ -465,35 +461,42 @@
                 msg = _("attachment: %(filename)s not exists") % {"filename": os.path.basename(imagef)}
                 self.request.write(self.formatter.text(msg))
                 return
-
+            else:
+                # ToDo may be it is better to just copy the image to the new location
+                # currently PIL does not support exif information
+                if self.image_for_webnail:
+                        buf = StringIO.StringIO()
+                        im_obj.save(buf, image_type)
+                        buf.flush()
+                        buf.seek(0)
+                        cache.put(self.request, webnail, buf, filename=image)
            # XXX later, a unit conversion method for using other units than 'px' is needed
             if not cache.exists(self.request, webnail):
-                # ToDo check if we can make the code simpler if we handle this option similiar than the other cache files
-                if not self.image_for_webnail:
-                    try:
-                        exif = im_obj._getexif()
-                    except (AttributeError, KeyError):
-                        exif = None
+                try:
+                    exif = im_obj._getexif()
+                except (AttributeError, KeyError):
+                    exif = None
+                try:
+                    im_obj.thumbnail((int(self.webnail_width.strip('px')), int(self.webnail_width.strip('px'))), Image.ANTIALIAS)
+                except IOError:
+                    #  one reason can be that the image file is truncated
+                    return
+                if exif:
                     try:
-                        im_obj.thumbnail((int(self.webnail_width.strip('px')), int(self.webnail_width.strip('px'))), Image.ANTIALIAS)
-                    except IOError:
-                        #  one reason can be that the image file is truncated
-                        return
-                    if exif:
-                        try:
-                            process = {
-                                1: lambda x: x,
-                                2: lambda x: x.transpose(Image.FLIP_LEFT_RIGHT),
-                                3: lambda x: x.transpose(Image.ROTATE_180),
-                                4: lambda x: x.transpose(Image.FLIP_TOP_BOTTOM),
-                                5: lambda x: x.transpose(Image.ROTATE_90).transpose(Image.FLIP_TOP_BOTTOM),
-                                6: lambda x: x.transpose(Image.ROTATE_270),
-                                7: lambda x: x.transpose(Image.ROTATE_90).transpose(Image.FLIP_LEFT_RIGHT),
-                                8: lambda x: x.transpose(Image.ROTATE_90),
-                            }
-                            im_obj = process[exif[274]](im_obj)
-                        except KeyError:
-                            pass
+                        process = {
+                            1: lambda x: x,
+                            2: lambda x: x.transpose(Image.FLIP_LEFT_RIGHT),
+                            3: lambda x: x.transpose(Image.ROTATE_180),
+                            4: lambda x: x.transpose(Image.FLIP_TOP_BOTTOM),
+                            5: lambda x: x.transpose(Image.ROTATE_90).transpose(Image.FLIP_TOP_BOTTOM),
+                            6: lambda x: x.transpose(Image.ROTATE_270),
+                            7: lambda x: x.transpose(Image.ROTATE_90).transpose(Image.FLIP_LEFT_RIGHT),
+                            8: lambda x: x.transpose(Image.ROTATE_90),
+                        }
+                        im_obj = process[exif[274]](im_obj)
+                    except KeyError:
+                        pass
+
                     buf = StringIO.StringIO()
                     im_obj.save(buf, image_type)
                     buf.flush()
@@ -566,8 +569,6 @@
                                                     self.thumb_key[i], self.imgtype[i])
             if not self.album:
                 self.webnail_image = self.web_key
-                if self.image_for_webnail:
-                    self.webnail_image = self.high_resolution_image
                 text = self.html_arrange_thumbnails(i)
                 if col_count <= cols:
                     result.append(''.join(text))
@@ -586,8 +587,6 @@
                 i = self.high_resolution_image.index(album_image)
                 self.create_thumbnail_and_webnail_image(image, self.web_key[i], self.thumb_key[i], self.imgtype[i])
                 self.webnail_image = self.web_key
-                if self.image_for_webnail:
-                    self.webnail_image = self.high_resolution_image
                 text = self.html_arrange_thumbnails(i)
             except ValueError:
                 text = self.formatter.text(_("""You can't use as album image: