Exemple #1
0
 def post(self, request, *args, **kwargs):
     user = request.user
     from corelib.utils.request_params import generate_upload_images
     image_files = generate_upload_images(request)
     if not image_files:
         return Response({})
     urls = ImageStorage.gen_urls(image_files[0], str(user.id))
     return Response({KEY_URL: urls})
Exemple #2
0
 def create_by_source_info(cls, source_uid, source, user_info={}):
     now = datetime.datetime.utcnow()
     #create default icon
     icon_url = user_info.get(KEY_AVATAR)
     icon_url = ImageStorage.generate_default_url(icon_url)
     user_info[KEY_AVATAR] = icon_url
     user_info[KEY_AVATAR] = FEMALE if int(user_info.get(KEY_GENDER, FEMALE)) not in [FEMALE, MALE] else int(user_info.get(KEY_GENDER, FEMALE))
     try:
         user = cls.objects.create(source_uid=source_uid, source=source, create_time=now, **user_info)
     except NotUniqueError as e:
         raise UserHasCreated
     return user
Exemple #3
0
def download_images(images, article_id):
    requests = [grequests.get(image) for image in images]
    responses = grequests.map(requests)
    data = []
    for image, rsp in izip(images, responses):
        if not rsp:
            urls = {'url': image}
        else:
            image_file = VirtualImageFile(rsp.content, rsp.headers.get('content-type', ''), image)
            urls = ImageStorage.gen_urls(image_file, str(article_id), conn_pool=pool)
            urls.update({'source': image})
        data.append(urls)
    return data