コード例 #1
0
ファイル: uploader.py プロジェクト: dongyi/feed-of-fate
def upload_ad_creative(image, max_size=MAX_AD_SIZE):
    resolution = ''
    errors = set()
    image = coerce_image(image)
    if image is None or isinstance(image, basestring):
        errors.add('image')

    f = image.file
    if get_filesize(f) > max_size:
        errors.add('image_size')

    image_upload = get_upload(image, max_size=max_size)
    if image_upload:
        resolution, swf_url = image_upload
    else:
        errors.add('image')

    if errors:
        return errors, None

    if resolution:
        rmatch = VALID_RESOLUTION.match(resolution)
        width, height = rmatch.groups()

    return errors, (swf_url, width, height)
コード例 #2
0
ファイル: uploader.py プロジェクト: dongyi/feed-of-fate
def get_field_data(field, max_size=MAX_GAME_UPLOAD_SIZE):
    if field is None or isinstance(field, basestring):
        return ""
    f = field.file
    filesize = get_filesize(f)
    if filesize > max_size:
        log.info('get_game_upload %d > %d for %r', filesize, max_size, f.filename)
        return None
    return f.read()
コード例 #3
0
ファイル: uploader.py プロジェクト: dongyi/feed-of-fate
def get_image_upload(field, path, max_size=MAX_UPLOAD_SIZE):
    if field is None or isinstance(field, basestring):
        return None
    f = field.file
    if get_filesize(f) > max_size:
        return None
    try:
        srvurl = get_srvurl(None)
        url = post_multipart(srvurl,
            files=[('file_upload', field.filename, f.read())],
            fields=[('path', path)])
    except IOError:
        return None
    return url.split(' ')[1].replace('cdn', 'thumbs', 1)
コード例 #4
0
ファイル: uploader.py プロジェクト: dongyi/feed-of-fate
def get_thumbnail_upload(field, path, size=(100, 100), max_size=MAX_UPLOAD_SIZE):
    """
    TODO: What does this do?
    """
    if field is None or isinstance(field, basestring):
        return None
    f = field.file
    if get_filesize(f) > max_size:
        return None
    try:
        url = upload_thumbnail(field.filename,
            f.read(), size=size, path=path)
    except IOError:
        return None
    return url.replace('cdn', 'thumbs', 1)
コード例 #5
0
ファイル: uploader.py プロジェクト: dongyi/feed-of-fate
def get_upload(field, original=False, max_size=MAX_UPLOAD_SIZE, add_actions=True):
    """
    TODO: Document
    """
    if field is None or isinstance(field, basestring):
        return None
    f = field.file
    if get_filesize(f) > max_size:
        return None
    try:
        resolution, url = upload_image(field.filename,
            f.read(), original=original, add_actions=add_actions)
    except IOError:
        return None
    return resolution, url.replace('http://s3.', 'http://cdn.')
コード例 #6
0
ファイル: uploader.py プロジェクト: dongyi/feed-of-fate
def upload_game_swf(field, game_slug, max_size=MAX_GAME_UPLOAD_SIZE):
    """
    TODO: Document
    """
    if field is None or isinstance(field, basestring):
        return None
    f = field.file
    filesize = get_filesize(f)
    if filesize > max_size:
        log.info('upload_field max_size exceeded (%d > %d) for %r',
                 filesize, max_size, f.filename)
        return None
    path = game_slug
    try:
        urls = upload_files(field.filename, f.read(), path=path)
    except IOError:
        return None
    return urls
コード例 #7
0
ファイル: uploader.py プロジェクト: dongyi/feed-of-fate
def upload_video_ad(field, ad_tag, max_size=MAX_VIDEO_AD_SIZE):
    f = field.file
    if get_filesize(f) > max_size:
        return None
    return upload_raw_file(field.filename, f.read(), 'v/%s' % (ad_tag,))