Exemplo n.º 1
0
def get_avatar(name):
    avatar = Avatar.objects(username=re.compile(name, re.IGNORECASE)).first()
    if avatar is None or avatar.image is None:
        return send_file(open('blueprints/avatar/char_face.png', 'r'), mimetype='image/png',
                         cache_timeout=3600 * 24 * 30, add_etags=False)
    else:
        if not avatar.last_modified or not request.if_modified_since or avatar.last_modified > request.if_modified_since:
            image = StringIO.StringIO(avatar.image.read())
            image.seek(0)
            response = send_file(image, mimetype='image/png')
            response.last_modified = avatar.last_modified
            response.expires = None
            return response
        else:
            return flask.Response(status=304)
Exemplo n.º 2
0
def get_avatar(name):
    avatar = Avatar.objects(username=re.compile(name, re.IGNORECASE)).first()
    if avatar is None or avatar.image is None:
        return send_file(open('blueprints/avatar/char_face.png', 'r'),
                         mimetype='image/png',
                         cache_timeout=3600 * 24 * 30,
                         add_etags=False)
    else:
        if not avatar.last_modified or not request.if_modified_since or avatar.last_modified > request.if_modified_since:
            image = StringIO.StringIO(avatar.image.read())
            image.seek(0)
            response = send_file(image, mimetype='image/png')
            response.last_modified = avatar.last_modified
            response.expires = None
            return response
        else:
            return flask.Response(status=304)
Exemplo n.º 3
0
def set_avatar(name, image):
    if not image:
        return False

    entry = Avatar.objects(username=name).first()
    try:
        if entry:
            entry.image.replace(image)
            entry.last_modified = datetime.utcnow().replace(microsecond=0)
            entry.save()
        else:
            entry = Avatar(username=name)
            entry.image.put(image)
            entry.save()
    except mongoengine.ValidationError:
        return False

    return True
Exemplo n.º 4
0
def set_avatar(name, image):
    if not image:
        return False

    entry = Avatar.objects(username=name).first()
    try:
        if entry:
            entry.image.replace(image)
            entry.last_modified = datetime.utcnow().replace(microsecond=0)
            entry.save()
        else:
            entry = Avatar(username=name)
            entry.image.put(image)
            entry.save()
    except mongoengine.ValidationError:
        return False

    return True