Integrating Fundref via Fundref Widget

At Ubiquity Press our new Junior Developer, Stuart Jennings is working to integrate Fundref with our submission platform, allowing authors to submit their Funding info so it can be published and deposited with Crossref.

We were informed of the Fundref Widget (info, github), which we used as the basis of our integration, with a slight modifications so that we can get hold of the Funder ID as well as their official name (required for deposit) and to bind the funder names to the award numbers.

This all went fine until Stuart started noticing blank entries in our POST dictionary:

<QueryDict: {u'abstract': [u''], u'title': [u'd'], u'csrfmiddlewaretoken': [u'iO4X7u8TAS6Ew6sTGu9mAEOr1QyH7d47'], u'has-funding': [u'True'], u'has-competing': [u'False'], u'funder-name-2': [u'Cambridge University Hospitals'], u'funder-name-3': [u'Fake Uni'], u'funder-name-0': [u''], u'funder-name-1': [u'Oxford University Hospitals NHS Trust'], u'section_id': [u'5'], u'funder-name-4': [u''], u'funder-name-5': [u''], u'award-number-3': [u'', u''], u'award-number-4': [u'', u''], u'award-number-5': [u'', u'1213'], u'award-number-2': [u'', u'Cam1', u'Cam2', u''], u'award-number-0': [u''], u'award-number-1': [u'', u'Ox1', u'Ox2', u'Ox3']}>

After some post-processing

award_numbers = {k: v for k, v in award_number_dict.iteritems() if v and k.startswith('award-number-')}

we’re left with the much nicer looking:

{
u'award-number-0': [u''],
u'award-number-1': [u'', u'Ox1', u'Ox2', u'Ox3'],
u'award-number-2': [u'', u'Cam1', u'Cam2', u''],
u'award-number-3': [u'', u''],
u'award-number-4': [u'', u''],
u'award-number-5': [u'', u'1213']
}

In order to filter out these blanks in the list we simply need to filter them out, python has a neat little function called filter that does exactly this:

award_numbers = {k: filter(None, v) for k, v in award_number_dict.iteritems() if v and k.startswith('award-number-')}

Voila:

{
u'award-number-0': [],
u'award-number-1': [u'Ox1', u'Ox2', u'Ox3'],
u'award-number-2': [u'Cam1', u'Cam2'],
u'award-number-3': [],
u'award-number-4': [],
u'award-number-5': [u'1213']
}

After some investigation, it appears that the Fundref widget creates a set of invisible fields and clones these whenever it is asked to add a new row to the block.

Pub Tech developer for Birkbeck CTP

Pub Tech developer for Birkbeck CTP