diff --git a/ckanext/qdes_schema/blueprint.py b/ckanext/qdes_schema/blueprint.py index 3d922701..8ea5ab8c 100644 --- a/ckanext/qdes_schema/blueprint.py +++ b/ckanext/qdes_schema/blueprint.py @@ -10,6 +10,8 @@ import json import xml.dom.minidom import os +import ckan.lib.navl.dictization_functions as dict_fns +import ckan.logic as logic from ckan.common import _, c, request from ckanext.qdes_schema import helpers @@ -17,6 +19,9 @@ from pprint import pformat from ckanext.qdes_schema.logic.helpers import dataservice_helpers as dataservice_helpers from flask import send_file +from ckan.views import dataset as dataset_view +from ckan.lib.search import SearchIndexError +from six import text_type abort = toolkit.abort get_action = toolkit.get_action @@ -29,6 +34,10 @@ clean_dict = logic.clean_dict tuplize_dict = logic.tuplize_dict parse_params = logic.parse_params +check_access = toolkit.check_access +g = check_access = toolkit.g +tuplize_dict = logic.tuplize_dict +parse_params = logic.parse_params qdes_schema = Blueprint('qdes_schema', __name__) @@ -279,11 +288,11 @@ def dataset_export(id, format): # dataset['contact_publisher'] = term all_relationships = helpers.get_all_relationships(dataset['id']) relationships = [] - + for relationship in all_relationships: if relationship.get('type') in ['Is Part Of']: relationships.append(relationship) - + # TODO: Need to load all secure vocabs as dict objects # Load vocabualry service contact_point vocab_value = {} @@ -304,7 +313,7 @@ def dataset_export(id, format): dataset['metadata_contact_point'] = vocab_value - # Get the identifiers + # Get the identifiers dataset['additional_info'] = h.get_multi_textarea_values(dataset.get('additional_info', [])) dataset['identifiers'] = h.get_multi_textarea_values(dataset.get('identifiers', [])) dataset['topic'] = h.get_multi_textarea_values(dataset.get('topic', [])) @@ -379,7 +388,6 @@ def dataset_export(id, format): if new_resources: dataset['resources'] = new_resources - extra_vars = {} extra_vars['dataset'] = dataset data = None @@ -403,6 +411,84 @@ def dataset_export(id, format): abort(404, _('Dataset not found')) +class CreateView(dataset_view.CreateView): + def post(self, package_type): + # If _ckan_phase is set to 'save_record' and pkg_name exists, set the dataset to active, save and redirect to dataset read page + if request.form.get(u'_ckan_phase') == 'save_record' and len(request.form.get(u'pkg_name', '')) > 0: + # Copied from https://github.com/ckan/ckan/blob/b123155c0fe1cd07736375ee5cf97abcd0a5fcf5/ckan/views/dataset.py#L542 + # Please make sure to keep up to date on any new CKAN release + + # The staged add dataset used the new functionality when the dataset is + # partially created so we need to know if we actually are updating or + # this is a real new. + context = self._prepare() + is_an_update = False + try: + data_dict = clean_dict( + dict_fns.unflatten(tuplize_dict(parse_params(request.form))) + ) + except dict_fns.DataError: + return base.abort(400, _(u'Integrity Error')) + try: + # prevent clearing of groups etc + context[u'allow_partial_update'] = True + # sort the tags + if u'tag_string' in data_dict: + data_dict[u'tags'] = dataset_view._tag_string_to_list( + data_dict[u'tag_string'] + ) + if data_dict.get(u'pkg_name'): + is_an_update = True + # This is actually an update not a save + data_dict[u'id'] = data_dict[u'pkg_name'] + del data_dict[u'pkg_name'] + # QDES modification begins + data_dict[u'state'] = u'active' + # QDES modification ends + # this is actually an edit not a save + pkg_dict = get_action(u'package_update')( + context, data_dict + ) + # QDES modification begins + return dataset_view._form_save_redirect( + pkg_dict[u'name'], u'new', package_type=package_type + ) + # QDES modification ends + except NotAuthorized: + return base.abort(403, _(u'Unauthorized to read package')) + except NotFound as e: + return base.abort(404, _(u'Dataset not found')) + except SearchIndexError as e: + try: + exc_str = text_type(repr(e.args)) + except Exception: # We don't like bare excepts + exc_str = text_type(str(e)) + return base.abort( + 500, + _(u'Unable to add package to search index.') + exc_str + ) + except ValidationError as e: + errors = e.error_dict + error_summary = e.error_summary + if is_an_update: + # we need to get the state of the dataset to show the stage we + # are on. + pkg_dict = get_action(u'package_show')(context, data_dict) + data_dict[u'state'] = pkg_dict[u'state'] + return dataset_view.EditView().get( + package_type, + data_dict[u'id'], + data_dict, + errors, + error_summary + ) + data_dict[u'state'] = u'none' + return self.get(package_type, data_dict, errors, error_summary) + else: + # Continue to CKAN core CreateView.post code workflow + return super().post(package_type) + + qdes_schema.add_url_rule(u'/dataset//related-datasets', view_func=related_datasets) qdes_schema.add_url_rule(u'/dataset//metadata', view_func=dataset_metadata) qdes_schema.add_url_rule(u'/dataservice//metadata', endpoint='dataservice_metadata', view_func=dataset_metadata) @@ -414,3 +500,5 @@ def dataset_export(id, format): view_func=unpublish_external_dataset_resource) qdes_schema.add_url_rule(u'/dataset//export/', view_func=dataset_export) +qdes_schema.add_url_rule(u'/dataset/new', defaults={u'package_type': u'dataset'}, + view_func=CreateView.as_view(str(u'new'))) diff --git a/ckanext/qdes_schema/fanstatic/dataset_no_resource.js b/ckanext/qdes_schema/fanstatic/dataset_no_resource.js index 4366a5eb..e37a42cd 100644 --- a/ckanext/qdes_schema/fanstatic/dataset_no_resource.js +++ b/ckanext/qdes_schema/fanstatic/dataset_no_resource.js @@ -1,7 +1,11 @@ jQuery(document).ready(function () { - jQuery('button[name="save_record"]').on('click', function (e) { + jQuery('button[name="save_record"]').on("click", function (e) { e.preventDefault(); - jQuery('input[name="_ckan_phase"]').remove(); - jQuery(this).closest('form').submit(); + if (jQuery('input[name="pkg_name"]').val().length > 0) { + jQuery('input[name="_ckan_phase"]').val("save_record"); + } else { + jQuery('input[name="_ckan_phase"]').remove(); + } + jQuery(this).closest("form").submit(); }); }); diff --git a/ckanext/qdes_schema/helpers.py b/ckanext/qdes_schema/helpers.py index 925d784e..b9914448 100644 --- a/ckanext/qdes_schema/helpers.py +++ b/ckanext/qdes_schema/helpers.py @@ -520,9 +520,9 @@ def map_update_schedule(uri, schema): def map_license(uri, schema): license_map = { constants.PUBLISH_EXTERNAL_IDENTIFIER_DATA_QLD_SCHEMA: { - 'https://linked.data.gov.au/def/licence-document/cc-by-4.0': 'cc-by-4', - 'https://linked.data.gov.au/def/licence-document/cc-by-nd-4.0': 'cc-by-nd-4', - 'https://linked.data.gov.au/def/licence-document/cc-by-sa-4.0': 'cc-by-sa-4' + 'https://linked.data.gov.au/def/qld-data-licenses/cc-by-4.0': 'cc-by-4', + 'https://linked.data.gov.au/def/qld-data-licenses/cc-by-nd-4.0': 'cc-by-nd-4', + 'https://linked.data.gov.au/def/qld-data-licenses/cc-by-sa-4.0': 'cc-by-sa-4' }, # @todo, in case needed, need to map this against external schema in future. constants.PUBLISH_EXTERNAL_IDENTIFIER_QSPATIAL_SCHEMA: {}, diff --git a/ckanext/qdes_schema/plugin.py b/ckanext/qdes_schema/plugin.py index 97d09c3d..4930ff50 100644 --- a/ckanext/qdes_schema/plugin.py +++ b/ckanext/qdes_schema/plugin.py @@ -416,6 +416,12 @@ def dataset_facets(self, facets_dict, package_type): return ordered_facets + def group_facets(self, facets_dict, group_type, package_type): + return self.dataset_facets(facets_dict, 'dataset') + + def organization_facets(self, facets_dict, organization_type, package_type): + return self.dataset_facets(facets_dict, 'dataset') + # IAuthFunctions def get_auth_functions(self): return { diff --git a/ckanext/qdes_schema/templates/group/read.html b/ckanext/qdes_schema/templates/group/read.html new file mode 100644 index 00000000..d7d56450 --- /dev/null +++ b/ckanext/qdes_schema/templates/group/read.html @@ -0,0 +1,21 @@ +{% ckan_extends %} + +{% block secondary_content %} + {% snippet "group/snippets/info.html", group=group_dict, show_nums=true %} + + {% set default_extent = h.get_qld_bounding_box_config() %} + {% snippet "snippets/spatial_query.html", default_extent=default_extent, extras={'id':group_dict.id} %} + +
+
+ {% for facet in facet_titles %} + {% if facet == 'temporal_start' or facet == 'temporal_end' %} + {{ h.snippet('snippets/facet_list_temporal.html', title=facet_titles[facet], name=facet, search_facets=search_facets, extras={'id':group_dict.id}) }} + {% elif not facet in ['collection_package_id', 'temporal_coverage_from', 'temporal_coverage_to'] %} + {{ h.snippet('snippets/facet_list.html', title=facet_titles[facet], name=facet, extras={'id':group_dict.id}) }} + {% endif %} + {% endfor %} +
+ close +
+{% endblock %} diff --git a/ckanext/qdes_schema/templates/organization/read.html b/ckanext/qdes_schema/templates/organization/read.html new file mode 100644 index 00000000..178aaba8 --- /dev/null +++ b/ckanext/qdes_schema/templates/organization/read.html @@ -0,0 +1,19 @@ +{% ckan_extends %} + +{% block organization_facets %} + {% set default_extent = h.get_qld_bounding_box_config() %} + {% snippet "snippets/spatial_query.html", default_extent=default_extent, extras={'id':group_dict.id} %} + +
+
+ {% for facet in facet_titles %} + {% if facet == 'temporal_start' or facet == 'temporal_end' %} + {{ h.snippet('snippets/facet_list_temporal.html', title=facet_titles[facet], name=facet, search_facets=search_facets, extras={'id':group_dict.id}) }} + {% elif not facet in ['collection_package_id', 'temporal_coverage_from', 'temporal_coverage_to'] %} + {{ h.snippet('snippets/facet_list.html', title=facet_titles[facet], name=facet, extras={'id':group_dict.id}) }} + {% endif %} + {% endfor %} +
+ close +
+{% endblock %} diff --git a/ckanext/qdes_schema/templates/scheming/display_snippets/qdes_multi_group.html b/ckanext/qdes_schema/templates/scheming/display_snippets/qdes_multi_group.html index a68b761d..a048c206 100644 --- a/ckanext/qdes_schema/templates/scheming/display_snippets/qdes_multi_group.html +++ b/ckanext/qdes_schema/templates/scheming/display_snippets/qdes_multi_group.html @@ -5,7 +5,8 @@ {% set columns = (12 / field.get('field_group')|length)|int %} {% for field_group in field.get('field_group') or [] %}
- {% if '/ckan-admin/vocabulary-services/secure-autocomplete/' in field_group.get('form_attrs', {}).get('data-module-source' ,'') %} + {% if '/ckan-admin/vocabulary-services/secure-autocomplete/' in field_group.get('form_attrs', {}).get('data-module-source' ,'') + and 'alt=1' not in field_group.get('form_attrs', {}).get('data-module-source' ,'') %} {% snippet "/scheming/display_snippets/qdes_secure_vocabulary_text.html", field=field_group , data=group_data %} {% else %} {% set value_data = group_data.get(field_group.field_name, '') %} diff --git a/ckanext/qdes_schema/templates/snippets/facet_list_temporal.html b/ckanext/qdes_schema/templates/snippets/facet_list_temporal.html index aaa9effc..242939d0 100644 --- a/ckanext/qdes_schema/templates/snippets/facet_list_temporal.html +++ b/ckanext/qdes_schema/templates/snippets/facet_list_temporal.html @@ -13,7 +13,7 @@

{{ _('Temporal coverage') }}

-
+
diff --git a/ckanext/qdes_schema/templates/snippets/spatial_query.html b/ckanext/qdes_schema/templates/snippets/spatial_query.html index 153171e8..b44b26bf 100644 --- a/ckanext/qdes_schema/templates/snippets/spatial_query.html +++ b/ckanext/qdes_schema/templates/snippets/spatial_query.html @@ -15,7 +15,7 @@

{{ _('Location') }} - {{ _('Clear map') }} + {{ _('Clear map') }}