Exemple #1
0
def _upload_image(user, image_file):
    """ """
    error_code = None
    message = None
    up = UploadAvatar()
    up.upload(network_object=image_file, user=user)
    user['image'] = up.names_list
    model.users.update(user_id=user["_id"], image=user['image'])
    message = ('users_msg', 'success_update_user')
    return error_code, message
Exemple #2
0
def _upload_image(user, image_file):
    """ """
    error_code = None
    message = None
    up = UploadAvatar()
    up.upload(network_object=image_file, user=user)
    user['image'] = up.names_list
    model.users.update(user_id=user["_id"], image=user['image'])
    message = ('users_msg', 'success_update_user')
    return error_code, message
Exemple #3
0
    def __upload_avatar(self):
        """ Upload the avatar """
        form = self.params
        self.user['image_tmp'] = form['image_uploaded']

        if self.message or not self.user['image_tmp']:
            return False

        file_name = os.path.join(UP_AVATARS_TMP_FOLDER, self.user['image_tmp'])
        if os.path.exists(file_name):
            with open(file_name) as image:
                up = UploadAvatar()
                up.upload(image=image, user=self.user)
                self.list_images = up.names_list
                return True
        self.message = g.users_msg('error_upload_2')
        return False
Exemple #4
0
def upload_avatar(name=None):
    """
    """
    extension = get_extension(name)
    up = UploadAvatar()
    path_image = up.ajax_upload(UP_AVATARS_TMP_FOLDER, extension)
    if up.allowed_file() == False:
        success = False
        message = g.users_msg('error_upload_1')
    else:
        up.thumb(AVATAR_IMAGE_SIZE['large'], os.path.join(UP_AVATARS_TMP_FOLDER, path_image))
        if path_image:
            success = True
            message = path_image
    if success:
        return dict(success=True, message=message)
    return dict(success=False, errors=[{ "message": message }])
Exemple #5
0
    def __upload_avatar(self):
        """ Upload the avatar """
        form = self.params
        self.user['image_tmp'] = form['image_uploaded']

        if self.message or not self.user['image_tmp']:
            return False

        file_name = os.path.join(UP_AVATARS_TMP_FOLDER, self.user['image_tmp'])
        if os.path.exists(file_name):
            with open(file_name) as image:
                up = UploadAvatar()
                up.upload(image=image, user=self.user)
                self.list_images = up.names_list
                return True
        self.message = g.users_msg('error_upload_2')
        return False
Exemple #6
0
def upload_avatar(name=None):
    """
    """
    extension = get_extension(name)
    up = UploadAvatar()
    path_image = up.ajax_upload(UP_AVATARS_TMP_FOLDER, extension)
    if up.allowed_file() == False:
        success = False
        message = g.users_msg('error_upload_1')
    else:
        up.thumb(AVATAR_IMAGE_SIZE['large'],
                 os.path.join(UP_AVATARS_TMP_FOLDER, path_image))
        if path_image:
            success = True
            message = path_image
    if success:
        return dict(success=True, message=message)
    return dict(success=False, errors=[{"message": message}])