[ckan-dev] Adding a tag to a package

Alan Tygel alantygel at gmail.com
Thu Aug 13 13:29:26 UTC 2015


Thanks Dan!

I was trying exactly the strategy described in [1]. The problem was that I
didn't understand that I could pass the whole package, instead of the
separated meta-data, as pointed in the create_package docs.

Anyway, maybe in my case package_patch would really be the better option!

all the best,
alan

[1]
http://docs.ckan.org/en/ckan-2.3/api/index.html#ckan.logic.action.update.package_update

On Thu, Aug 13, 2015 at 3:19 PM, Dan Mihaila <danmihaila at gmail.com> wrote:

> Hello,
> If you are using CKAN 2.2 read carefully
> http://docs.ckan.org/en/ckan-2.3/api/index.html#ckan.logic.action.update.package_update
> (It is recommended to call ckan.logic.action.get.package_show()
> <http://docs.ckan.org/en/ckan-2.3/api/index.html#ckan.logic.action.get.package_show>,
> make the desired changes to the result, and then call package_update()
> with it.)
> If you have 2.3 I recommend to use:
>
> http://docs.ckan.org/en/ckan-2.3/api/index.html#ckan.logic.action.patch.package_patch
> which i think is doing what you need.
> I didn't test it, but I found it useful :)
>
> Dan
>
> *Dan Mihaila*, IT Consultant
> (M) +40 722 502 304 • (GTalk) dan.mihaila at gmail.com • (Skype) carcotelul
> • (Twitter) dan_mihaila • (Yahoo) carcotelul
>   <dmihaila at dginternational.org>
>
> On Thu, Aug 13, 2015 at 4:11 PM, Alan Tygel <alantygel at gmail.com> wrote:
>
>> Hi,
>>
>> Thanks to Matt Leduc, I learned that I should have passed the whole
>> package, and not just the part where I wanted to update it.
>>
>> So, the correct code would be:
>>
>> # take the package data_dict
>> dataset = p.toolkit.get_action('package_show')({},{'id': ds['id'] })
>>
>> # append a new tag
>>
>> dataset['tags'].append(p.toolkit.get_action('tag_show')({},{'id':request.POST['tag1']}))
>>
>> # update the package
>> p.toolkit.get_action('package_update')({},dataset)
>>
>> all the best,
>> alan
>>
>> On Thu, Aug 13, 2015 at 2:12 PM, Alan Tygel <alantygel at gmail.com> wrote:
>>
>>> Hi,
>>>
>>> I'm trying to add a tag to a package, but something is going wrong.
>>> Following the documentation, my strategy was:
>>>
>>> # take the package data_dict
>>> dataset = p.toolkit.get_action('package_show')({},{'id': ds['id'] })
>>>
>>> # append a new tag
>>>
>>> dataset['tags'].append(p.toolkit.get_action('tag_show')({},{'id':request.POST['tag1']}))
>>>
>>> # update the package
>>> p.toolkit.get_action('package_update')({},{'id':dataset['id'],
>>> 'tags':dataset['tags']})
>>>
>>> I actually succeeded in adding the new tag, but after this operation the
>>> package resources don't show any more.
>>>
>>> I appreciate any hints! And as soon as I fix this, I'll write about in
>>> the docs.
>>>
>>> all the best,
>>> alan
>>>
>>>
>>>
>>>
>>>
>>>
>>> --
>>> Programa de Pós-Graduação em Informática - PPGI/UFRJ
>>> EITA - Educação, Informação e Tecnologias para Autogestão
>>> Núcleo de Solidariedade Técnica - Soltec/UFRJ
>>> <http://www.soltec.ufrj.br>
>>> http://www.cirandas.net/alantygel
>>> http://www.contraosagrotoxicos.org
>>>
>>
>>
>>
>> --
>> Programa de Pós-Graduação em Informática - PPGI/UFRJ
>> EITA - Educação, Informação e Tecnologias para Autogestão
>> Núcleo de Solidariedade Técnica - Soltec/UFRJ <http://www.soltec.ufrj.br>
>> http://www.cirandas.net/alantygel
>> http://www.contraosagrotoxicos.org
>>
>> _______________________________________________
>> 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
>
>


-- 
Programa de Pós-Graduação em Informática - PPGI/UFRJ
EITA - Educação, Informação e Tecnologias para Autogestão
Núcleo de Solidariedade Técnica - Soltec/UFRJ <http://www.soltec.ufrj.br>
http://www.cirandas.net/alantygel
http://www.contraosagrotoxicos.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20150813/033f2672/attachment-0003.html>


More information about the ckan-dev mailing list