Ejemplo n.º 1
0
def handle_upload(uploaded_file):
    errors = []
    ext = '.%s' % get_ext(uploaded_file.content_type)
    tmp = open(os.path.join(_settings.AVATARS_DIR, 'tmp',
                            get_random_filename(suffix=ext)), 'w+b')
    try:
        tmp.write(uploaded_file.read(_settings.MAX_AVATAR_SIZE + 100))
        if len(open(tmp.name, 'r').read()) > _settings.MAX_AVATAR_SIZE:
            errors.append(_(u'File size too big.')) # FIXME: Intentar sacar de acá
            os.remove(tmp.name)
    except Exception, e:
        errors.append(_(u'Unknown error occurred.')) # FIXME: Intentar sacar de acá
Ejemplo n.º 2
0
def retrieve_url(url):
    import urllib2

    errors = []
    ext = '.%s' % get_ext(url, True)
    tmp = open(os.path.join(_settings.AVATARS_DIR, 'tmp',
                            get_random_filename(suffix=ext)), 'w+b')
    try:
        headers = {'User-Agent': settings.VALIDATOR_USER_AGENT}
        request = urllib2.Request(url, headers=headers)
        # for h in urllib2.urlopen(request).info().headers: print h.strip()
        tmp.write(urllib2.urlopen(request).read(
            _settings.MAX_AVATAR_SIZE + 100))
        if len(open(tmp.name, 'r').read()) > _settings.MAX_AVATAR_SIZE:
            # FIXME:
            # FIXME: Habrá manera de sacar esta traducción de acá?
            errors.append(_(u'File size too big.')) # FIXME: Intentar sacar de acá
            os.remove(tmp.name)
    except Exception, e:
        print e
        errors.append(_(u'Unknown error occurred.')) # FIXME: Intentar sacar de acá