annotate montage/formatters.py @ 2:4b8aa9b0a45b

montage actually does something now
author k0s <k0scist@gmail.com>
date Fri, 25 Dec 2009 03:59:26 -0500
parents b7348ffe5b46
children d60a5ffbf4f4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
4b8aa9b0a45b montage actually does something now
k0s <k0scist@gmail.com>
parents: 0
diff changeset
1 import mimetypes
0
b7348ffe5b46 initial import of montage
k0s <k0scist@gmail.com>
parents:
diff changeset
2 from decoupage.formatters import All
b7348ffe5b46 initial import of montage
k0s <k0scist@gmail.com>
parents:
diff changeset
3
2
4b8aa9b0a45b montage actually does something now
k0s <k0scist@gmail.com>
parents: 0
diff changeset
4 class Images(object):
4b8aa9b0a45b montage actually does something now
k0s <k0scist@gmail.com>
parents: 0
diff changeset
5 """list of images"""
0
b7348ffe5b46 initial import of montage
k0s <k0scist@gmail.com>
parents:
diff changeset
6
b7348ffe5b46 initial import of montage
k0s <k0scist@gmail.com>
parents:
diff changeset
7 def __init__(self, arg):
2
4b8aa9b0a45b montage actually does something now
k0s <k0scist@gmail.com>
parents: 0
diff changeset
8 if 'x' in arg:
4b8aa9b0a45b montage actually does something now
k0s <k0scist@gmail.com>
parents: 0
diff changeset
9 width, height = [ i.strip() for i in arg.split('x', 1) ]
4b8aa9b0a45b montage actually does something now
k0s <k0scist@gmail.com>
parents: 0
diff changeset
10 self.width = width or None
4b8aa9b0a45b montage actually does something now
k0s <k0scist@gmail.com>
parents: 0
diff changeset
11 self.height = height or None
4b8aa9b0a45b montage actually does something now
k0s <k0scist@gmail.com>
parents: 0
diff changeset
12 else:
4b8aa9b0a45b montage actually does something now
k0s <k0scist@gmail.com>
parents: 0
diff changeset
13 self.width = self.height = None
0
b7348ffe5b46 initial import of montage
k0s <k0scist@gmail.com>
parents:
diff changeset
14
b7348ffe5b46 initial import of montage
k0s <k0scist@gmail.com>
parents:
diff changeset
15 def __call__(self, request, data):
2
4b8aa9b0a45b montage actually does something now
k0s <k0scist@gmail.com>
parents: 0
diff changeset
16 data['width'] = self.width
4b8aa9b0a45b montage actually does something now
k0s <k0scist@gmail.com>
parents: 0
diff changeset
17 data['height'] = self.height
4b8aa9b0a45b montage actually does something now
k0s <k0scist@gmail.com>
parents: 0
diff changeset
18
4b8aa9b0a45b montage actually does something now
k0s <k0scist@gmail.com>
parents: 0
diff changeset
19 # filter out non-images
4b8aa9b0a45b montage actually does something now
k0s <k0scist@gmail.com>
parents: 0
diff changeset
20 _files = []
4b8aa9b0a45b montage actually does something now
k0s <k0scist@gmail.com>
parents: 0
diff changeset
21 for f in data['files']:
4b8aa9b0a45b montage actually does something now
k0s <k0scist@gmail.com>
parents: 0
diff changeset
22 mimetype = mimetypes.guess_type(f['name'])[0]
4b8aa9b0a45b montage actually does something now
k0s <k0scist@gmail.com>
parents: 0
diff changeset
23 if mimetype and mimetype.split('/')[0] == 'image':
4b8aa9b0a45b montage actually does something now
k0s <k0scist@gmail.com>
parents: 0
diff changeset
24 _files.append(f)
4b8aa9b0a45b montage actually does something now
k0s <k0scist@gmail.com>
parents: 0
diff changeset
25 data['files'] = _files
4b8aa9b0a45b montage actually does something now
k0s <k0scist@gmail.com>
parents: 0
diff changeset
26