[ckan-dev] DataStore API and Download

Matthew Fullerton matt.fullerton at gmail.com
Wed Sep 28 08:20:03 UTC 2016


Hi François,
It is possible if you write an extension. In extensions you can extend
templates and you could do something like this (important part in red):

(in the file templates/package/resource_read.html)

{% ckan_extends %}

{% block resource_actions_inner %}
  {% if h.check_access('package_update', {'id':pkg.id }) %}
    <li>{% link_for _('Manage'), controller='package',
action='resource_edit', id=pkg.name, resource_id=res.id, class_='btn',
icon='wrench' %}</li>
  {% endif %}
  {% if res.url and h.is_url(res.url) %}
    <li>
      <a class="btn btn-primary resource-url-analytics resource-type-{{
res.resource_type }}" href="{{ res.url }}">
        {% if res.resource_type in ('listing', 'service') %}
          <i class="icon-eye-open"></i> {{ _('View') }}
        {% elif  res.resource_type == 'api' %}
          <i class="icon-key"></i> {{ _('API Endpoint') }}
        {% elif not res.has_views or not res.can_be_previewed %}
          <i class="icon-external-link"></i> {{ _('Go to resource') }}
        {% else %}
          <i class="icon-download"></i> {{ _('Download') }}
        {% endif %}
      </a>
    </li>
  {% endif %}
  {% if res.datastore_active %}
    <li>
      <a class="btn btn-primary resource-url-analytics resource-type-{{
res.resource_type }}" href="/datastore/dump/{{ res.id }}"
target="_blank"><i class="icon-cloud-download"></i>{{ _('Export from DB')
}}</a>
    </li>
    <li>{% snippet 'package/snippets/data_api_button.html', resource=res,
datastore_root_url=c.datastore_api %}</li>
  {% endif %}
{% endblock %}

The if statement about res.datastore_active differs from the standard CKAN
template ( {% if 'datastore' in g.plugins %} ) and I think there is an
ongoing issue with datastore_active, so you might need to try it out with
the latest CKAN and see how it goes.

Best,
Matt

--
Matt Fullerton
Software development and data science for open data and mobility
matt at crowdsalad.de
+49 89 7456 0495 / +49 176 5789 6501
http://www.crowdsalad.de

On 27 September 2016 at 22:52, Bois Francois-Xavier <fxbois at gmail.com>
wrote:

> Hi Matt,
> in fact I know this shortcut url.
> What I would like to know is whether it is possible to add a "download"
> entry in the menu "explore" (with a dynamic resource, I only find Preview
> and Edit)
>
> On Tue, Sep 27, 2016 at 6:27 PM, Matthew Fullerton <
> matt.fullerton at gmail.com> wrote:
>
>> Hi François,
>> It should be built in, try:
>>
>> http://YOUR_CKAN_URL/datastore/dump/RESOURCE_ID
>>
>> Best,
>> Matt
>>
>> --
>> Matt Fullerton
>> Software development and data science for open data and mobility
>> matt at crowdsalad.de
>> +49 89 7456 0495 / +49 176 5789 6501
>> http://www.crowdsalad.de
>>
>> On 27 Sep 2016 13:48, "Bois Francois-Xavier" <fxbois at gmail.com> wrote:
>>
>>> Hi
>>>
>>> I was playing with the datastore API and was surprised not being able to
>>> download "as csv" the content of the dynamic resource I've created (in the
>>> web interface). Is there any specific plugin to achieve this ?
>>>
>>> --
>>> François-Xavier Bois
>>> Kernix - 15 rue Cels - 75014 PARIS
>>> Tel. +33 1 53 98 73 43
>>>
>>> _______________________________________________
>>> ckan-dev mailing list
>>> ckan-dev at lists.okfn.org
>>> https://lists.okfn.org/mailman/listinfo/ckan-dev
>>> Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev
>>>
>>>
>> _______________________________________________
>> ckan-dev mailing list
>> ckan-dev at lists.okfn.org
>> https://lists.okfn.org/mailman/listinfo/ckan-dev
>> Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev
>>
>>
>
>
> --
> François-Xavier Bois
> Kernix - 15 rue Cels - 75014 PARIS
> Tel. +33 1 53 98 73 43
>
> _______________________________________________
> ckan-dev mailing list
> ckan-dev at lists.okfn.org
> https://lists.okfn.org/mailman/listinfo/ckan-dev
> Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20160928/1c9218c1/attachment-0003.html>


More information about the ckan-dev mailing list