コード例 #1
0
def resource_file_add_process(resource,
                              files,
                              user,
                              extract_metadata=False,
                              fed_res_file_names='',
                              **kwargs):

    from .resource import add_resource_files
    folder = kwargs.pop('folder', None)
    resource_file_objects = add_resource_files(
        resource.short_id,
        *files,
        folder=folder,
        fed_res_file_names=fed_res_file_names,
        fed_zone_home_path=resource.resource_federation_path)

    # receivers need to change the values of this dict if file validation fails
    # in case of file validation failure it is assumed the resource type also deleted the file
    file_validation_dict = {
        'are_files_valid': True,
        'message': 'Files are valid'
    }
    post_add_files_to_resource.send(sender=resource.__class__,
                                    files=files,
                                    fed_res_file_names=fed_res_file_names,
                                    resource=resource,
                                    user=user,
                                    validate_files=file_validation_dict,
                                    extract_metadata=extract_metadata,
                                    **kwargs)

    check_file_dict_for_error(file_validation_dict)

    resource_modified(resource, user, overwrite_bag=False)
    return resource_file_objects
コード例 #2
0
ファイル: utils.py プロジェクト: hydroshare/hydroshare
def resource_file_add_process(resource, files, user, extract_metadata=False,
                              source_names=[], **kwargs):

    from .resource import add_resource_files
    if __debug__:
        assert(isinstance(source_names, list))
    folder = kwargs.pop('folder', None)
    full_paths = kwargs.pop('full_paths', {})
    auto_aggregate = kwargs.pop('auto_aggregate', True)
    resource_file_objects = add_resource_files(resource.short_id, *files, folder=folder,
                                               source_names=source_names, full_paths=full_paths,
                                               auto_aggregate=auto_aggregate)

    # receivers need to change the values of this dict if file validation fails
    # in case of file validation failure it is assumed the resource type also deleted the file
    file_validation_dict = {'are_files_valid': True, 'message': 'Files are valid'}
    post_add_files_to_resource.send(sender=resource.__class__, files=files,
                                    source_names=source_names,
                                    resource=resource, user=user,
                                    validate_files=file_validation_dict,
                                    extract_metadata=extract_metadata,
                                    res_files=resource_file_objects, **kwargs)

    check_file_dict_for_error(file_validation_dict)

    resource_modified(resource, user, overwrite_bag=False)
    return resource_file_objects
コード例 #3
0
def resource_file_add_process(resource,
                              files,
                              user,
                              extract_metadata=False,
                              source_names=[],
                              source_sizes=[],
                              is_file_reference=False,
                              **kwargs):

    from .resource import add_resource_files
    if __debug__:
        assert (isinstance(source_names, list))
    folder = kwargs.pop('folder', None)
    resource_file_objects = add_resource_files(
        resource.short_id,
        *files,
        folder=folder,
        source_names=source_names,
        source_sizes=source_sizes,
        is_file_reference=is_file_reference)

    # receivers need to change the values of this dict if file validation fails
    # in case of file validation failure it is assumed the resource type also deleted the file
    file_validation_dict = {
        'are_files_valid': True,
        'message': 'Files are valid'
    }
    post_add_files_to_resource.send(sender=resource.__class__,
                                    files=files,
                                    source_names=source_names,
                                    resource=resource,
                                    user=user,
                                    validate_files=file_validation_dict,
                                    extract_metadata=extract_metadata,
                                    res_files=resource_file_objects,
                                    **kwargs)

    check_file_dict_for_error(file_validation_dict)

    resource_modified(resource, user, overwrite_bag=False)
    return resource_file_objects