fairdm.core.overview#

Pure helpers shared by the four record overview pages: project, dataset, sample and measurement.

What the pages work out from a record, including who is credited on it, lives on fairdm.core.plugins.RecordOverviewPlugin. What stays here has no shared subject: how a name is written in a citation, how a partial date becomes a date, and how data is serialised into a script element.

Module Contents#

Functions#

safe_reverse

Reverse a URL name, giving None where Django would raise.

as_date

Turn a partial date into a plain date, for comparing and sorting.

format_partial_date

Write a partial date as precisely as it was recorded.

author_name

Write a contributor’s name as a citation lists it: “Keller, A.”.

sentence_case

Capitalise the first letter only, so “XRF measurements” keeps its acronym.

format_authors

Write the DataCite creator list as a reader writes it: “Keller, A., Oliveira, T. & Brandt, L.”.

json_ld

Serialise data for an inline <script>.

API#

safe_reverse(name, **kwargs)[source]#

Reverse a URL name, giving None where Django would raise.

Args: name: The URL name. **kwargs: The URL’s keyword arguments.

Returns: The URL, or None when no route matches.

as_date(partial)[source]#

Turn a partial date into a plain date, for comparing and sorting.

A year or a month is padded out to the first day, so never show the result of this call to a reader; use :func:format_partial_date for that.

Args: partial: A PartialDate, a date, or None.

Returns: The date, or None when there is nothing to convert.

format_partial_date(partial)[source]#

Write a partial date as precisely as it was recorded.

Args: partial: A PartialDate, a date, or None.

Returns: The full date, the month and year, or the year alone, in the active language’s formats; an empty string when nothing is recorded.

author_name(contributor)[source]#

Write a contributor’s name as a citation lists it: “Keller, A.”.

Args: contributor: A person or organisation.

Returns: The last name and first initial, or the contributor’s own string form when it has no first and last name.

sentence_case(text)[source]#

Capitalise the first letter only, so “XRF measurements” keeps its acronym.

Args: text: The text to capitalise.

Returns: The text with its first letter in upper case and the rest untouched.

format_authors(contributors)[source]#

Write the DataCite creator list as a reader writes it: “Keller, A., Oliveira, T. & Brandt, L.”.

Args: contributors: The creators, in credit order.

Returns: The names joined with commas and a final ampersand, or an empty string for no creators.

json_ld(data)[source]#

Serialise data for an inline <script>.

The characters that could end the element are escaped, so user-written names and descriptions can never break out of it.

Args: data: Anything json.dumps accepts; other values are written as their string form.

Returns: The JSON text, safe to place inside a script element.