Skip to content

Commit

Permalink
Merge commit 'd400a6ce3ccee3c43b840d11a4c55b411996b795'
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkCalvert committed Nov 18, 2021
2 parents 068761b + d400a6c commit cd84785
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 13 deletions.
96 changes: 92 additions & 4 deletions ckanext/qdes_schema/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@
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
from flask import Blueprint
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
Expand All @@ -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__)

Expand Down Expand Up @@ -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 = {}
Expand All @@ -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', []))
Expand Down Expand Up @@ -379,7 +388,6 @@ def dataset_export(id, format):
if new_resources:
dataset['resources'] = new_resources


extra_vars = {}
extra_vars['dataset'] = dataset
data = None
Expand All @@ -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/<id_or_name>/related-datasets', view_func=related_datasets)
qdes_schema.add_url_rule(u'/dataset/<id>/metadata', view_func=dataset_metadata)
qdes_schema.add_url_rule(u'/dataservice/<id>/metadata', endpoint='dataservice_metadata', view_func=dataset_metadata)
Expand All @@ -414,3 +500,5 @@ def dataset_export(id, format):
view_func=unpublish_external_dataset_resource)
qdes_schema.add_url_rule(u'/dataset/<id>/export/<format>',
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')))
10 changes: 7 additions & 3 deletions ckanext/qdes_schema/fanstatic/dataset_no_resource.js
Original file line number Diff line number Diff line change
@@ -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();
});
});
6 changes: 3 additions & 3 deletions ckanext/qdes_schema/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand Down
6 changes: 6 additions & 0 deletions ckanext/qdes_schema/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
21 changes: 21 additions & 0 deletions ckanext/qdes_schema/templates/group/read.html
Original file line number Diff line number Diff line change
@@ -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} %}

<div class="filters">
<div>
{% 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 %}
</div>
<a class="close no-text hide-filters"><i class="fa fa-times-circle"></i><span class="text">close</span></a>
</div>
{% endblock %}
19 changes: 19 additions & 0 deletions ckanext/qdes_schema/templates/organization/read.html
Original file line number Diff line number Diff line change
@@ -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} %}

<div class="filters">
<div>
{% 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 %}
</div>
<a class="close no-text hide-filters"><i class="fa fa-times-circle"></i><span class="text">close</span></a>
</div>
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
{% set columns = (12 / field.get('field_group')|length)|int %}
{% for field_group in field.get('field_group') or [] %}
<div class="col-xs-{{columns}}">
{% 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, '') %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ <h2 class="module-heading">
{{ _('Temporal coverage') }}
</h2>

<form method="get" class="temporal-coverage form-inline" action="{{ h.add_url_param() }}">
<form method="get" class="temporal-coverage form-inline" action="{{ h.add_url_param(extras=extras) }}">


<div class="form-group">
Expand Down
2 changes: 1 addition & 1 deletion ckanext/qdes_schema/templates/snippets/spatial_query.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<h2 class="module-heading">
<i class="icon-medium icon-globe"></i>
{{ _('Location') }}
<a id="dataset-map-clear" href="{{ h.remove_url_param(['ext_bbox','ext_prev_extent', 'ext_location']) }}" class="action">{{ _('Clear map') }}</a>
<a id="dataset-map-clear" href="{{ h.remove_url_param(['ext_bbox','ext_prev_extent', 'ext_location'], extras=extras) }}" class="action">{{ _('Clear map') }}</a>
</h2>
<ul class="unstyled nav nav-simple nav-facet nav-dataset-map" id="dataset-map-nav">
<li class="nav-item">
Expand Down

0 comments on commit cd84785

Please sign in to comment.