2
|
1 import mimetypes
|
0
|
2 from decoupage.formatters import All
|
|
3
|
2
|
4 class Images(object):
|
|
5 """list of images"""
|
0
|
6
|
|
7 def __init__(self, arg):
|
2
|
8 if 'x' in 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
|
0
|
14
|
|
15 def __call__(self, request, data):
|
2
|
16 data['width'] = self.width
|
|
17 data['height'] = self.height
|
|
18
|
|
19 # filter out non-images
|
|
20 _files = []
|
|
21 for f in data['files']:
|
|
22 mimetype = mimetypes.guess_type(f['name'])[0]
|
|
23 if mimetype and mimetype.split('/')[0] == 'image':
|
|
24 _files.append(f)
|
|
25 data['files'] = _files
|
|
26
|