Exemple #1
0
def resource_pre_create_actions(resource_type,
                                resource_title,
                                page_redirect_url_key,
                                files=(),
                                metadata=None,
                                requesting_user=None,
                                **kwargs):
    from .resource import check_resource_type
    from hs_core.views.utils import validate_metadata

    if not resource_title:
        resource_title = 'Untitled resource'
    else:
        resource_title = resource_title.strip()
        if len(resource_title) == 0:
            resource_title = 'Untitled resource'

    resource_cls = check_resource_type(resource_type)
    if len(files) > 0:
        size = validate_resource_file_size(files)
        validate_resource_file_count(resource_cls, files)
        validate_resource_file_type(resource_cls, files)
        # validate it is within quota hard limit
        validate_user_quota(requesting_user, size)

    if not metadata:
        metadata = []
    else:
        validate_metadata(metadata, resource_type)

    page_url_dict = {}
    # receivers need to change the values of this dict if file validation fails
    file_validation_dict = {
        'are_files_valid': True,
        'message': 'Files are valid'
    }

    # Send pre-create resource signal - let any other app populate the empty metadata list object
    # also pass title to other apps, and give other apps a chance to populate page_redirect_url
    # if they want to redirect to their own page for resource creation rather than use core
    # resource creation code
    pre_create_resource.send(sender=resource_cls,
                             metadata=metadata,
                             files=files,
                             title=resource_title,
                             url_key=page_redirect_url_key,
                             page_url_dict=page_url_dict,
                             validate_files=file_validation_dict,
                             user=requesting_user,
                             **kwargs)

    if len(files) > 0:
        check_file_dict_for_error(file_validation_dict)

    return page_url_dict, resource_title, metadata
Exemple #2
0
def resource_pre_create_actions(resource_type, resource_title, page_redirect_url_key,
                                files=(), source_names=[], metadata=None,
                                requesting_user=None, **kwargs):
    from.resource import check_resource_type
    from hs_core.views.utils import validate_metadata

    if __debug__:
        assert(isinstance(source_names, list))

    if not resource_title:
        resource_title = 'Untitled resource'
    else:
        resource_title = resource_title.strip()
        if len(resource_title) == 0:
            resource_title = 'Untitled resource'

    resource_cls = check_resource_type(resource_type)
    if len(files) > 0:
        size = validate_resource_file_size(files)
        validate_resource_file_count(resource_cls, files)
        validate_resource_file_type(resource_cls, files)
        # validate it is within quota hard limit
        validate_user_quota(requesting_user, size)

    if not metadata:
        metadata = []
    else:
        validate_metadata(metadata, resource_type)

    page_url_dict = {}
    # this is needed since raster and feature resource types allows to upload a zip file,
    # then replace zip file with exploded files. If the zip file is loaded from hydroshare
    # federation zone, the original zip file encoded in source_names gets deleted
    # in this case and fed_res_path is used to keep the federation path, so that the resource
    # will be stored in the federated zone rather than the hydroshare zone
    fed_res_path = []
    # receivers need to change the values of this dict if file validation fails
    file_validation_dict = {'are_files_valid': True, 'message': 'Files are valid'}

    # Send pre-create resource signal - let any other app populate the empty metadata list object
    # also pass title to other apps, and give other apps a chance to populate page_redirect_url
    # if they want to redirect to their own page for resource creation rather than use core
    # resource creation code
    pre_create_resource.send(sender=resource_cls, metadata=metadata, files=files,
                             title=resource_title,
                             url_key=page_redirect_url_key, page_url_dict=page_url_dict,
                             validate_files=file_validation_dict,
                             source_names=source_names,
                             user=requesting_user, fed_res_path=fed_res_path, **kwargs)

    if len(files) > 0:
        check_file_dict_for_error(file_validation_dict)

    return page_url_dict, resource_title,  metadata, fed_res_path
Exemple #3
0
def resource_pre_create_actions(resource_type,
                                resource_title,
                                page_redirect_url_key,
                                files=(),
                                fed_res_file_names='',
                                metadata=None,
                                requesting_user=None,
                                **kwargs):
    from .resource import check_resource_type
    from hs_core.views.utils import validate_metadata

    if not resource_title:
        resource_title = 'Untitled resource'
    else:
        resource_title = resource_title.strip()
        if len(resource_title) == 0:
            resource_title = 'Untitled resource'

    resource_cls = check_resource_type(resource_type)
    if len(files) > 0:
        validate_resource_file_size(files)
        validate_resource_file_count(resource_cls, files)
        validate_resource_file_type(resource_cls, files)

    if not metadata:
        metadata = []
    else:
        validate_metadata(metadata, resource_type)

    page_url_dict = {}
    # this is needed since raster and feature resource types allows to upload a zip file,
    # then replace zip file with exploded files. If the zip file is loaded from hydroshare
    # federation zone, the original zip file encoded in fed_res_file_names gets deleted
    # in this case and fed_res_path is used to keep the federation path, so that the resource
    # will be stored in the federated zone rather than the hydroshare zone
    fed_res_path = []
    # receivers need to change the values of this dict if file validation fails
    file_validation_dict = {
        'are_files_valid': True,
        'message': 'Files are valid'
    }

    # Send pre-create resource signal - let any other app populate the empty metadata list object
    # also pass title to other apps, and give other apps a chance to populate page_redirect_url
    # if they want to redirect to their own page for resource creation rather than use core
    # resource creation code
    pre_create_resource.send(sender=resource_cls,
                             metadata=metadata,
                             files=files,
                             title=resource_title,
                             url_key=page_redirect_url_key,
                             page_url_dict=page_url_dict,
                             validate_files=file_validation_dict,
                             fed_res_file_names=fed_res_file_names,
                             user=requesting_user,
                             fed_res_path=fed_res_path,
                             **kwargs)

    if len(files) > 0:
        check_file_dict_for_error(file_validation_dict)

    return page_url_dict, resource_title, metadata, fed_res_path