view 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
line wrap: on
line source

import mimetypes
from decoupage.formatters import All

class Images(object):
    """list of images"""

    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

    def __call__(self, request, data):
        data['width'] = self.width
        data['height'] = self.height

        # filter out non-images
        _files = []
        for f in data['files']:
            mimetype = mimetypes.guess_type(f['name'])[0]
            if mimetype and mimetype.split('/')[0] == 'image':
                _files.append(f)
        data['files'] = _files