예제 #1
0
def package_show(context, data_dict):
    class DatasetType:
        (specific_version, latest_version, unversioned) = range(3)

    # The parent dataset is private so it doesn't appear in the lists
    # but we want to override the authentication checks so we can
    # access the child datasets that represent the different versions
    ignore_auth = context.get('ignore_auth')
    context['ignore_auth'] = True

    # Get the dataset we actually asked for
    requested_dataset = ckan_package_show(context, data_dict)

    version_to_display = requested_dataset

    parent_names = _get_parent_dataset_names(
        _get_context(context), requested_dataset['id'])

    if len(parent_names) > 0:
        base_name = parent_names[0]
        dataset_type = DatasetType.specific_version
        all_version_names = _get_child_dataset_names(
            _get_context(context), base_name)
    else:
        # Requesting the latest version or an unversioned dataset
        base_name = requested_dataset['name']

        all_version_names = _get_child_dataset_names(
            _get_context(context), base_name)

        if len(all_version_names) > 0:
            dataset_type = DatasetType.latest_version
        else:
            dataset_type = DatasetType.unversioned

    all_active_versions = _get_ordered_active_dataset_versions(
        _get_context(context),
        data_dict.copy(),  # Will get modified so make a copy
        all_version_names)

    # Show the most recent, public active version
    if dataset_type == DatasetType.latest_version and \
       len(all_active_versions) > 0:
        version_to_display = all_active_versions[0]

    if dataset_type in (DatasetType.unversioned, DatasetType.specific_version):
        # Do default CKAN authentication
        context['ignore_auth'] = ignore_auth
        logic.check_access('package_show', _get_context(context), data_dict)

    version_to_display['_versions'] = _get_version_names_and_urls(
        all_active_versions, base_name)

    # Reindexing fails if we don't do this
    # Later versions of CKAN will not include these in the package
    # See https://github.com/ckan/ckan/issues/3114
    version_to_display.pop('relationships_as_subject', False)
    version_to_display.pop('relationships_as_object', False)

    return version_to_display
예제 #2
0
def package_show(context, data_dict):
    class DatasetType:
        (specific_version, latest_version, unversioned) = range(3)

    # The parent dataset is private so it doesn't appear in the lists
    # but we want to override the authentication checks so we can
    # access the child datasets that represent the different versions
    ignore_auth = context.get('ignore_auth')
    context['ignore_auth'] = True

    # Get the dataset we actually asked for
    requested_dataset = ckan_package_show(context, data_dict)

    version_to_display = requested_dataset

    parent_names = _get_parent_dataset_names(
        get_context(context), requested_dataset['id'])

    if len(parent_names) > 0:
        base_name = parent_names[0]
        dataset_type = DatasetType.specific_version
        all_version_names = _get_child_dataset_names(
            get_context(context), base_name)
    else:
        # Requesting the latest version or an unversioned dataset
        base_name = requested_dataset['name']

        all_version_names = _get_child_dataset_names(
            get_context(context), base_name)

        if len(all_version_names) > 0:
            dataset_type = DatasetType.latest_version
        else:
            dataset_type = DatasetType.unversioned

    all_active_versions = _get_ordered_active_dataset_versions(
        get_context(context),
        data_dict.copy(),  # Will get modified so make a copy
        all_version_names)

    # Show the most recent, public active version
    if dataset_type == DatasetType.latest_version and \
       len(all_active_versions) > 0:
        version_to_display = all_active_versions[0]

    if dataset_type in (DatasetType.unversioned, DatasetType.specific_version):
        # Do default CKAN authentication
        context['ignore_auth'] = ignore_auth
        logic.check_access('package_show', get_context(context), data_dict)

    version_to_display['_versions'] = _get_version_names_and_urls(
        all_active_versions, base_name)

    # Reindexing fails if we don't do this
    # Later versions of CKAN will not include these in the package
    # See https://github.com/ckan/ckan/issues/3114
    version_to_display.pop('relationships_as_subject', False)
    version_to_display.pop('relationships_as_object', False)

    return version_to_display
예제 #3
0
def _get_or_create_parent_dataset(context, data_dict):
    try:
        dataset = ckan_package_show(
            _get_context(context), {'id': data_dict['name']})
    except (logic.NotFound):
        dataset = toolkit.get_action('package_create')(
            _get_context(context), data_dict)

    return dataset
예제 #4
0
def _get_or_create_parent_dataset(context, data_dict):
    try:
        dataset = ckan_package_show(get_context(context),
                                    {'id': data_dict['name']})
    except (logic.NotFound):
        dataset = toolkit.get_action('package_create')(get_context(context),
                                                       data_dict)

    return dataset
예제 #5
0
def package_show(context, data_dict):
    """TODO: Docstring for package_show.

    :context: TODO
    :data_dict: TODO
    :returns: TODO

    """
    pkg_dict = ckan_package_show(context, data_dict)
    # TODO make actual retrieval from database for comments
    pkg_dict['comments'] = tk.get_action('comment_show')(context, data_dict)
    return pkg_dict
예제 #6
0
def _get_ordered_active_dataset_versions(context, data_dict, child_names):
    versions = []

    for name in child_names:
        data_dict['id'] = name
        version = ckan_package_show(context, data_dict)
        if version['state'] == 'active' and not version['private']:
            versions.append(version)

    versions.sort(key=_get_version, reverse=True)

    return versions
예제 #7
0
def _get_ordered_active_dataset_versions(context, data_dict, child_names):
    versions = []

    for name in child_names:
        data_dict['id'] = name
        version = ckan_package_show(context, data_dict)
        if version['state'] == 'active' and not version['private']:
            versions.append(version)

    versions.sort(key=_get_version, reverse=True)

    return versions
예제 #8
0
def ceon_package_show(context, data_dict):
    pkg = _model.Package.get(data_dict['id'])
    if pkg and pkg.state == 'deleted':
        context['ignore_auth'] = True
    result = ckan_package_show(context, data_dict)
    return result
예제 #9
0
def ceon_package_show(context, data_dict):
    context['ignore_auth'] = True
    result = ckan_package_show(context, data_dict)
    return result
예제 #10
0
def ceon_package_show(context, data_dict):
    pkg = _model.Package.get(data_dict['id'])
    if pkg and pkg.state == 'deleted':
        context['ignore_auth'] = True
    result = ckan_package_show(context, data_dict)
    return result