[ckan-dev] free tags from custom fields

Jordi Piqueras Bautista jpiqueras at absis.es
Wed May 13 07:04:55 UTC 2015


I’m with Sam! Even more and being more accurate I think the documentation is not clearly enough :)

I spent a lot of time doing the example of country_codes field adding at a second time more “countries” in the list of the function and now I just realised that it is something because the list is only created at the first time.

http://docs.ckan.org/en/latest/extensions/adding-custom-fields.html#tag-vocabularies

for tag in (u'uk', u'ie', u'de', u'fr', u'es'): <-- now I wanted to add other ones like u’aa’, u’bb’, u’cc’

How can I update the list of the elements of that list - in the create_country_codes() function?

Thanks.

De: ckan-dev [mailto:ckan-dev-bounces at lists.okfn.org] En nombre de Sam Leitner
Enviado el: martes, 12 de mayo de 2015 17:19
Para: CKAN Development Discussions
Asunto: Re: [ckan-dev] free tags from custom fields

I believe I found what I was looking for. To both add a field to free tags and to maintain the field in its own right, I can add a couple of lines to my plugin.

def _modify_package_schema(self, schema):
...
        schema.update({'subject_matter':[tk.get_converter('tag_string_convert'), tk.get_converter('convert_to_extras'),]})

def show_package_schema(self):
...
        schema.update({'subject_matter': [tk.get_converter('convert_from_extras'),]})

Any problems with doing this? Now it would be really nice if removing an element from this subject_matter field would remove the same element in the free tag field. Any thoughts on how painful it would be to modify the javascript in select2 to make that happen?



On Thu, May 7, 2015 at 3:02 PM, Sam Leitner <sam.leitner at gmail.com<mailto:sam.leitner at gmail.com>> wrote:
Hi Nilesh,

The extension docs explicitly describe how to add "vocabulary tags", and I can follow those successfully to create something analogous to the country codes, but I'd like to add "normal free tags" (in the language used in the docs) instead  -- I would like to duplicate the functionality of the Tags field that is built in to CKAN, but using a new field.

Is the Tags field output what you mean by "free extra tags"?

The form field in my package_metadata_fields.html looks as follows for a new tag field named subject_matter:
{% set subject_matter_attrs = {'data-module': 'autocomplete', 'data-module-tags': '', 'data-module-source': '/api/2/util/tag/autocomplete?incomplete=?'} %}
{{ form.input('subject_matter', id='field-subject_matter', label=_('Subject Matter'), placeholder=_('subject1, subject2'), value=data.subject_matter, error=errors.subject_matter, classes=['control-full'], attrs=subject_matter_attrs) }}

I don't follow what "skip the template for updations" means. Are you saying that I shouldn't even be using the IDatasetForm interface? If what I'm asking for is as simple as some variation of a schema[...].update(...) I would be very grateful for a specific example.

Many thanks for your help!
Sam



On Thu, May 7, 2015 at 1:30 PM, Nilesh Khule <nileshkhule7 at gmail.com<mailto:nileshkhule7 at gmail.com>> wrote:

Sam,

You want the custom fields as free tags follow the steps as per documentation
http://docs.ckan.org/en/latest/extensions/adding-custom-fields.html

If you want those custom fields as free extra tags skip the template from updations - package_metadata_fields.html



On Thu, May 7, 2015 at 7:43 PM, Sam Leitner <sam.leitner at gmail.com<mailto:sam.leitner at gmail.com>> wrote:
Hi ckan-dev,

I would like to add a custom dataset field that creates free tags. What is the best way to do that? Is it possible to do this with some slight change to  _modify_package_schema() and show_package_schema() discussed in the plugin documentation?  Something along the lines of a
schema.update({ 'new_tag_field': [tk.get_converter('convert_to_free_tags')] })
?

All I've found in the docs related to free tags is this: "To create a new free tag simply add the tag to a package, e.g. using the package_update() function." Further clarification would be hugely helpful.

Thanks!
Sam

_______________________________________________
ckan-dev mailing list
ckan-dev at lists.okfn.org<mailto: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<mailto: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/20150513/c3e03444/attachment-0003.html>


More information about the ckan-dev mailing list