Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional DataStore Tab in Resource Edit #190

Merged
13 changes: 13 additions & 0 deletions ckanext/xloader/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,16 @@ def xloader_status_description(status):
return captions.get(status['status'], status['status'].capitalize())
else:
return _('Not Uploaded Yet')


def is_xloader_format(resource_format):
from ckanext.xloader.plugin import XLoaderFormats

return XLoaderFormats.is_it_an_xloader_format(resource_format)


def is_xloader_type(resource_url_type):
try:
return resource_url_type not in toolkit.h.datastore_rw_resource_url_types()
except AttributeError:
return (resource_url_type == 'upload' or resource_url_type == '')
2 changes: 2 additions & 0 deletions ckanext/xloader/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,6 @@ def get_helpers(self):
return {
"xloader_status": xloader_helpers.xloader_status,
"xloader_status_description": xloader_helpers.xloader_status_description,
"is_xloader_format": xloader_helpers.is_xloader_format,
"is_xloader_type": xloader_helpers.is_xloader_type,
}
7 changes: 6 additions & 1 deletion ckanext/xloader/templates/package/resource_edit_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@

{% block inner_primary_nav %}
{{ super() }}
{{ h.build_nav_icon('xloader.resource_data', _('DataStore'), id=pkg.name, resource_id=res.id) }}
{%
if (h.is_xloader_format(res.format) or res.datastore_active)
and h.is_xloader_type(res.url_type)
%}
{{ h.build_nav_icon('xloader.resource_data', _('DataStore'), id=pkg.name, resource_id=res.id, icon='cloud-upload') }}
{% endif %}
{% endblock %}
12 changes: 12 additions & 0 deletions ckanext/xloader/templates/package/resource_read.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% ckan_extends %}

{% block action_manage_inner %}
JVickery-TBS marked this conversation as resolved.
Show resolved Hide resolved
{{ super() }}
{%
if (h.is_xloader_format(res.format) or res.datastore_active)
and h.check_access('package_update', {'id':pkg.id })
and h.is_xloader_type(res.url_type)
%}
<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 %}
12 changes: 12 additions & 0 deletions ckanext/xloader/templates/package/snippets/resource_item.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% ckan_extends %}

{% block resource_item_explore_inner %}
JVickery-TBS marked this conversation as resolved.
Show resolved Hide resolved
{{ super() }}
{%
if (h.is_xloader_format(res.format) or res.datastore_active)
and h.check_access('package_update', {'id':pkg.id })
and h.is_xloader_type(res.url_type)
%}
<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 %}
12 changes: 12 additions & 0 deletions ckanext/xloader/templates/package/snippets/resources.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% ckan_extends %}

{% block resources_list_edit_dropdown_inner %}
JVickery-TBS marked this conversation as resolved.
Show resolved Hide resolved
{{ super() }}
{%
if (h.is_xloader_format(resource.format) or resource.datastore_active)
and h.check_access('package_update', {'id':pkg.id })
and h.is_xloader_type(resource.url_type)
%}
<li>{% link_for _('DataStore'), named_route='xloader.resource_data', id=pkg.name, resource_id=resource.id, class_='dropdown-item', icon='cloud-upload' %}</li>
{% endif %}
{% endblock %}