コード例 #1
0
ファイル: __init__.py プロジェクト: z010155/Houdini-Panel
def getAvatar(id):
    # I edited some parts of this and made it more comprehensible because this dote ...

    # pretty self explanatory
    AVAILABLE_SIZES = [60, 88, 95, 120, 300, 600]

    # Again and again, this is the user's database model
    user = session.query(User).filter_by(ID=id).first()

    # By default the size is 120 if it's not specified in the URL (cp?size=integer)
    size = 120
    try:
        if "size" in request.args:
            size = int(request.args.get("size"))
            size = size if size in AVAILABLE_SIZES else 120
    except KeyError:
        pass

    details = [
        user.Photo, user.Color, user.Head, user.Face, user.Neck, user.Body,
        user.Hand, user.Feet, user.Flag
    ]
    if details is None:
        return abort(404)

    items = Avatar.initializeImage(list(map(int, details)), size)

    return send_file(Avatar.buildAvatar(items), mimetype='image/png')