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#
Reverse a URL name, giving |
|
Turn a partial date into a plain date, for comparing and sorting. |
|
Write a partial date as precisely as it was recorded. |
|
Write a contributor’s name as a citation lists it: “Keller, A.”. |
|
Capitalise the first letter only, so “XRF measurements” keeps its acronym. |
|
Write the DataCite creator list as a reader writes it: “Keller, A., Oliveira, T. & Brandt, L.”. |
|
Serialise |
API#
- safe_reverse(name, **kwargs)[source]#
Reverse a URL name, giving
Nonewhere Django would raise.Args: name: The URL name. **kwargs: The URL’s keyword arguments.
Returns: The URL, or
Nonewhen 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_datefor that.Args: partial: A
PartialDate, a date, orNone.Returns: The date, or
Nonewhen 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, orNone.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
datafor 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.dumpsaccepts; other values are written as their string form.Returns: The JSON text, safe to place inside a script element.