changeset 5:d60a5ffbf4f4

* include a new template to display images in a grid * refactor Images formatter * stub for thumbnails
author k0s <k0scist@gmail.com>
date Fri, 25 Dec 2009 17:22:01 -0500
parents 75b19560f517
children 439a417c857e
files montage/formatters.py montage/templates/grid.html montage/templates/strip.html
diffstat 3 files changed, 63 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/montage/formatters.py	Fri Dec 25 04:21:30 2009 -0500
+++ b/montage/formatters.py	Fri Dec 25 17:22:01 2009 -0500
@@ -1,18 +1,23 @@
 import mimetypes
-from decoupage.formatters import All
+from decoupage.formatters import FormatterBase
 
-class Images(object):
-    """list of images"""
+class Images(FormatterBase):
+    """display images with thumbnails"""
+
+    defaults = { 'size': 'x',
+                 'columns': None }
 
     def __init__(self, arg):
-        if 'x' in arg:
-            width, height = [ i.strip() for i in arg.split('x', 1) ]
-            self.width = width or None
-            self.height = height or None
-        else:
-            self.width = self.height = None
+        FormatterBase.__init__(self, arg)
 
+        # get image size for display
+        width, height = [ i.strip() for i in self.size.split('x', 1) ]
+        self.width = width or None
+        self.height = height or None
+        
     def __call__(self, request, data):
+
+        # add width + height data
         data['width'] = self.width
         data['height'] = self.height
 
@@ -22,5 +27,18 @@
             mimetype = mimetypes.guess_type(f['name'])[0]
             if mimetype and mimetype.split('/')[0] == 'image':
                 _files.append(f)
+                f['link'] = f['path']
         data['files'] = _files
+        
+        # columns for grid display
+        if self.columns is None:
+            data['columns'] = len(data['files'])
+        else:
+            data['columns'] = int(self.columns)
 
+        # thumbnails 
+        if 'thumbnails' not in self.args:
+            return
+        for f in data['files']:
+            raise NotImplementedError
+            import pdb; pdb.set_trace()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/montage/templates/grid.html	Fri Dec 25 17:22:01 2009 -0500
@@ -0,0 +1,32 @@
+<!DOCTYPE html
+    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+      xmlns:py="http://genshi.edgewall.org/"
+      xmlns:xi="http://www.w3.org/2001/XInclude">
+  <head>
+    <title>${title or path}</title>
+  </head>
+  <body>
+    <center>
+    <table>
+      <tr py:for="row in range(len(files)/columns)">
+        <td py:for="col in range(columns)" py:with="image = files[row*columns + col]">
+          <center>
+            <img src="${image['path']}" width="${width or None}" height="${height or None}"/><br/>
+            ${image.get('title', image['description'])}            
+          </center>
+        </td>
+      </tr>
+      <tr py:if="len(files) % columns" py:with="row = len(files) / columns">
+        <td py:for="col in range(columns)" py:with="image = files[row*columns + col]">
+          <center>
+            <img src="${image['path']}" width="${width or None}" height="${height or None}"/><br/>
+            ${image.get('title', image['description'])}            
+          </center>
+        </td>        
+      </tr>
+    </table>
+    </center>
+  </body>
+</html>
--- a/montage/templates/strip.html	Fri Dec 25 04:21:30 2009 -0500
+++ b/montage/templates/strip.html	Fri Dec 25 17:22:01 2009 -0500
@@ -10,7 +10,10 @@
   <body>
     <py:for each="index, image in enumerate(files)">
       <div>
-        <img src="${image['path']}" width="${width or None}" height="${height or None}"/><br/>
+        <a href="${image['link']}">
+          <img src="${image['path']}" width="${width or None}" height="${height or None}"/>
+        </a>
+        <br/>
         ${image.get('title', image['description'])}
       </div>
       <hr width="${width}px" py:if="index != len(files) - 1"/>