#1044: BibKnowledge: get_kb_mappings_json not to return key if no value
------------------------+--------------------------
Reporter: jcaffaro | Owner:
Type: enhancement | Status: new
Priority: major | Component: BibKnowledge
Version: | Keywords:
------------------------+--------------------------
Currently when using {{{get_kb_mappings_json()}}} for a key that has no
value, the key is returned as value. For example:
{{{
foobarKB:
foo1 --> bar1
foo2 -->
foo3 --> bar3
get_kb_mappings_json('foobarKB', 'foo2')
{'label': 'foo2', 'value': 'foo2'}
}}}
source:modules/bibknowledge/lib/bibknowledge.py@a6221e6#L113
This is making impossible to disambiguate between the two cases:
{{{
foobarKB1: | foobarKB2:
foo1 --> bar1 | foo1 --> bar1
foo2 --> | foo2 --> foo2
foo3 --> bar3 | foo3 --> bar3
}}}
One could be willing to receive {{{null}}} or empty string instead:
{{{
get_kb_mappings_json('foobarKB', 'foo2')
>>{'label': 'foo2', 'value': null}
}}}
or
{{{
get_kb_mappings_json('foobarKB', 'foo2')
>>{'label': 'foo2', 'value': ""}
}}}
This function interface could also be extended similarly to
[source:modules/bibformat/doc/hacking/bibformat-api.webdoc@1bb7957#L334
bibformat_engine.BibFormatObject.kb(kb, string, default="")] so that the
default returned value can be decided:
{{{
get_kb_mappings_json('foobarKB', 'foo2', default="")
>>{'label': 'foo2', 'value': ""
get_kb_mappings_json('foobarKB', 'foo2', default='foo2')
>>{'label': 'foo2', 'value': 'foo2'}}
}}}
This might extend to other kb-related functions, and REST APIs.
(As briefly mused with Joe about one year ago, there is no reason not to
move to this new interface)
--
Ticket URL: <http://invenio-software.org/ticket/1044>
Invenio <http://invenio-software.org>