Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/ckan/ckanext-xloader into…
Browse files Browse the repository at this point in the history
… merge-upstream
  • Loading branch information
ThrawnCA committed Feb 2, 2024
2 parents 696387e + 959dfd2 commit eba7676
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 23 deletions.
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ Configuration:

See the extension's `config_declaration.yaml <ckanext/xloader/config_declaration.yaml>`_ file.

This plugin also supports the `ckan.download_proxy` setting, to use a proxy server when downloading files.
This setting is shared with other plugins that download resource files, such as ckanext-archiver. Eg:

ckan.download_proxy = http://my-proxy:1234/

You may also wish to configure the database to use your preferred date input style on COPY.
For example, to make [PostgreSQL](https://www.postgresql.org/docs/current/runtime-config-client.html#RUNTIME-CONFIG-CLIENT-FORMAT)
expect European (day-first) dates, you could add to ``postgresql.conf``:
Expand Down
6 changes: 2 additions & 4 deletions ckanext/xloader/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ def xloader_status_description(status):
def is_resource_supported_by_xloader(res_dict, check_access=True):
is_supported_format = XLoaderFormats.is_it_an_xloader_format(res_dict.get('format'))
is_datastore_active = res_dict.get('datastore_active', False)
if check_access:
user_has_access = toolkit.h.check_access('package_update', {'id': res_dict.get('package_id')})
else:
user_has_access = True
user_has_access = not check_access or toolkit.h.check_access('package_update',
{'id':res_dict.get('package_id')})
url_type = res_dict.get('url_type')
if url_type:
try:
Expand Down
7 changes: 7 additions & 0 deletions ckanext/xloader/templates/package/resource_read.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@
<li>{% link_for _('DataStore'), named_route='xloader.resource_data', id=pkg.name, resource_id=res.id, class_='btn btn-light', icon='cloud-upload' %}</li>
{% endif %}
{% endblock %}

{% block resource_actions_inner %}
{% if h.check_ckan_version(max_version='2.10') and h.is_resource_supported_by_xloader(res) %}
<li>{% link_for _('DataStore'), named_route='xloader.resource_data', id=pkg.name, resource_id=res.id, class_='btn btn-light', icon='cloud-upload' %}</li>
{% endif %}
{{ super() }}
{% endblock %}
7 changes: 7 additions & 0 deletions ckanext/xloader/templates/package/snippets/resource_item.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@
<li>{% link_for _('DataStore'), named_route='xloader.resource_data', id=pkg.name, resource_id=res.id, class_='dropdown-item', icon='cloud-upload' %}</li>
{% endif %}
{% endblock %}

{% block resource_item_explore_links %}
{% if h.check_ckan_version(max_version='2.10') and h.is_resource_supported_by_xloader(res) %}
<li>{% link_for _('DataStore'), named_route='xloader.resource_data', id=pkg.name, resource_id=res.id, class_='dropdown-item', icon='cloud-upload' %}</li>
{% endif %}
{{ super() }}
{% endblock %}
27 changes: 15 additions & 12 deletions ckanext/xloader/templates/xloader/resource_data.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,34 @@

{% set show_table = true %}

{% block upload_ds_button %}
{% set action = h.url_for('xloader.resource_data', id=pkg.name, resource_id=res.id) %}
<form method="post" action="{{ action }}" class="datapusher-form mb-3 mr-3 d-inline-block">
{{ h.csrf_input() if 'csrf_input' in h }}
<button class="btn btn-primary" name="save" type="submit">
<i class="fa fa-cloud-upload"></i> {{ _('Upload to DataStore') }}
</button>
</form>
{% endblock %}

<div class="clear-fix mx-1 d-inline-block"></div>

{% block delete_ds_button %}
{% if res.datastore_active %}
{% set delete_action = h.url_for('xloader.delete_datastore_table', id=pkg.id, resource_id=res.id) %}
<form method="post" action="{{ delete_action }}" class="mb-3 d-inline-block pull-right">
<form method="post" action="{{ delete_action }}" class="mb-3 d-inline-block">
{{ h.csrf_input() if 'csrf_input' in h }}
<a href="{{ delete_action }}"
class="btn btn-danger pull-left"
class="btn btn-danger"
type="submit"
data-module="confirm-action"
data-module-with-data=true
data-module-content="{{ _('Are you sure you want to delete the DataStore and Data Dictionary?') }}"
>{% block delete_datastore_button_text %}<i class="fa fa-remove"></i> {{ _('Delete from DataStore') }}{% endblock %}</a>
>{% block delete_datastore_button_text %}<i class="fa fa-trash-alt"></i> {{ _('Delete from DataStore') }}{% endblock %}</a>
</form>
{% endif %}
{% endblock %}

{% block upload_ds_button %}
<form method="post" action="{{ h.url_for('xloader.resource_data', id=pkg.name, resource_id=res.id) }}" class="datapusher-form mb-3 d-inline-block">
{{ h.csrf_input() if 'csrf_input' in h }}
<button class="btn btn-primary" name="save" type="submit">
<i class="fa fa-cloud-upload"></i> {{ _('Upload to DataStore') }}
</button>
</form>
{% endblock %}

{% if status.error and status.error.message %}
{% set show_table = false %}
<div class="alert alert-error">
Expand Down
6 changes: 3 additions & 3 deletions ckanext/xloader/tests/samples/mixed_numeric_string_sample.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Funding agency,Program title,Maximum (indicative) grant amount
DTIS,Accessible Tourism Infrastructure Grants,Five hundred thousand dollars
DTIS,Boosting Accessible Tourism Experiences Grants,5000
Funding agency,Program title,Maximum (indicative) grant amount
DTIS,Accessible Tourism Infrastructure Grants,Five hundred thousand dollars
DTIS,Boosting Accessible Tourism Experiences Grants,5000
8 changes: 4 additions & 4 deletions ckanext/xloader/tests/samples/sample_with_blanks.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Funding agency,Program title,Opening date,Service ID
DTIS,Visitor First Experiences Fund,23/03/2023,63039
DTIS,First Nations Sport and Recreation Program Round 2,22/03/2023,63040
,,,63041
Funding agency,Program title,Opening date,Service ID
DTIS,Visitor First Experiences Fund,23/03/2023,63039
DTIS,First Nations Sport and Recreation Program Round 2,22/03/2023,63040
,,,63041
1 change: 1 addition & 0 deletions ckanext/xloader/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def is_it_an_xloader_format(cls, format_):
if cls.formats is None:
cls._formats = config.get("ckanext.xloader.formats")
if cls._formats is not None:
# use config value. preserves empty list as well.
cls._formats = cls._formats.lower().split()
else:
cls._formats = DEFAULT_FORMATS
Expand Down

0 comments on commit eba7676

Please sign in to comment.