如何启用API按钮CKAN数据集? [英] How to enable API button for CKAN data set?

查看:363
本文介绍了如何启用API按钮CKAN数据集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功添加了CKAN网站的数据集。它能使preVIEW数据集为好。

下面的URL数据集

  testckan.com:5000/dataset/my-data1/resource/4c2647ca-a4ab-4d20-8119-5c3da9d4ae14

通过添加 API / REST / 为下面的URL能够公开的数据集作为一个JSON的服务。

<$p$p><$c$c>testckan.com:5000/api/rest/dataset/my-data1/resource/4c2647ca-a4ab-4d20-8119-5c3da9d4ae14

所有我想要做的就是添加一个按钮,以便用户可以查看数据集作为一个JSON,而不是在这不是用户友好的URL键入它。

我也有类似的按钮

  http://data.gov.uk/dataset/bona-vacantia-estates-advertisements

在API和放大器; APPS。请看下面的图片。

如何启用CKAN数据集,像上面API按钮?


解决方案

您将不得不修改前端模板为包(即数据集)视图。您可以这个变化添加到您自己的源CKAN code的副本,还是像亨德里克提及,data.gov.uk人都做过,创建的 CKAN扩展修改的模板。

您该功能的例子是针对data.gov.uk网站是开源和提供 GitHub的。的特定部分是在<一href=\"https://github.com/datagovuk/ckanext-dgu/blob/master/ckanext/dgu/theme/templates/package/read_common.html\"相对=nofollow> read_common.html

 &LT; B&GT; API:LT; / B&GT;&LT; A HREF =$ {h.url_for(控制器=API,注册='包',行动='秀,ID = c.pkg.name,版本='2')}&GT;
$ {h.url_for(控制器=API,注册='包',行动='秀',ID = c.pkg.name,版本='2')}
&所述; / A&GT;

的<一个href=\"http://docs.ckan.org/en/847-new-theming-docs/template-helper-functions.html#ckan.lib.helpers.url_for\"相对=nofollow> url_for功能是从ckan.lib.helpers模块,可用于模板作为'H'根据CKAN文档,所以你应该能够直接在模板中使用它作为在code以上。

I have successfully added a data set for the CKAN site. It enables to preview the data set as well.

Below is the URL for the data set

testckan.com:5000/dataset/my-data1/resource/4c2647ca-a4ab-4d20-8119-5c3da9d4ae14

By adding api/rest/ to the URL as below enables to expose data sets as a JSON service.

testckan.com:5000/api/rest/dataset/my-data1/resource/4c2647ca-a4ab-4d20-8119-5c3da9d4ae14

All I want to do is add an button so that user can view the data set as a JSON rather than typing it in the URL which is not user friendly.

I have seen similar button in the

http://data.gov.uk/dataset/bona-vacantia-estates-advertisements

under API & APPS. Please see the image below.

How to enable API button for CKAN data set like above?

解决方案

You will have to modify the front-end templating for the package (aka dataset) view. You can either add this change to your own copy of CKAN source code, or like Hendrik mentioned and data.gov.uk people have done, create a CKAN extension to modify the templates.

Your example of the feature is implemented for the data.gov.uk site which is open source and available in GitHub. The specific part is in the read_common.html:

<b>API: </b><a href="${h.url_for(controller='api', register='package', action='show', id=c.pkg.name, ver='2')}">
${h.url_for(controller='api', register='package', action='show', id=c.pkg.name, ver='2')}
</a>

The url_for function is from the ckan.lib.helpers module which "is available for templates as 'h'" according to the CKAN docs, so you should be able to use it directly in the template as in the code above.

这篇关于如何启用API按钮CKAN数据集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆