[ckan-dev] Adding a tag to a package

Alan Tygel alantygel at gmail.com
Thu Aug 13 13:11:52 UTC 2015


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20150813/ea057418/attachment-0003.html>


More information about the ckan-dev mailing list