comparison montage/formatters.py @ 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 4b8aa9b0a45b
children 93af41dcff3a
comparison
equal deleted inserted replaced
4:75b19560f517 5:d60a5ffbf4f4
1 import mimetypes 1 import mimetypes
2 from decoupage.formatters import All 2 from decoupage.formatters import FormatterBase
3 3
4 class Images(object): 4 class Images(FormatterBase):
5 """list of images""" 5 """display images with thumbnails"""
6
7 defaults = { 'size': 'x',
8 'columns': None }
6 9
7 def __init__(self, arg): 10 def __init__(self, arg):
8 if 'x' in arg: 11 FormatterBase.__init__(self, arg)
9 width, height = [ i.strip() for i in arg.split('x', 1) ]
10 self.width = width or None
11 self.height = height or None
12 else:
13 self.width = self.height = None
14 12
13 # get image size for display
14 width, height = [ i.strip() for i in self.size.split('x', 1) ]
15 self.width = width or None
16 self.height = height or None
17
15 def __call__(self, request, data): 18 def __call__(self, request, data):
19
20 # add width + height data
16 data['width'] = self.width 21 data['width'] = self.width
17 data['height'] = self.height 22 data['height'] = self.height
18 23
19 # filter out non-images 24 # filter out non-images
20 _files = [] 25 _files = []
21 for f in data['files']: 26 for f in data['files']:
22 mimetype = mimetypes.guess_type(f['name'])[0] 27 mimetype = mimetypes.guess_type(f['name'])[0]
23 if mimetype and mimetype.split('/')[0] == 'image': 28 if mimetype and mimetype.split('/')[0] == 'image':
24 _files.append(f) 29 _files.append(f)
30 f['link'] = f['path']
25 data['files'] = _files 31 data['files'] = _files
32
33 # columns for grid display
34 if self.columns is None:
35 data['columns'] = len(data['files'])
36 else:
37 data['columns'] = int(self.columns)
26 38
39 # thumbnails
40 if 'thumbnails' not in self.args:
41 return
42 for f in data['files']:
43 raise NotImplementedError
44 import pdb; pdb.set_trace()