Exemplo n.º 1
0
def room_photo(roomID):
    cache_key = 'photo-{}'.format(roomID)
    photo_data = _cache.get(cache_key)

    if photo_data == '*':
        return _redirect_no_photo()
    elif photo_data is None:
        photo = Photo.find_first(Room.id == roomID, _join=Photo.room)
        if photo is None:
            _cache.set(cache_key, '*')
            return _redirect_no_photo()
        _cache.set(cache_key, photo.data)

    io = BytesIO(photo_data)
    return send_file('photo.jpg', io, 'image/jpeg', no_cache=False)
Exemplo n.º 2
0
def room_photo(roomID):
    cache_key = 'photo-{}'.format(roomID)
    photo_data = _cache.get(cache_key)

    if photo_data == '*':
        return _redirect_no_photo()
    elif photo_data is None:
        photo = Photo.find_first(Room.id == roomID, _join=Photo.room)
        if photo is None:
            _cache.set(cache_key, '*')
            return _redirect_no_photo()
        _cache.set(cache_key, photo.data)

    io = BytesIO(photo_data)
    return send_file('photo.jpg', io, 'image/jpeg', no_cache=False)
Exemplo n.º 3
0
def room_photo(roomID, size, **kw):
    cache_key = 'photo-{}-{}'.format(roomID, size)
    photo_data = _cache.get(cache_key)

    if photo_data == '*':
        return _redirect_no_photo(size)
    elif photo_data is None:
        photo = Photo.find_first(Room.id == roomID, _join=Photo.room)
        if photo is None:
            _cache.set(cache_key, '*')
            return _redirect_no_photo(size)
        photo_data = photo.thumbnail if size == 'small' else photo.data
        _cache.set(cache_key, photo_data)

    io = BytesIO(photo_data)
    return send_file('photo-{}.jpg'.format(size), io, 'image/jpeg', no_cache=False)