Skip to content

Commit

Permalink
Merge pull request ckan#38 from qld-gov-au/develop
Browse files Browse the repository at this point in the history
Develop to master
  • Loading branch information
ThrawnCA authored Mar 14, 2023
2 parents 10ce4dd + c7a54ac commit 7abfbdd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
3 changes: 3 additions & 0 deletions ckanext/validation/assets/js/module-resource-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ this.ckan.module('resource-schema', function($) {
},

_markUnaligned: function() {
if (this.align_block.hasClass("no-default-schema")) {
return;
}
this.align_block.removeClass('hidden');
this.field_align.prop('checked', false);
}
Expand Down
29 changes: 27 additions & 2 deletions ckanext/validation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import logging
import json
import os
from six import ensure_str
from io import BytesIO
from datetime import datetime as dt
Expand Down Expand Up @@ -114,8 +115,7 @@ def run_sync_validation(resource_data):
if is_url_valid(resource_data['url']):
source = resource_data['url']
else:
upload = uploader.get_resource_uploader(resource_data)
source = upload.get_path(resource_data["id"])
source = _get_uploaded_resource_path(resource_data)

report = validate(source,
format=_format,
Expand All @@ -138,6 +138,31 @@ def run_sync_validation(resource_data):
resource_data['_success_validation'] = True


def _get_uploaded_resource_path(resource_data):
"""Get a path for uploaded resource. Supports a default ResourceUpload and
ckanext-s3filestore S3ResourceUploader."""
upload = uploader.get_resource_uploader(resource_data)
path = None

if isinstance(upload, uploader.ResourceUpload):
path = upload.get_path(resource_data['id'])
else:
try:
from ckanext.s3filestore.uploader import S3ResourceUploader
except Exception:
return path

if isinstance(upload, S3ResourceUploader):
filename = os.path.basename(resource_data["url"])
key_path = upload.get_path(resource_data["id"], filename)
path = upload.get_signed_url_to_key(key_path, {
'ResponseContentDisposition':
'attachment; filename=' + filename,
})

return path


def _get_session(resource_data):
dataset = tk.get_action('package_show')({
'user': get_site_user()['name']
Expand Down

0 comments on commit 7abfbdd

Please sign in to comment.